2017-08-07 82 views
0

我想打開Finder中選定的組織模式文件,方法是雙擊它。但由於我在守護進程模式中使用Emacs,我想使用emacsclient命令。如何使用`emacsclient`命令在OS X上雙擊EMACS文件?

因此,主要想法是將命令emacsclient -c posixPathToFile包裝在AppleScript 應用程序中以將其打開。

tell application "Finder" 
    set fileAlias to the selection as alias 
    set fileName to name of fileAlias 
    set posixPath to POSIX path of fileAlias 
end tell 

-- tell application "Emacs" to activate 

try 
    do shell script "/usr/local/bin/emacsclient -c " & quoted form of posixPath 
end try 

我知道一些set命令是不需要的。我們假設這個腳本被保存爲Xemacs.app,並且我將這個應用關聯到總是打開.org文件。

使用此應用程序無法通過雙擊該文件,而是如果我在Finder中選擇文件,然後獨立調用Xemacs.app。爲什麼?我對AppleScript沒有足夠的信心去弄清楚會發生什麼。

所以解決方法是使用的Automator服務

on run {input, parameters} 

    set posixPath to POSIX path of input 


    tell application "iTerm" to do shell script "/usr/local/bin/emacsclient -c " & quoted form of posixPath 

    return input 

end run 

的服務是「在Emacs打開」

現在選擇一個文件,然後右鍵單擊並callig服務>「打開保存爲在Emacs中「工作並打開文件。

第一種方法有什麼問題?

+0

如何使應用程序與鴨嘴獸,並從那裏運行腳本,並與該鴨嘴獸應用程序相關聯自己喜歡的文件類型? – lawlist

+0

想法不是使用第三方工具 – m0ll3art

+0

下面是一個標題爲「Mac *上的Emacsdaemon和Emacsclient」的相關主題,它有幾個示例:https://emacs.stackexchange.com/questions/141/emacsdaemon-and- emacsclient-on-mac,這裏是reddit上的另一個相關線程:https://www.reddit.com/r/emacs/comments/1wu2ja/a_tip_for_os_x_users_using_emacs_daemon/?st=j639vmk6&sh=8bb51e73 Google關鍵字:「** emacsclient automator app emacs發現者**「 – lawlist

回答

0

好的,我解決了我的問題。問題來自於我對ScriptEditorAutomator之間的差異的誤解。如果我使用Automator創建應用程序並使用以前的腳本而不是使用ScriptEditor創建應用程序,那麼它將按預期工作。

可以通過在Automator中創建應用程序並運行shell腳本而不是將命令封裝在Ascript中來簡化該過程。

shell script Automator