[转][笔记]Mac Finder 从当前位置打开终端
2016-09-07 本文已影响205人
C86guli
原文地址:http://www.shannap.com/mac-finder-to-terminal.html
Mac 的 Finder 基本功能相对还是比较弱的,对于程序员来说,常常要用到从当前位置打开 Terminal 。在 App Store 上你可以找到一个叫 Go2Shell 的软件,可以实现这个功能。但是这么简单的事情,我确实不大愿意用 App Store 安装一个软件,于是自己写了个简单的 AppleScript 脚本,用法以及效果和 Go2Shell 一样,估计它的方法和我也是一样的。
打包好的程序点此下载,下载后按住command键,把它拖动到 Finder 的工具栏上即可。

如果不想用我打包好的话,那么代码如下。
set cmd to ""
tell application "Finder"
set theWindow to window 1
set thePath to (POSIX path of (target of theWindow as alias))
set cmd to "cd " & "\"" & thePath & "\""
end tell
tell application "Terminal"
activate
tell application "System Events" to keystroke "t" using command down
delay 0.5
do script cmd in window 1
end tell
把代码保存成 .scpt 文件,双击打开,另存为 Application 类型,这样就会得到一个 .app 文件,把它拉到 Finder 的工具栏。
把代码保存成 .scpt 文件,双击打开,选择: 文件->导出

文件保存格式选择:应用程序

得到一个 .app 文件,按住 comand 键,把它拉到 Finder 的工具栏。
