How to change the iTunes encoder with applescript

I want to change the iTunes encoder with an apple script! I only know, that the mp3 encoder is called “encoder id 28”, the aiff encoder is called “encoder id 29” and the wav encoder is called “encoder id 30”! But I don’t know how I can teach iTunes to use this encoder! I tested it with this script, but it doesn’t work:

on run
with timeout of 999999 seconds
tell application "iTunes
set new_encoder to (encoder id 29)
convert selection with new_encoder
end tell
end timeout
end run

do you have an idea? :?:

To switch encoders, try this:


tell application "iTunes"
-- set selected Playlist
set sPlaylist to (get view of front window)
-- set AIFF as encoder and backup current settings
set aiffEncoder to "AIFF Encoder" -- string grabbed from iTunes prefs
set prefEncoder to name of current encoder -- encoder set in iTunes prefs
set current encoder to encoder aiffEncoder
-- script
repeat with i from 1 to (count tracks of sPlaylist)
set newT to item 1 of (convert (track i of sPlaylist))
end repeat
-- set encoder back to how it was before
set current encoder to encoder prefEncoder -- back to iTunes prefs
end tell