I’m trying to make a script to change the Genre of the currently playing track in iTunes - and everything works, but am unable to pull the current genre into a variable. I’ve tried several variations of the following. Any thoughts are appreciated.
I got this version to work - I think the previous problem was the variable was in a subroutine and I got a “variable not defined error”. Any thoughts on how to switch back to the old application? i.e. i’m in Mail, activate this script via QS, then automatically switch back to Mail?
tell application "iTunes"
activate
if player state is playing then
--to changeG(this_track)
set GenreList to {"Mellow Rock", "Rock", "Jazz", "Old Jazz", "Folk", "Groove", "Classic Rock", "Hard Rock", "Vocal", "Jazz", "Rap", "Hip Hop", "R&B"}
set thisTrack to current track
set OldGenre to thisTrack's genre
--set OldGenre to genre of (get current track)
--set OldGenre to "test"
set NewGenre to (choose from list GenreList with prompt "Current Genre is " & OldGenre & return & "Select the new genre." default items item 1 of GenreList)
tell application "iTunes" to set genre of thisTrack to NewGenre
end if
end tell
This should get close to what you’re trying to do, sadamny (although I’ve also suggested one or two tweaks):
property GenreList : {"Mellow Rock", "Rock", "Jazz", "Old Jazz", "Folk", "Groove", ¬
"Classic Rock", "Hard Rock", "Vocal", "Jazz", "Rap", "Hip Hop", "R&B"}
set currApp to path to frontmost application as Unicode text
tell application "iTunes" to if player state is playing then tell current track
activate
set OldGenre to genre
if OldGenre is not in GenreList and (count OldGenre) > 0 then set GenreList's end to OldGenre
set NewGenre to (choose from list GenreList with prompt "Change genre to:" default items OldGenre)
if NewGenre is not false then set genre to NewGenre
end tell
activate application currApp
However, unless you really want to look at iTunes, you might like to try this variation:
property GenreList : {"Mellow Rock", "Rock", "Jazz", "Old Jazz", "Folk", "Groove", ¬
"Classic Rock", "Hard Rock", "Vocal", "Jazz", "Rap", "Hip Hop", "R&B"}
tell application "iTunes" to if player state is playing then tell current track
set OldGenre to genre
if OldGenre is not in GenreList and (count OldGenre) > 0 then set GenreList's end to OldGenre
tell me to set NewGenre to (choose from list GenreList with prompt "Change genre to:" default items OldGenre)
if NewGenre is not false then set genre to NewGenre
end tell