5

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

  • 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 Syed Hussain 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 Syed Hussain Sep 6 '13 at 14:49
1

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
  • 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
1

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.

0

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
0

Here is my solution for iTunes 12.9 on macOS Mojave 10.14. My solution simply listens for a trigger keystroke when iTunes is active and then fires a sequence of other keystrokes that presses the “Clear” button using only the keyboard.

The instructions below set this up using the paid app Keyboard Maestro, but you should be able to replicate this using any other app that can listen to a keystroke and then fire other keystrokes. Quicksilver, Automator, or AppleScript could be used in alternative solutions.

In Keyboard Maestro, first, create a folder “iTunes-specific mapping” with this configuration:

Available in these applications:

  • iTunes

Then add a macro called Clear “Up Next” and set a trigger hot key:

Triggered by any of the following (when iTunes is at front):

  • This hot key:
    • ' is pressed

Will execute the following actions:

Click “+” to add an action, search for the “Type a Keystroke” action, and add five copies of it to the list of actions. Configure them to type these keystrokes in order:

  1. U (Show Up Next)
  2. F7 (An OS-wide shortcut that toggles how Tab cycles through controls. See “Full Keyboard Access” at the bottom of System Preferences > Keyboard > Shortcuts for more details. If your normal setting is already “All controls”, you don’t need this step.)
  3. Tab (focus the Clear button)
  4. Space (activate the Clear button)
  5. F7 (toggle Full Keyboard Access back to what it was before step 2)

After setting this up, with Keyboard Maestro open in the background, you can press ' within iTunes to clear the Up Next queue.

A limitation of this solution: if there are no tracks in the Up Next queue, this sequence of keystrokes will instead pause the current track.

If this sequence of keystrokes isn’t working for you, it may be because the iTunes interface changed, or because the OS has responded to F7 too slowly and changed the behavior of Tab only after Tab is pressed. You can fix the first problem by changing the sent keystrokes, and you can fix the second problem by adding Pause actions between the keystrokes.

  • I don’t have time to edit my answer now, but I improved this solution to be more robust, such that you can safely trigger the macro even if no tracks are in Up Next. The key is to use the “if the screen contains an image” feature of Keyboard Maestro. After opening the Up Next popup, assert that it is actually visible on-screen. Then use an If statement to see if the popup already says “No upcoming songs.”, and just send an Escape keypress to close the popup if so. – Rory O'Kane May 28 at 6:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .