2010-02-02 74 views
3

如何设置所有.rb文件或所有.py文件在emacs中打开,如果我双击它们;说,从桌面?直接打开一个文件到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的:标准输入是不是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 
+0

我认为这将属于superuser.com – 2010-02-02 18:24:39

+0

我没有发布它的原因是我假设它会涉及一个bash脚本 - 这对我来说似乎是对的。但如果它不属于它,就移动它! – Isaac 2010-02-02 18:25:20

+0

在理想的世界里,它会去那里。可悲的是,我还没有在开发人员不希望自己设置emacs的环境中工作(或者更可能的是,使用一些低级编辑器......并*喜欢它*)。 – 2010-02-02 18:48:36

回答

3

对于每种类型的,请在Finder文件,选择文件菜单Get Info。在打开的信息窗口中,在Open with部分下,选择您正在使用的emacs应用程序(它必须是应用程序版本),然后按Change All..

如果您使用命令行中的传统curses emacs,则可以在ScriptEditor或Automator操作中构建一个小AppleScript应用程序,该应用程序将从Finder接收文件并使用它们打开emacs。然后使用Get Info将该应用与.rb和.py文件相关联。

编辑:看到这个recent answer的一种方式来创建一个AppleScript启动程序的应用程序:只需修改shell命令来调用emacs代替。

更多编辑:您的脚本几乎在那里,但您需要运行Terminal.app下的脚本。尝试修改它,如下所示:

 launch application "Terminal" 
     tell application "Terminal" 
      do script "cd '" & base & "';" & " emacs " & fname 
     end tell 
+0

这里的问题是我使用终端 - 如果它很简单,我会做到这一点! – Isaac 2010-02-02 18:48:34

+0

@Isaac铜。在你提到的问题中,你点击一个文件来打开它。你在码头怎么做? – chollida 2010-02-02 18:58:59

+0

正如我在问题中所说 - 我是从桌面双击。 – Isaac 2010-02-02 19:26:08

1

我不是OS X的专家,但如果emacs的有像它在Unix和Windows上,它应该有一个emacsclient实用程序,用于喂养新文件到一个已经运行的Emacs会话。

This previous SO question有一些关于如何在多重设置上执行此操作的详细信息。也许有些适用?