from finder go to same directory in terminal (iterm2)

Description of what you are sharing

The idea is motivated by the new format of preset sharing.
You can easily open the finder to the correct place but the path is ugly.
So not easy to find to move to the correct path inside a terminal.
So a bit of applescript and you can have a button creating a new tab in iterm2 and that tab point to the correct directory:
Here is the script:

tell application "Finder"
	set currentDir to target of Finder window 1 as alias
end tell
set mydir to POSIX path of currentDir

tell application "iTerm"
	if (count of window) = 0 then
		set awindow to (make new window)
	end if
	repeat with awindow in windows
		if profile name of current session of awindow = "Default" then
			set currwindo to awindow
			exit repeat
		end if
	end repeat
	tell awindow
		set mytab to create tab with default profile
		tell (first session of mytab)
			write text "cd " & mydir
		end tell
	end tell
end tell
Imprint | Privacy Policy