Go2Shell and AppleScript

Go2Shell and AppleScript

給Finder加上一個打開當前路徑的終端的功能

有兩種實現(xiàn):
Go2Shell App 和 AppleScript

擴展:

AppleScript 實現(xiàn) Go2Shell 一樣的可視化打開方式

一、Go2Shell

1. 安裝

1、Go2Shell官方安裝 (推薦,因為AppStore下載的版本太低,無法打開iTerm2 -坑-)
http://zipzapmac.com/Go2Shell

2、AppStore下載

至此就可以打開shell,不過僅僅是打開系統(tǒng)默認的終端shell

2. 進入 Preferences 的方式

open -a Go2Shell --args config

iTerm2 不能打開當前文件所在目錄()

3. 官網(wǎng)下載效果圖(多了個 >_< 能直接打開配置)

二、配置 Automator 方法

1. 新建 Automator 服務

打開Automator,選擇新建,選擇服務

2. 設置 Automator 服務

1、 服務接受設為沒有輸入,位置設為Finder(訪達)
2、 從左側(cè)的資源庫中找出 運行 AppleScript,拖到右側(cè),然后保存為Open iTerm Here

復制以下代碼

代碼意思是將當前最前面的Finder地址如果獲取不到,則返回桌面地址然后通知iTerm的第一個窗口新建標簽并跳到這個目錄去

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


3、點擊運行就能在 iTerm2 中打開當前目錄
4、 設置快捷鍵

打開系統(tǒng)設置,再去鍵盤設置里改一下快捷鍵,然后就可以快速在Finder中通過iTerm打開當前目錄了


三、擴展

Automator 創(chuàng)建應用

使用的 Automator AppleScript 時候就在想為什么使用創(chuàng)建的服務,好吧,換個思路創(chuàng)建個應用,嘗試著以Go2Shell的方式按住command鍵拖到文件夾上,結(jié)果和Go2Shell實現(xiàn)的效果一樣OK,對 Automator 的使用充滿期望~~

最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

友情鏈接更多精彩內(nèi)容