Frage

Is it possible to run a Node.js Command line app and control it via keystrokes? E.g. think of "Alfred" (Mac OS) which runs invisible in the background, but opens if you press ⌘⌥.

I know it is possible to detect keystrokes, if you set "process.stdin.setRawMode(true);" but this doesn't seem to register ⌘ keystrokes. Do I need additional technoligy? (E.g. AppleScript?)

Thank you, Pipo

War es hilfreich?

Lösung

There are two parts to this question:

  1. Running a command line app in the background
  2. The app receiving commands from global shortcuts

To answer number 1, look at https://superuser.com/questions/334597/enable-disable-startup-programs-script-services-on-amac. If you want your script to be shutdown/restarted easily from the command line, I would go with suggestion 4 and use launchd.

To answer number 2, look at the second answer here: https://apple.stackexchange.com/questions/24063/create-global-shortcut-to-run-command-line-applications After mentioning a large number of third party apps that can do this, it mentions how to use the Automator service to run scripts from shortcuts.

Since this is a node.js specific question, I would probably hook a little server into my script that listens for commands sent from other scripts (which are assigned a keyboard shortcut each). Dnode is excellent, if you want to perform "Remote Procedure Calls" on your "server script" from very simple "client scripts".

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top