[TOC]
說(shuō)明
在Finder加上一個(gè)打開(kāi)當(dāng)前路徑的終端的功能有三種實(shí)現(xiàn)
FinderGo App
, Go2Shell App
和 AppleScript
FinderGo.app
推薦這個(gè)方式,兼容性和適配更好,如果想更快速在當(dāng)前目錄打開(kāi) iterm2,建議配合 AppleScript 方式
應(yīng)用下載位置 FinderGo1.1.0
使用方法源碼地址的文檔有介紹,支持 iterm2 hyper Terminal 三種方式
Go2Shell.app
使用方法
Go2Shell官方安裝 http://zipzapmac.com/Go2Shell
蘋(píng)果應(yīng)用商店安裝Go2Shell
直接拖拽到 Finder 里即可.
10.10
以后需要按著command
進(jìn)行拖拽
進(jìn)入 Preferences 的方式
# 新老版本都可以通過(guò)命令行打開(kāi)
open -a Go2Shell --args config
# v2.3 直接在應(yīng)用文件中打開(kāi) Go2Shell 就行
優(yōu)點(diǎn):Find直接點(diǎn)Go2Shell按鈕就可以在當(dāng)前目錄打開(kāi)終端了
缺點(diǎn):iTerm2 APPStore 版本每次都是在新的終端窗口中打開(kāi),而不是在新的終端標(biāo)簽中打開(kāi)
更新 Go2Shell 經(jīng)過(guò)測(cè)試 2.3 版本可以在 MacOS 10.11 使用
填寫(xiě)內(nèi)容為
cd %PATH%; clear; echo -e "Last login: `date`"; pwd
使用方法,按圖內(nèi)的設(shè)置,點(diǎn)擊 Install Go2Shell from Finder
Finder 出現(xiàn)圖標(biāo)
點(diǎn)擊右邊這個(gè)>_<
圖標(biāo),就可以在 iterm2 中以新窗口的模式打開(kāi)一個(gè) terminal
刪除這個(gè)功能,或者圖標(biāo)顯示錯(cuò)誤很好處理,按住
cmd
鍵,鼠標(biāo)拖拽這個(gè)圖標(biāo)到外面釋放圖標(biāo),就可以刪除這個(gè)功能了
配置Automator方法-推薦
- 打開(kāi)
Automator
,選擇新建
,選擇服務(wù)
- 服務(wù)接受設(shè)為
沒(méi)有輸入
,位置設(shè)為Finder
- 從左側(cè)的資源庫(kù)中找出
運(yùn)行AppleScript
,拖到右側(cè),然后保存為Open iTerm Here
- 在剛剛創(chuàng)建的
AppleScript
的輸入框中輸入如下代碼
on run {input, parameters}
tell application "Finder"
set pathList to (quoted form of POSIX path of (folder of the front window as alias))
set command to "clear; cd " & pathList
end tell
tell application "System Events"
-- some versions might identify as "iTerm2" instead of "iTerm"
set isRunning to (exists (processes where name is "iTerm")) or (exists (processes where name is "iTerm2"))
end tell
tell application "iTerm"
activate
set hasNoWindows to ((count of windows) is 0)
if isRunning and hasNoWindows then
create window with default profile
end if
select first window
tell the first window
if isRunning and hasNoWindows is false then
create tab with default profile
end if
tell current session to write text command
end tell
end tell
end run
代碼意思是將當(dāng)前最前面的Finder地址如果獲取不到,則返回桌面地址
然后通知iTerm的第一個(gè)窗口新建標(biāo)簽并跳到這個(gè)目錄去
- 為了避免每次都要去點(diǎn)菜單,再去鍵盤(pán)設(shè)置里改一下快捷鍵,然后就可以快速在Finder中通過(guò)iTerm打開(kāi)當(dāng)前目錄了
- 注意,這個(gè)方式在 macOS 10.12 以后,重啟系統(tǒng)或者 Finder 后,手動(dòng)激活 Finder 的這個(gè)自定義服務(wù),才能生效