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 ⌘⌥.
是否可以运行节点。js命令行应用,通过按键控制?如认为“阿尔弗雷德”(Mac OS),无形的在后台运行,但如果你按下打开⌘⌥。
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?)
我知道它可以检测按键,如果您设置“process.stdin.setRawMode(真正);“但这似乎没有注册⌘按键。我需要额外的技术吗?(例如AppleScript ?)
Thank you, Pipo
谢谢你,的态度
1 个解决方案
#1
3
There are two parts to this question:
这个问题有两部分:
- Running a command line app in the background
- 在后台运行命令行应用程序
- 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
.
要回答第一个问题,请查看https://superuser.com/questions/334597/enabledisable -startup- programs-script-services-- on amac。如果您希望您的脚本能够轻松地从命令行关闭/重新启动,我将使用建议4并使用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.
要回答第2个问题,请查看第二个答案:https://apple.stackexchange.com/questions/24063/create-global- global- short- run-command-line-applications,在提到大量的第三方应用程序可以做到这一点后,它提到了如何使用Automator服务来从快捷方式中运行脚本。
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".
因为这是一个节点。特定于js的问题,我可能会在脚本中挂起一个小服务器来监听从其他脚本发送的命令(每个脚本都有一个键盘快捷键)。Dnode非常棒,如果您想在“服务器脚本”上执行“远程过程调用”,请使用非常简单的“客户端脚本”。
#1
3
There are two parts to this question:
这个问题有两部分:
- Running a command line app in the background
- 在后台运行命令行应用程序
- 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
.
要回答第一个问题,请查看https://superuser.com/questions/334597/enabledisable -startup- programs-script-services-- on amac。如果您希望您的脚本能够轻松地从命令行关闭/重新启动,我将使用建议4并使用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.
要回答第2个问题,请查看第二个答案:https://apple.stackexchange.com/questions/24063/create-global- global- short- run-command-line-applications,在提到大量的第三方应用程序可以做到这一点后,它提到了如何使用Automator服务来从快捷方式中运行脚本。
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".
因为这是一个节点。特定于js的问题,我可能会在脚本中挂起一个小服务器来监听从其他脚本发送的命令(每个脚本都有一个键盘快捷键)。Dnode非常棒,如果您想在“服务器脚本”上执行“远程过程调用”,请使用非常简单的“客户端脚本”。