Skip to content

Instantly share code, notes, and snippets.

@pn11
Last active June 1, 2019 10:11
Show Gist options
  • Save pn11/b4819ed99af608fa4bcd to your computer and use it in GitHub Desktop.
Save pn11/b4819ed99af608fa4bcd to your computer and use it in GitHub Desktop.
ROOT fileをFinderで選択してiTerm2で開く

ROOT fileをFinderで選択してiTerm2で開く

先日書いたこれのCUI版。iTerm2のAppleScriptにファイル名を渡すだけのワークフローをAutomatorでつくった。Serviceとして登録してFinderから呼び出せるようにした。 iTerm2のApple Scriptはこれをつくったときのを用意して、あとはAppleScriptに変数を渡す方法と、Stringの扱いと、POSIX ofていうよくわからないのをみつけてできた。

やってること

以下のようなAppleScriptを画像のようにAutomatorに入れてサービスをつくればよい。サービスは新規作成でつくれる。保存すれば勝手に登録されて、呼び出すときはFinderでファイルを選択して右クリック->Servicesでいける。

on run {input, parameters}
	
	set fileName to POSIX path of item 1 of input
	
	tell application "iTerm"
		activate
		
		set t to (make new terminal)
		
		tell t
			set number of columns to 100
			set number of rows to 30
			
			set s to (launch session "Default session")
			tell s
				write text "root " & fileName
				write text "_file0->ls()"
			end tell
		end tell
	end tell
	
	return input
end run

fig1

Automator内でテストしたいときはこれだけでは動かず、Ask for Finder Itemsを前に挿入する。

参考にさせていただいたページ

AppleScriptに変数を渡す方法について

Serviceのつくりかた、POSIX of について

文字列の扱い

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment