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 am looking for a way to assign a keyboard shortcut to clear all the tracks from Up Next queue of iTunes. Does anyone know a way to do this?

Using Mac OS X Mountain Lion 10.8.4

share|improve this question
1  
Are you looking for a keyboard shortcut to add selected tracks to Up Next, or to view the Up Next list? Viewing already has a shortcut - option+command+U. –  tubedogg Sep 6 '13 at 0:33
    
I want a shortcut to clear all the tracks from the up next queue –  Bilal Sep 6 '13 at 13:54
    
I found stackoverflow.com/questions/13659626/… which uses gui scripting for adding a track to up next. But it was not useful for clearing the up next queue with applescript unfortunately –  Bilal Sep 6 '13 at 14:49
add comment

3 Answers 3

This following script will work on OSX < 10.7.

activate application "iTunes"
tell application "System Events"
    tell process "iTunes"
        click (first button of scroll area 1 of window "iTunes" whose description is "up next")
        delay 1
        click button "Clear" of UI element 1 of row 1 of table 1 of scroll area 1 of window 1
    end tell
end tell
share|improve this answer
    
Just tried it : Very buggy. Sometimes the Up Next queue is button 4, sometimes it's button 2. –  Matthieu Riegler Sep 6 '13 at 17:20
    
Can be fixed within a try block –  adayzdone Sep 6 '13 at 17:31
    
Still doesn't work. ( 0SX 10.8.4 /w iTunes 11.0.5) –  Matthieu Riegler Sep 6 '13 at 17:48
    
Works in ( 0SX 10.6.8 /w iTunes 11.0.5) –  adayzdone Sep 6 '13 at 17:54
    
I found why it doesn't work : iTunes on OSX >= 10.7 uses a NSPopover for Up next which is not available on 10.6 and below. –  Matthieu Riegler Sep 6 '13 at 17:59
show 2 more comments

So here's a complete answer :


For iTunes 11 & OS X 10.6 (iTunes 11 requires at least 10.6.8) :

  • Create a new Automator service
  • Select Service Receives no input In iTunes
  • Add a Run AppleScript action
  • copy the code given by adayzdone. (You may need to adapt "up next" following the language of you system. For example on my French OS X it's "suivant")
  • Save the service.
  • Go to System Preferences > Keyboard > Keyboard Shortcuts
  • In Services, add a keyboard shortcut to your new service

For OS X 10.7 and above:

For the up next menu iTunes 11 uses an NSPopover which is available in OS X v10.7 and later. Therefore the hierarchy of UI Elements is different from the case above.

On iTunes 11.0.5, there is a bug where the button opening the Popover has no children. Therefore it is NOT possible to access the content of the popover to click on the clear button using Applescript.

share|improve this answer
    
I figured out a way of clicking the clear button by simulating a mouse click see apple.stackexchange.com/a/101158/34352 –  Bilal Sep 7 '13 at 12:39
add comment
up vote 0 down vote accepted

I found a way to do it on Mac OS X Mountain Lion 10.8. it uses cliclick from http://www.bluem.net/en/mac/cliclick/ to simulate a mouse click at the location of the clear button. The script assuming that cliclick is in /usr/local/bin

This works for me on a 15 inch macbook pro retina running at 1440x900@2x

To use the script either use the instructions by Matthieu Riegler for a global shortcut or use it from the command line

The code:

#!/usr/bin/env osascript
activate application "iTunes"
tell application "System Events"
    tell process "iTunes"
        click (first button of scroll area 1 of window "iTunes" whose description is "up next")
        delay 1
        set upNextButton to button 4 of scroll area 1 of window 1
        set pos to upNextButton's position

        --  160, 54  the number of pixels away the clear button is

        set clearX to (item 1 of pos) + 160
        set clearY to (item 2 of pos) + 54
        set cmd to "/usr/local/bin/cliclick -- " & {clearX, " ", clearY}
        do shell script cmd

    end tell
end tell

also a script for the mini player assumes that the up next list is closed

#!/usr/bin/env osascript
activate application "iTunes"
tell application "System Events"
    tell process "iTunes"
        set upNextButton to (first button of window "MiniPlayer" whose description is "show up next")
        click upNextButton
        delay 1

        set pos to upNextButton's position
        --  19, 48  the number of pixels away the clear button is 
        set clearX to (item 1 of pos) + 19
        set clearY to (item 2 of pos) + 45

        set cmd to "/usr/local/bin/cliclick -- " & {clearX, " ", clearY}
        do shell script cmd

        delay 0.1
        click upNextButton

    end tell
end tell
share|improve this answer
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.