I am having trouble with a script I use for converting, renaming, and copying files from iTunes to a folder. This script had been working perfectly, but after upgrading to a new imac, is exhibiting a specific strange behavior. Here is the entire script (sorry”it’s a little long.)
tell application "iTunes"
activate
if kind of container of view of front browser window is not library or selection of front browser window is {} then
display dialog "You must select some tracks first." buttons {"Cancel"} default button 1 with icon 2 giving up after 15
end if
set sel to selection of front browser window
-- plural for dialog
set s to "s"
if (count of items in sel) is 1 then set s to ""
set myEncoders to name of every encoder
set encoderBackup to name of current encoder
set myNewEncoder to (choose from list myEncoders with prompt ¬
"Convert track" & s & " using..." default items (encoderBackup as list) ¬
OK button name "OK" cancel button name ¬
"Cancel" without multiple selections allowed and empty selection allowed) as string
if myNewEncoder is "false" then error number -128
set uD to (choose folder with prompt "Move converted file" & s & " to...")
if uD is false then error number -128
set current encoder to encoder myNewEncoder
set pathToImage to "Mac HD:Users:Studio:Documents:Album Art:AlbumArt.pct"
set currentArtwork to (read file pathToImage from 513 as artwork)
set cnt to 0
repeat with this_track in sel
try -- skip on failure
if cnt < 9 then
set zeroStr to "0" & (cnt + 1) as string
else
set zeroStr to (cnt + 1) as string
end if
set new_track to item 1 of (convert this_track)
set loc to new_track's location
set dbid to new_track's database ID
set name_hold to zeroStr & "-" & (get name of new_track) & "-companyname"
set name of new_track to name_hold
-- change ID3 tags
set artist of new_track to "Company Name"
set album of new_track to "[url=http://www.companyname.com]www.companyname.com[/url]"
set rating of new_track to 0
set grouping of new_track to ""
set composer of new_track to ""
set comment of new_track to ""
set track number of new_track to 0
set track count of new_track to 0
set disc number of new_track to 0
set disc count of new_track to 0
set data of artwork 1 of new_track to currentArtwork
-- move the file to new location
do shell script "mv " & (quoted form of POSIX path of loc) & " " & (quoted form of POSIX path of uD as string)
-- delete the track
delete new_track
set cnt to cnt + 1
end try
end repeat
set current encoder to encoder encoderBackup
display dialog "Done." buttons {"Thanks"} default button 1 with icon 1 giving up after 90
end tell
Everything works as expected except for the moving of the file. Instead of moving to the location I specify (“uD”), for some unexplainable reason it saves to the location “HD:Company Name:www.companyname.com:”. In other words, it is saving to a folder named the value of the track’s “album” tag, that is within a folder named the value of the track’s “artist” tag, that is at the root level of the external hard drive my iTunes library is on. I have verified that it is using these tags by changing their values”the folders created by the script change accordingly.
If I set the end dialog to display the value of “uD” at the end of the script, it is correct. However, if I set the end dialog to display the value of “loc” at the end of the script, it is the incorrect location as just described. I also tried displaying the value of “loc” right after it is defined in the script and at that point it is still correct. The change happens later (even though it is not even used until the shell the script, and even if I remove the shell script completely!)
I hope my description makes sense and that someone might have some insight into this problem.
Thanks!
Michael
Model: iMac
AppleScript: 2.1.2
Browser: Safari 4.0.5
Operating System: Mac OS X (10.6)