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.