`
denger
  • 浏览: 356929 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

为Finder Toolbar 添加 OpenInTextMate

阅读更多
    TextMate作为Mac coder 最常用的 开发工具之一,当我们想用 TextMate打开当前所在目录或当前选中的文件时,如果希望可以快捷操作的话,除了可以自己使用快捷键外,还可以通过自定义 Finder Toolbar 为其添加一个 Open in textmate 的 button。效果图如下:


     其原理是通过获取当前选中的文件或当前所在目录,然后将其具体路径在作为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" )。
  • 大小: 58.6 KB
1
5
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics