【问题标题】:Open a Mac application using Coffescript使用 Coffeescript 打开 Mac 应用程序
【发布时间】:2014-03-14 02:06:43
【问题描述】:

我正在为 Git 的 Atom 文本编辑器编写一个包,它使用 Coffeescript。我有一个键绑定,它将启动我正在创建的功能。

我需要写什么来简单地打开一个应用程序?在这种情况下,我想打开 Transmit.app。

【问题讨论】:

  • 这是作为初始化脚本的一部分还是在一个包中?

标签: node.js coffeescript atom-editor


【解决方案1】:

使用来自 node 的 spawn 或来自 Atom 的内置 BufferedProcess 运行进程非常简单。 BufferedProcess 包装 spawn 并提供标准输出和错误行缓冲。

来自the docs的示例:

{BufferedProcess} = require 'atom'

 command = 'ps'
 args = ['-ef']
 stdout = (output) -> console.log(output)
 exit = (code) -> console.log("ps -ef exited with #{code}")
 process = new BufferredProcess({command, args, stdout, exit})

来自atom-script的更多充实示例(修改):

{BufferedProcess} = require 'atom'

command = "open"
args = ["/path/to/Transmit.app"]

# Default to where the user opened atom
options =
  cwd: atom.project.getPath()
  env: process.env

stdout = (output) -> console.log(output)
stderr = (output) -> console.error(output)

exit = (return_code) ->
  if return_code is 0
    console.log("Exited with 0")
  else
    console.log("Exited with " + return_code)

# Run process
bufferedProcess = new BufferedProcess({command, args, options, stdout, stderr, exit})

如果你选择重生路线,我建议你看看 test-status 是如何做到的。

【讨论】:

    【解决方案2】:

    我的快速谷歌搜索说 Atom 编辑器集成了 nodejs,所以你应该可以使用child_process.spawn

    {spawn} = require 'child_process'
    spawn 'path/to/your/transmit/app'
    

    【讨论】:

      猜你喜欢
      • 2019-06-22
      • 2015-10-17
      • 2021-04-02
      • 2019-01-21
      • 1970-01-01
      • 2015-05-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多