从Finder的上下文菜单创建新文本文件

所以我看到了关于TUAW的这篇文章关于NuFile,一个上下文菜单插件,为您提供了使用上下文菜单在Finder中创建新文件的快捷方式。

我觉得这听起来很酷,但我只会用它来创建文本文件所以我为Brent Simmons的免费软件写了一个AppleScriptBig Cat Scripts插件就是这样以下是如何使用它:

  1. 如果您还没有这样做,请下载并安装Big Cat Scripts

  2. Copy the script below, paste it into your script editor, and save it in your~/Library/Application Support/Big Cat Scripts/Files/我将脚本命名为“新文本文件”。

  3. Control-click in any Finder window and choose your script from the Scripts sub-menu.

  4. 将出现一个对话框,提示您输入文件名Enter a name, then click Create.

  5. The file will be created and opened for editing in your preferred text editor(见下文。)

这是脚本:

on main()
   tell application "Finder"
      try
         set _folder to (the target of the front window) as alias
      on error
         beep
      end try

      display dialog ¬
         "New text file name:" default answer "" buttons ¬
         {"Cancel", "Create"} default button 2
      set _fname to text returned of result
      if exists file _fname of _folder then
         display alert "A file named ‘" & _fname & ¬
            "’ already exists in this folder." as informational
         return -- ends script
      end if

      set _path to quoted form of ((POSIX path of _folder) & _fname)
      do shell script "bbedit " & _path
   end tell
end main

做shell脚本脚本末尾的行假定您最喜欢的文本编辑器有一个命令行工具,并且该工具在shell中可用路径如果您使用TextWrangler,请更改“的BBEdit“工具”编辑”; if you use TextMate, change it to “伴侣”; and if you use SubEthaEdit, change it to “看到”。