2014-03-14 110 views
0

我正在爲Git編寫Atom文本編輯器的包,它使用Coffeescript。我有一個鍵綁定,將啓動我創建的功能。使用Coffescript打開Mac應用程序

我需要寫什麼來簡單地打開應用程序?在這種情況下,我想打開Transmit.app。

+0

這是否會作爲您的init腳本的一部分或包? –

回答

1

我的快速谷歌搜索表示,Atom編輯器有nodejs集成,所以你應該能夠使用child_process.spawn

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

運行的進程是非常有spawn從節點簡單或原子內置BufferedProcessBufferedProcess包裝產卵並提供標準輸出和錯誤行緩衝。從atom-script

{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}) 

更充實例(修改):從the docs

{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是怎麼做的。

相關問題