I have a script that allows me to change from one iTunes library to another. When I open my lossless library, I need to set the encoder to Apple Lossless Encoder, when I open my ACC192 library, I need to set the encoder to ACC Encoder. Using statements like
tell application “iTunes” to set current encoder to encoder “Apple Lossless Encoder”
doesn’t seem to work.
Mac OSX Lion 10.7
It is interesting how
tell application "iTunes"
activate
set p to format of current encoder
end tell
returns “MP3” for me but when I do this
tell application "iTunes"
activate
set format of current encoder to "MP3"
end tell
It doesn’t let me set it.
But I will keep trying to figure it out. This is an interesting script that I hope to use when its fixed.
I just realized when looking at the dictionary for iTunes that the format of the encoder is read-only. It sounds like GUI scripting might be the way.
No that’s not true.
The current encoding is not read only but the encoder itself is read only. It is not a string but an encoding object that needs to be set so for MP3 you should use something like this…
tell application "iTunes"
set current encoder to encoder "MP3 Encoder"
end tell
I never thought about that method because drmjdoyle said that very method didn’t work.
I think drmjdoyle has made a typo because on my machine there is no “Apple Lossless Encoder” but just “Lossless Encoder”. So maybe this code would work for him.
tell application "iTunes"
set current encoder to encoder "Lossless Encoder"
end tell
But it’s the only method… Even if the property format was writable, it is object-wise not possible with AppleScript in any situation or better said in any type of language. That’s why I mentioned it (normally I don’t).
using
tell application “iTunes”
set current encoder to encoder “Apple Lossless Encoder”
end tell
or
tell application “iTunes”
set current encoder to encoder “Apple Lossless”
end tell
doesn’t work.
It returns an error
iTunes got an error: Can’t set current encoder to encoder “Apple Lossless Encoder”.
Still need help.
Thanks DJ Bazzie Wazzie,
While the drop down selector shows “Apple Lossless” as a choice for the encoder, using only “Lossless” as you suggested does work!
I am using the most recent version of iTunes. Perhaps it was different in a previous version. Regardless, thanks for your help
you’re welcome!
You could use the following code to see the actual names of all the encodings. The encoding names you see in the drop down menu are localized names and the name you use in AppleScript is not.
tell application "iTunes"
name of every encoder --returns all names of encoders you can use.
end tell
When there is a difference between iTunes version in the name of the lossless encoder but they both contain the string “lossless” you could use the following code.
tell application "iTunes"
set listOfEncoderNames to name of every encoder
repeat with encoderName in listOfEncoderNames
if encoderName contains "lossless" then
set current encoder to encoder encoderName
return
end if
end repeat
--if we're here something went wrong
display dialog "Can't find Lossless encoder" buttons {"OK"} default button 1
end tell