思い立ったが吉日!

iOSが好きです。

[mac]iTerm2をupdateしたらgo2shellが現在ディレクトリに移動してくれなくなったのでapplescriptに乗り換えた

iTerm2をupdateしたらgo2shellが現在ディレクトリに移動してくれなくなったのでapplescriptに乗り換えた


今まではgo2shellというアプリをインストールしてFinderのツールバーに常駐させて使っていたのですが、iTermをアップデートしたタイミングで、go2shellしてiTermを開くとホームディレクトリで開かれるようになってしまった。

Finderで見てるカレントディレクトリに行ってくれるべんり君だったのに...

代替アプリを探してたらautometerやapplescriptでできるみたいだったので、何個か記事見た結果applescriptのが良さそうだったので参考にさせていただきました。

applescriptを開いて

f:id:watarotten:20160919233059p:plain

tell application "iTerm"
    activate
end tell

tell application "Finder"
    set _dir to POSIX path of ((folder of (front window)) as alias)
end tell

tell application "iTerm"
    activate
    
    set _current_session to current session of current window
    
    tell _current_session
        write text "cd \"" & _dir & "\""
    end tell
end tell

上記コードをコピペ。

f:id:watarotten:20160919233134p:plain

「iTermを開く」とかで「アプリケーション」として保存。

f:id:watarotten:20160919233423p:plain

これで、Finderで見ている時にiTermを開きたくなったらこのファイルを実行すれば、iTermでカレントディレクトリを開いてくれます。

Finderツールバーに追加するには、保存したファイルをcmd+ドラッグでツールバーの上に持っていけばツールバーに追加され実行ファイル探さなくていいのでラクです。

f:id:watarotten:20160919234055p:plain

こんな感じで追加出来ます。

まだgo2shellが右に生きてますが...

参考

starzero.hatenablog.com

qiita.com

apple.stackexchange.com