Mac 配置Finder當(dāng)前目錄打開(kāi)iTerm2

[TOC]

說(shuō)明

在Finder加上一個(gè)打開(kāi)當(dāng)前路徑的終端的功能有三種實(shí)現(xiàn)

FinderGo AppGo2Shell AppAppleScript

FinderGo.app

推薦這個(gè)方式,兼容性和適配更好,如果想更快速在當(dāng)前目錄打開(kāi) iterm2,建議配合 AppleScript 方式

使用方法源碼地址的文檔有介紹,支持 iterm2 hyper Terminal 三種方式

Go2Shell.app

使用方法

  • Go2Shell官方安裝 http://zipzapmac.com/Go2Shell

  • 蘋(píng)果應(yīng)用商店安裝Go2Shell

  • 直接拖拽到 Finder 里即可. 10.10 以后需要按著 command 進(jìn)行拖拽

Paste_Image.png

進(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 使用

image.png

填寫(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)

image.png

點(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
Paste_Image.png
  • 從左側(cè)的資源庫(kù)中找出 運(yùn)行AppleScript,拖到右側(cè),然后保存為Open iTerm Here
Paste_Image.png
  • 在剛剛創(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)前目錄了
Paste_Image.png
  • 注意,這個(gè)方式在 macOS 10.12 以后,重啟系統(tǒng)或者 Finder 后,手動(dòng)激活 Finder 的這個(gè)自定義服務(wù),才能生效
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容

  • 【本篇博客為自己查詢(xún)方便所做,如果您能從中受益,筆者會(huì)感到榮幸】 軟件和目錄結(jié)構(gòu)層面 ~/Library/Appl...
    清水蘆葦閱讀 3,436評(píng)論 3 4
  • 這是我這段時(shí)間寫(xiě)的關(guān)于Mac Finder的一系列知識(shí)和操作技巧,現(xiàn)在整理出來(lái),希望大家能夠喜歡。我也將會(huì)繼續(xù)奉獻(xiàn)...
    Mac高級(jí)玩家閱讀 115,950評(píng)論 11 236
  • iTerm2介紹 本文初衷 整理自己腦袋中、收藏中的那些資料,來(lái)一次清空,讓自己重新開(kāi)始。 幫助 Mac 后來(lái)者,...
    UPUPMO閱讀 11,099評(píng)論 6 88
  • 在手機(jī)中 你讓我聽(tīng) 屏息凝氣 隱約傳來(lái) 鐘聲低沉 在風(fēng)中 抗?fàn)帯㈩澏丁⒀蜎](méi) 喘息、明滅、消散 只剩下風(fēng) 蒼涼呼嘯
    Anand02閱讀 141評(píng)論 0 1
  • 煙柳紅霞何顧,醉夢(mèng)繁世沉浮。 十年纖柔心墓,倩影婆娑輕撫。 許卿一生共度,月下杯酒瑩燭。 往日時(shí)光傾覆,風(fēng)塵伴君莫舞。
    明月笑忘書(shū)閱讀 116評(píng)論 0 0