Send media keys to specific application trick?

I'm trying to send media keys, prev, next, pause/play, to a specific application, but it won't let me input into the hot key box, is there an easy way to do this, without some karabiner remap tricks or something?


See this thread: How can I assign media play key as a hotkey trigger?

thanks, guess it's not so easy.

Maybe I am misunderstanding the question—but if you want to send a media key command to a specific application, an AppleScript would work:


tell application "Music"
 end tell

Skip forward 30 seconds

tell application "Music" to set player position to (player position + 30)
1 Like

I guess you can invoke them, that's cool, it works in spotify, unfortunately I already had good control of spotify, when I try it in another more obscure player that I wanted to control called "headset" or even "google chrome", I get a notification that says macro cancelled, if i check log it says:

2020-09-09 21:30:25 Execute an AppleScript failed with script error: text-script:25:38: execution error: The variable playpause is not defined. (-2753)

any idea what that means? do I have to grant permission or something, because it asked before it worked with spotify.

It could mean that the obscure player uses a different command for play/pause.

Does the obscure player have an AppleScript dictionary?

Which player is the obscure player? I'll take a look at it.

it's called headset, it's a youtube controller,

it does have controls for play pause/next/prev/stop, if you press them with mouse or via media key, but it only skips forward and back 5 seconds which sucks, I would really like to skip more than that with it with applescript

I would also like to get it working on google music.

thanks for any info you find.

So you are trying to play, pause and skip YouTube videos, right?

If so, you can do it with an AppleScript that sends a YouTube kay shortcut to the webpage.

K pauses, J skips back 10 seconds and L skips forward 10 seconds.

Keep in mind that you are limited to the 10 second skip that is native to YouTube. But you can trigger the script multiple times to get a result of multiple skips. Twice = a 20 second skip in two 10 second increments.

Example AppleScript to skip 10 seconds forward for the first YouTube tab in Safari:

The AppleScript part:

set tabURL to ""

tell application "Safari"
	set windowsList to index of every window
	repeat with i in windowsList
			tell window i
				set current tab to (first tab whose URL contains tabURL)
			end tell
			set index of window i to 1
			exit repeat
		end try
	end repeat
end tell
1 Like

thanks, I knew about the j, k l, h shortcuts for youtube, I was going to use them primitively as straight up keystrokes being sent to the player.

10 seconds skip is pretty good, it would be nicer if I could override it to how long I wanted but i guess that's limited by the particular player, spotify let me do 30 via applescript and probably would do other lengths, which is not normal because their normal is 15 seconds so that's cool.

do you know the variables for playpause for youtube? I have skip forward, backward, next and prev already so that's good.

and about that other player, any way to find out the variable to control? maybe I can ask the dev, it's open source and does support media keys via the keyboard, so there must be some way.

As far as I can tell, the other player uses the YouTube commands, so I would skip it and send the commands directly to the YouTube webpage. Why not cut out the middleman?

If you want to pursue it, ask the developer if his app has an AppleScript dictionary.


Basically, you will want to look at each individual player and see if it has an AppleScript dictionary.


The k kay will play/pause a YouTube video, depending on the video's current state.

All of the native YouTube keyboard shortcuts:

1 Like

thanks for all the info, it does use youtube, but sort of in the background, but maybe commands to youtube will work to control it.

I will play around with it all later, I dragged the app into script editor and hit file dictionary and it's not displayed and when I browse it's greyed out, so I don't think it is has one.

but I have contacted the dev before in the past he is nice, I can ask him if he supports any scripting.

FYI, if you use my YouTube Mover script above, it does work in the background (at least on my system).

YouTube—Mover—Skip 10 Forward.kmmacros (2.6 KB)

I do almost everything from background so that is helpful, when I imported yours it worked in safari, when I tried to swap out the name for Google chrome, it tells me this.

2020-09-10 15:02:26 Execute an AppleScript failed with script error: text-script:165:176: script error: A class name can’t go after this identifier. (-2740)

any idea?

Nope. I hate Chrome, and won't use it due to the many bugs.

Dust off your Sherlock Holmes hat and start investigating! :slight_smile:

lol, everyone hates chrome, I think I'm the only Mac user who doesn't use safari, I'll look around, maybe even ask on a script forum but they'll bite my head off most likely.

I know you said without any other app but if nothing works, try BeardedSpice

1 Like

I have it downloaded, just never really got around to trying it/figuring out exactly what it does, I didn't want it to interfere with my media shortcuts I've established using bettertouchtool and keyboard maestro.

I have used mac media forwarder before, and that worked, although I forgot what I used it for, to prioritize spotify over something but I forget what, but bearded spice does have a lot of sites and an option to suggest an app, so I will look it over one day.

tell application "Google Chrome"
repeat with thisWindow in windows
set cnt to 1
repeat with thisTab in (tabs of thisWindow)
if URL of thisTab contains "" then
set active tab index of thisWindow to cnt
set index of thisWindow to 1
exit repeat
end if
set cnt to cnt + 1
end repeat
end repeat
end tell

is how to control chrome if anyone doesn't hate chrome with all their heart.