Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Automator: clear ID3 tags & add to iTunes playlist

I download a lot of music. Constantly cleaning up my Downloads folder is becoming tedious. After some Google I discovered Automator, which now moves music files to the 'Automatically Add to iTunes' folder.


However, the files disappear somewhere in my library while I want them to be added to a dumb playlist (not a smart 'recently added' one).

And I want to take it a step further and delete some ID3 tags.

In iTunes I clear all but the artist, title, genre and cover art.


This whole process is repetitive and takes up unnecessary time.

I have no experience with Apple script or Automator and really want all this to be automatic but have no idea where to start.

Can anyone please help me?

Posted on Aug 25, 2014 5:16 AM

Reply
8 replies

Aug 25, 2014 7:11 AM in response to QuakeFX

Hi,



In your Automator workflow: replace the "Move file to 'Automatically Add to iTunes' folder" action by the "Run AppleScript script" action.

Remove all text in the action

Put this script in the action


on run {input, parameters}
    set tName to "dumb playlist" -- the name of the dumb playlist
    tell application "iTunes"
        if not (exists playlist tName) then
            set dumbP to make new user playlist with properties {name:tName}
        else
            set dumbP to playlist tName
        end if
        set importedTracks to {}
        repeat with i in input
            try
                tell (add i to dumbP) -- import , iTunes copy this file in his library)
                    set {album, album artist, comment, composer, episode ID, episode number, grouping, lyrics, sort album, sort artist, sort album artist, sort composer, track number, track count, disc count, disc number, episode ID, episode number, season number, year, bpm} to {"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""}
                    set end of importedTracks to it
                end tell
                my deleteFile(i) -- delete this file in the download folder
            end try
        end repeat
    end tell
    return importedTracks
end run

on deleteFile(f)
    do shell script "/bin/rm -f " & (quoted form of POSIX path of f)
end deleteFile


This script import each file into a dumb playlist , if the import into iTunes is successful, the script clear some tags in this track and delete this file in the Download folder.

Aug 30, 2014 1:54 PM in response to QuakeFX

QuakeFX wrote:


That looks really neat Jacques!

But it seems to be a bit unstable. It misses +-1 in 4 songs, they don't get added to itunes.

And none get deleted from the Downloads folder. Does it work for you?


No, I don't use folders action on the download folder.

I had not thought about the download, but the script should check that the download of each file is completed, otherwise iTunes will not import a partial file.


Try this script:

on run {input, parameters}
    set tName to "dumb playlist" -- the name of the dumb playlist  
    tell application "iTunes"
        if not (exists playlist tName) then
            set dumbP to make new user playlist with properties {name:tName}
        else
            set dumbP to playlist tName
        end if
        set importedTracks to {}
        repeat with i in input
            set f to contents of i
            my checkDownload(f) -- check that the download is completed.
            try
                tell (add f to dumbP) -- import , iTunes copy this file in his library)  
                    set {album, album artist, comment, composer, episode ID, episode number, grouping, lyrics, sort album, sort artist, sort album artist, sort composer, track number, track count, disc count, disc number, episode ID, episode number, season number, year, bpm} to {"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""}
                    set end of importedTracks to it
                end tell
                my deleteFile(f) -- delete this file in the download folder  
            end try
        end repeat
    end tell
    return importedTracks
end run

on deleteFile(f)
    do shell script "/bin/rm -f " & (quoted form of POSIX path of f)
end deleteFile

on checkDownload(f)
    set oldSize to size of (info for f)
    repeat
        delay 3
        set s to size of (info for f)
        if s = oldSize then return -- the download is complete
        set oldSize to s
    end repeat
end checkDownload

Sep 2, 2014 5:27 AM in response to Jacques Rioux

Now the script does nothing.

In v1, both songs that took a while and songs that downloaded almost instantly were added successfully. I think the 'Filter finder items - kind is music' filters out incomplete downloads, so it wouldn't be necessary to script the checkDownload(f)?


I'm trying to understand what's going on but I'm studying and working around the clock so I'm sorry if my replies seem lazy.

Sep 2, 2014 8:40 AM in response to QuakeFX

Hi,


QuakeFX wrote:


Now the script does nothing.

In v1, both songs that took a while and songs that downloaded almost instantly were added successfully. I think the 'Filter finder items - kind is music' filters out incomplete downloads, so it wouldn't be necessary to script the checkDownload(f)?


I'm trying to understand what's going on but I'm studying and working around the clock so I'm sorry if my replies seem lazy.



Hi,



I found a problem when iTunes imports a file, it locks the file for some time, so the script get this error ("iTunes got an error: File permission error") when the script try to edit the tags.

So i add a delay in the script


Test this script on the Applescript Editor :

on run --{input, parameters}
    set x to path to downloads folder
    set input to choose file with prompt "Select some audio files" default location x with multiple selections allowed
    set tName to "dumb playlist" -- the name of the dumb playlist   
    tell application "iTunes"
        if not (exists playlist tName) then
            set dumbP to make new user playlist with properties {name:tName}
        else
            set dumbP to playlist tName
        end if
        set importedTracks to {}
        repeat with i in input
            set f to contents of i
            try
                set t to add f to dumbP -- import , iTunes copy this file in his library)
                set end of importedTracks to t -- success
                my deleteFile(f) -- delete this file in the download folder   
                repeat
                    set j to 0
                    try -- to clear tags
                        tell t to set {album, album artist, comment, composer, episode ID, episode number, grouping, lyrics, sort album, sort artist, sort album artist, sort composer, track number, track count, disc count, disc number, episode ID, episode number, season number, year, bpm} to {"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""}
                        exit repeat -- success
                    on error err number n
                        if n = -54 then -- iTunes got an error: File permission error. (need delay before clearing tag, because iTunes lock this file)
                            set j to j + 1
                            if j > 4 then exit repeat -- After five times, it's enough, go to next file
                            delay 1
                        else
                            exit repeat -- I don't manage other errors
                        end if
                    end try
                end repeat
            end try
        end repeat
    end tell
    return importedTracks
end run

on deleteFile(f)
    do shell script "/bin/rm -f " & (quoted form of POSIX path of f)
end deleteFile



Run the script, when the dialog is displayed, select 2 or more audio files in the downloads folder.


When the script will stop, check if iTunes imports these files in the playlist and check if the files are deleted in the downloads folder.

Sep 2, 2014 5:13 PM in response to QuakeFX

QuakeFX wrote:


It works! Files are imported, added to the dumb playlist, tags get sorted and files are deleted.

Would it be possible to do this without the popup?


And I greatly appreciate you writing this script for me. Thank you for your time and effort.


Ok


Try again the folder action:

Right click on the Downloads folder, select menu --> "Services" --> "Folder actions Setup..."

Uncheck "Enable Folder Actions" in "Folder actions Setup" window


Open the workflow

Use this script in the "Run AppleScript Script" action:

on run {input, parameters}
    set tName to "dumb playlist" -- the name of the dumb playlist   
    tell application "iTunes"
        if not (exists playlist tName) then
            set dumbP to make new user playlist with properties {name:tName}
        else
            set dumbP to playlist tName
        end if
        set importedTracks to {}
        repeat with i in input
            set f to contents of i
            my checkDownload(f) -- check that the download is completed.
            try
                set t to add f to dumbP -- import , iTunes copy this file in his library)
                set end of importedTracks to t -- success
                my deleteFile(f) -- delete this file in the download folder
                set j to 0
                repeat
                    try -- to clear tags
                        tell t to set {album, album artist, comment, composer, episode ID, episode number, grouping, lyrics, sort album, sort artist, sort album artist, sort composer, track number, track count, disc count, disc number, episode ID, episode number, season number, year, bpm} to {"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""}
                        exit repeat -- success
                    on error err number n
                        if n = -54 then -- iTunes got an error: File permission error. (need delay before clearing tag, because iTunes lock this file)
                            set j to j + 1
                            if j > 4 then exit repeat -- After five times, it's enough, go to next file
                            delay 1
                        else
                            exit repeat -- I don't manage other errors
                        end if
                    end try
                end repeat
            end try
        end repeat
    end tell
    return importedTracks
end run

on deleteFile(f)
    do shell script "/bin/rm -f " & (quoted form of POSIX path of f)
end deleteFile

on checkDownload(f)
    set oldSize to size of (info for f)
    repeat
        delay 3
        set s to size of (info for f)
        if s = oldSize then return -- the download is complete
        set oldSize to s
    end repeat
end checkDownload

Save.

Check "Enable Folder Actions" in "Folder actions Setup" window

------

If that does not work:

Right click on the Downloads folder, select menu --> "Services" --> "Folder actions Setup..."

Uncheck "Enable Folder Actions" in "Folder actions Setup" window


Open the workflow

Removes this line "my checkDownload(f) -- check that the download is completed."

Remove the "on checkDownload(f) ... end checkDownload" block

Save

Check "Enable Folder Actions" in "Folder actions Setup" window

----




if it still does not work:

The workflow will check all the items in the Downloads folder, instead of the added items in the Downloads folder, as if that does not work when the files is downloading, it will work on audio files already downloaded when the process will run next time.


Right click on the Downloads folder, select menu --> "Services" --> "Folder actions Setup..."

Uncheck "Enable Folder Actions" in "Folder actions Setup" window


Open the worflow

1- Insert "Get Specified Finder items" action at the first position of the workflow

Drag/drop the Downloads folder into the first action.

2- Insert "Get Folder Contents" action at the second position.

Keep all others actions.

Save

Check "Enable Folder Actions" in "Folder actions Setup" window.


Edit: I forgot to remove two lines in the script, the script is okay now.

Automator: clear ID3 tags & add to iTunes playlist

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.