为Finder Toolbar 添加 OpenInTextMate

TextMate作为Mac coder 最常用的 开发工具之一,当我们想用 TextMate打开当前所在目录或当前选中的文件时,如果希望可以快捷操作的话,除了可以自己使用快捷键外,还可以通过自定义 Finder Toolbar 为其添加一个 Open in textmate 的 button。效果图如下:
[img]http://dl.iteye.com/upload/attachment/466190/88f46c4c-b969-3a26-ab4b-59f63ea59169.png[/img]

其原理是通过获取当前选中的文件或当前所在目录,然后将其具体路径在作为open 参数传递给 textmate。以下是 AppleScript的实现:
[code]-- 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[/code]

可以看出 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" )。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值