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
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
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
Up next
which is not available on 10.6 and below.
– Matthieu Riegler
Sep 06 '13 at 17:59
System Events got an error: Can’t get table 1 of scroll area 1 of window 1 of process "iTunes". Invalid index.
– Bilal Syed Hussain
Sep 06 '13 at 18:40
So here's a complete answer :
For iTunes 11 & OS X 10.6 (iTunes 11 requires at least 10.6.8) :
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.
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
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:
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.