Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I would like to launch a Genius playlist for the currently playing song in iTunes via an AppleScript.

A prerequisite would be for the script to work when iTunes is in full screen.

And ideally, it wouldn't :

  • bring iTunes to front
  • leave an error message when genius isn't available for that song
  • depend on the system language

I found this script, but it doesn't work for me when iTunes is in full screen. Still, it's a great start.

It would maybe be possible to use the protocol the iOS "Remote" app uses, but that seems to be overkill.

Any help would be appreciated.

(the goal is to launch genius from softwares like Keyboard Maestro or Alfred)

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

Try this :

tell application "iTunes" to try
    activate
    with timeout of 10 seconds
        reveal current track -- error if no current track
        set tName to name of (first window whose its class is browser window or its class is playlist window)
    end timeout
on error
    return "Can't find track!"
end try

tell application "System Events"
    tell application process "iTunes"
        try
            set b to (first button of window tName whose value of attribute "AXDescription" is "Genius")
            if not (enabled of b) then return "Genius button disabled" -- (film, video clip,...)
            perform action "AXPress" of b
        on error -- no Genius button (radio, podcast, .....) playlist
            return "Can't create genius list from that track!"
        end try
        delay 2
        tell front window to if value of attribute "AXSubRole" is "AXDialog" then -- dialog opened.
            perform action "AXPress" of button "OK" -- close the dialog
            return "Can't create genius list from that track!"
        end if
    end tell
end tell
return "Done"
share|improve this answer
    
I had to change button "OK" by first button to make it work with my french install, but it otherwise works great! Thanks! This said, I still hope someone bring up some magic in order to leave iTunes in the background. –  olivier Jul 17 '12 at 13:39
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.