I have some code in an applescript that works with iTunes files with the following lines:
set pathToImage to "Mac HD:Users:Studio:Documents:Album Art:AlbumArt.pct"
set currentArtwork to (read file pathToImage from 513 as artwork)
Then, within a repeat loop, there’s:
set data of artwork 1 of new_track to currentArtwork
At this point in the script, I get error -2003. This script used to work in 10.5. I have since updated computers and now have 10.6. And, it no longer works.
Any idea as to what’s causing this?
Thanks!
Michael
The pict format for images is deprecated in 10.6. You can still use it, but only in 32-bit mode.
Aha. Thanks, Shane. I’ll convert to a jpeg.
Changed the album art to a jpeg, but still get the same error. Any other ideas?
Try reading the jpeg “as data”, and use the result to set the “raw data” of the artwork.
Thanks, Shane. I tried changing “as artwork” to “as data” but get Parameter Error -50. If I set that back to “as artwork” and have the script write as “raw data” instead of just “data”, I get an Unknown Type Error -1731.
Did you cut out the the “from 513” bit? Post your latest code…
No. Originally I tried:
set currentArtwork to (read file pathToImage from 513 as data)
But, just now tried:
set currentArtwork to (read file pathToImage as data)
Got the same error.
Works fine here – check your path.
Hmmm. Checked my path but still get the following error:
“iTunes got an error: Parameter error.” number -50 from data to type class
There’s not much anyone can do if you won’t post a decent slab of your code…
The full code before the two changes you suggested, Shane, was:
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 "Macintosh HD:Users:iTunes:Documents:iTunes Album Art:AlbumArt.jpg"
set currentArtwork to (read file pathToImage from 513 as artwork)
set cnt to 0
repeat with this_track in sel
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 "Companyname"
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 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 repeat
set current encoder to encoder encoderBackup
display dialog "Done." buttons {"Thanks"} default button 1 with icon 1 giving up after 90
end tell
Change this:
set currentArtwork to (read file pathToImage from 513 as artwork)
to this:
set currentArtwork to (read file pathToImage as data)
and move it outside the ‘tell application “ITunes”’ block.
Then change this:
set data of artwork 1 of new_track to currentArtwork
to this:
set raw data of artwork 1 of new_track to currentArtwork
See how that goes.
Changed and moved these two lines before the “tell” block (they now come first):
set pathToImage to "Macintosh HD:Users:iTunes:Documents:iTunes Album Art:AlbumArt.jpg"
set currentArtwork to (read file pathToImage as data)
No longer got an error there!
However, on this line:
set raw data of artwork 1 of new_track to currentArtwork
I get “iTunes got an error: Unknown object type.” number -1731
I was afraid of that. I’m afraid I don’t know the answer – it might need the kind set to something or other. I know that the revers of what you’re doing works, so I don’t think you’re doing anything wrong.
Okay. Thanks, Shane. I really appreciate all your help.
Michael
What happens if you try it on an album that already has JPEG artwork?
Wow. That works.
Does that mean there’s a way to tweak the code, or does every track have to have pre-existing artwork?
I don’t know – it was just a hunch. Check the kind property – setting that to the right value might be the key.
Hi Shane. As a followup, setting “raw data” back to just “data” solved the issue. The script is working perfectly now. THANKS AGAIN!!!
Michael