Making Mac media keys open app other than iTunes

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?)


Solution 1:

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

Solution 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?