其原理是通过获取当前选中的文件或当前所在目录,然后将其具体路径在作为open 参数传递给 textmate。以下是 AppleScript的实现:
-- Opens the currently selected Finder files, or else the current Finder window, in TextMate. Also handles dropped files and folders. -- By Henrik Nyh -- script was clicked on run tell application "Finder" if selection is {} then set finderSelection to folder of the front window as string else set finderSelection to selection as alias list end if end tell tm(finderSelection) end run -- script was drag-and-dropped onto on open (theList) tm(theList) end open -- open in TextMate on tm(listOfAliases) tell application "TextMate" open listOfAliases activate end tell end tm
可以看出 AppleScript 的代码可读性还是很不错的,比如 set finderSelection to folder of the front window as string ,获取当前窗体的路径将其转化为string 并赋值给finderSelection变量,看上去就是一句完整英文句子。
其App文件已经找打包好了在附件中,直接下载解压后并将APP文件其拖拽至Finder 中的 ToolBar 位置即可,如果自己想给改变其图标,可以右键该 App ,选择 "Show Package Contents" ,在 Resources 可以看到图标,并可将其替换。其中代码在 Scripts目录中,有兴趣可以看看,并可以通过这种方式可以自定义更多的方便快捷的 ToolBar Button,比如附件中另外一个实用的button,打开当前目录的终端("Open Terminal Here" )。