Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Chrome "packaged apps" respond to global keyboard commands?

I've recently switched from Spotify to Google Music, but miss having a desktop client that responds to keyboard commands. In particular, my laptop has media keys and my fingers keep going to them out of muscle memory.

Media keys found on google images

To remedy this (and other irritations), I've turned Google Play into a packaged app: "Package All Areas"

Unfortunately, I can't seem to find any documentation on getting packaged apps to respond to keyboard shortcuts. Is this possible? Doesn't have to be media keys (if they're tricky), but I'd prefer it if they triggered from anywhere in the OS.

like image 370
Tom Wright Avatar asked Aug 13 '13 15:08

Tom Wright


1 Answers

since chrome 25, there is chrome.commands, and since chrome 35 commands can have global scope (see headline 'Scope').

EDIT: i posted before that the commands api is only available to extensions (and not to 'packaged apps'), because only extensions are explicitly mentioned in the docs - just tried it on a packaged app though, and BOOM - it works :)

EDIT II: although the docs state that "the extension developer is limited to specifying only Ctrl+Shift+[0..9] as global shortcut", i successfully tried using 'MediaPlayPause' as a global shortcut on OSX (thanks to user Xan for pointing me there)

manifest.json:

  "app": {
    "background": {
      "scripts": ["main.js"]
    }
  },
  "commands": {
    "toggle-feature-foo": {
      "suggested_key": {
        "default": "Ctrl+Shift+5"
      },
      "description": "Toggle feature foo",
      "global": true
    }
  }

main.js:

chrome.commands.onCommand.addListener(function(command) {
    console.log('command:',command);
});
like image 153
schellmax Avatar answered Sep 30 '22 18:09

schellmax