Making Mac media keys open app other than iTunes

16

2

On a Mac, when one presses the Press/Play media key (F8), and no application intercepts that key, it opens iTunes and starts playing. Is there any way to get it to open another app? In my case, I want it to open Spotify. Bonus if it's possible to get it to start playing on launch (Maybe AppleScript is the way to go for this?)

Wuffers

Posted 2011-10-10T02:15:30.213

Reputation: 16 645

1@Lri my question is not a duplicate. I want to know how to make it open Spotify, not just how to keep it from opening iTunes. – Wuffers – 2011-11-18T11:16:27.513

Answers

5

I know this question is old, but other answers don't really solve the problem.

All you have to do is to install Karabiner (previously known as KeyRemap4MacBook).

Then you just have to add the wanted behavior.

  • Open Preferences menu.
  • Switch to Misc & Uninstall tab
  • Click on Open private.xml
  • Open the file private.xml in your favorite Text Editor
  • Replace the empty file by this definition :

    <?xml version="1.0"?>
    <root>
        <!-- Spotify Path -->
        <vkopenurldef>
            <name>KeyCode::VK_OPEN_URL_APP_Spotify</name>
            <url type="file">/Applications/Spotify.app</url>
        </vkopenurldef>
    
        <!-- Set Spotify definition -->
        <appdef>
            <appname>SPOTIFY</appname>
            <equal>com.spotify.client</equal>
        </appdef>
    
        <!-- Use 'Music Play' key to launch Spotify if not ever in the application -->
        <!-- else, act as normal play/pause button in Spotify, Itunes -->
        <item>
            <name>Change Play key to launch Spotify</name>
            <identifier>private.play_launch_spotify</identifier>
            <not>SPOTIFY, ITUNES</not>
            <autogen>
                __KeyToKey__,
                ConsumerKeyCode::MUSIC_PLAY,
                KeyCode::VK_OPEN_URL_APP_Spotify,
            </autogen>
        </item>
    </root>
    
  • Go back to Change Key tab and click on Reload XML button.

  • You now just have to enable the new item added at the top of the list:

    Screenshot

Guillaume

Posted 2011-10-10T02:15:30.213

Reputation: 59

How can I do this with Karabiner Elements (the original Karabiner had to be scrapped for newer versions of macOS, replaced with Karabiner Elements)? Perhaps I can specify a complex modification by adding entries to the .config/karabiner/karabiner.json file?

– Luke Davis – 2019-04-19T18:26:35.003

2

You might find this useful, too. How to prevent iTunes from launching on media key press

Spotify should respond to F8 by default. How do you get the awesome key icon?

tekknolagi

Posted 2011-10-10T02:15:30.213

Reputation: 1 130

4All you do is surround the key you want to make into an icon like that with the <kb> HTML tag. – Wuffers – 2011-11-17T11:15:58.417

And Spotify does respond to F8, but only when it's running. What I want to know is how to make this key launch Spotify if neither it not iTunes are running. – Wuffers – 2011-11-17T11:17:02.817

Ohh. Hm. Good question! – tekknolagi – 2011-11-18T08:45:42.280

0

I would add a custom Keyboard Shortcut to your Function Keys F8-F12.

Normally you would access these function keys by holding fn and the associated Media Key. For example F8 = fn + (Play/Pause on newer Macbook Pros)

In order to make the function keys, rather than their media key functionality, default I would use Function Flip (Free)

jds

Posted 2011-10-10T02:15:30.213

Reputation: 632

1Or to disable the special key functionality, go into System Preferences -> Keyboard and check "Use All F1, F2, etc, keys as standard function keys". And Voila, they now start showing up as F1, F2, F3, etc... – Benjamin Schollnick – 2012-06-09T11:09:39.267

0

To open Spotify and play a song on launch you could do this in AppleScript:

tell application "Spotify"
activate
    play track "spotify:track:trackURI"
end tell

Export this script as an Application with the option "Save as executable script" (or something similar).

Then, to map your f8 key to this script, go to System Preferences, and then under "Keyboard" enable "Use All F1, F2, etc, keys as standard function keys". For the next step, you need to switch to the "Keyboard Shortcuts" tab and add a new Keyboard Shorcut under Applications that will open the AppleScript. (If I remember correctly, you have to reboot your computer or log out for the changes to take place)

rien333

Posted 2011-10-10T02:15:30.213

Reputation: 137