如果我想让所有的 .rb 文件或 .py 文件在我双击它们时都用 emacs 打开,该怎么做呢?例如从桌面上打开这些文件。
我的操作系统是 OS X 10.6.2。
我有以下脚本:
on open of finderObjects
repeat with currFile in finderObjects
set unixPath to POSIX path of currFile
set base to do shell script "dirname " & unixPath
set fname to do shell script "basename " & unixPath
do shell script "cd '" & base & "';" & " emacs " & fname
end repeat
end open
但是如果我将一个文件(text.py - 只打印一行)拖到它上面,我会收到以下信息:emacs: standard input is not a tty。
我不确定如何解决这个问题。谢谢!
编辑:通过链接解决:http://www.macosxhints.com/article.php?story=20031027142625782
set filecount to 0
on open filelist
repeat with i in filelist
set filecount to 1
tell application "Terminal"
set filename to do shell script ¬
"perl -e \"print quotemeta ('" & POSIX path of i & "');\""
do script "emacs " & filename & "; exit"
end tell
end repeat
end open
if filecount < 1 then
tell application "Terminal"
do script "emacs; exit"
end tell
end if