2

I use saavn.com for listening to bollywood music. It's a great service but they don't have native mac app so I can't control it using keyboard media keys.

There must be a way to use keyboard media keys to control all music.

Karan
  • 57,289

2 Answers2

6

You could assign a shortcut to a script like this:

tell application "Safari"
    repeat with t in documents
        tell t
            if URL starts with "http://www.saavn.com/" then
                do JavaScript "e = document.querySelectorAll('#pause:not(.hide)')[0] || document.querySelectorAll('#play:not(.hide)')[0]; e.click()"
                exit repeat
            end if
        end tell
    end repeat
end tell

A similar script for YouTube and Chrome:

tell application "Google Chrome"
    repeat with t in tabs of windows
        tell t
            if URL starts with "http://www.youtube.com" then
                execute javascript "player = document.querySelectorAll('#player embed')[0]
if (player) {
    player.getPlayerState() == 1 ? player.pauseVideo() : player.playVideo()
} else { // if youtube.com/html5 is enabled
    document.querySelectorAll('.html5-player-chrome > button:first-child')[0].click()
}"
                exit repeat
            end if
        end tell
    end repeat
end tell
Lri
  • 42,502
  • 8
  • 126
  • 159
0

For the keyboard part I would use keyremap4macbook - this will allow you to intercept media keys. I can also launch scripts for keypresses (@lauri-rantas answer covers that nicely). Unfortunately it also needs some coding to adjust it to ones needs.

What I like about it is:

  • you will even be to override the media keys and "caps-lock"
  • one can also differenciate between left-shift, control, command keys and the corresponding right ones
  • the remappings can depend on which app is in foreground - so your mapping won't interfere with other media players
bdecaf
  • 468