15

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

  • 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 Nov 18 '11 at 11:16
4

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

  • 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 Apr 19 at 18:26
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?

  • 4
    All you do is surround the key you want to make into an icon like that with the <kb> HTML tag. – Wuffers Nov 17 '11 at 11:15
  • 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 Nov 17 '11 at 11:17
  • Ohh. Hm. Good question! – tekknolagi Nov 18 '11 at 8:45
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)

  • 1
    Or 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 Jun 9 '12 at 11:09
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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.