Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@johnfmorton
Last active May 30, 2023 14:42
Show Gist options
  • Star 29 You must be signed in to star a gist
  • Fork 14 You must be signed in to fork a gist
  • Save johnfmorton/e97298dfc57d6f1ad0e295973323da4b to your computer and use it in GitHub Desktop.
Save johnfmorton/e97298dfc57d6f1ad0e295973323da4b to your computer and use it in GitHub Desktop.
Use Transmit 5 to open in iTerm (instead of Terminal.app) as mentioned here https://library.panic.com/transmit5/open-in-terminal/
on openTerminal(location, remoteHost, serverPort)
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 targetTab to ""
set sshCommand to ""
if ((count of remoteHost) is greater than 0) then
set cdCommand to " 'cd \"" & location & "\"; eval \"$SHELL -il\"'"
set sshCommand to "ssh -t " & "'" & remoteHost & "'"
else
set cdCommand to "cd \"" & location & "\""
end if
if (serverPort is greater than 0) then
set sshCommand to sshCommand & " -p " & serverPort
end if
set sshCommand to sshCommand & cdCommand
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
if ((count of sshCommand) is greater than 0) then
tell current session to write text sshCommand
end if
end tell
end tell
end openTerminal
@niladam
Copy link

niladam commented Oct 24, 2017

Exactly what i was looking for. Thanks, i've forked :)

@jkubler
Copy link

jkubler commented May 8, 2018

Works great, thanks!!

@aviman1109
Copy link

I tried to open a folder in Transmit , but its not work .
Only toke me to ~/
So I modified the txt . Make it work.
Is there anything wrong?

on openTerminal(location, remoteHost, serverPort)

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 targetTab to ""
	set sshCommand to ""

	if ((count of remoteHost) is greater than 0) then
		set cdCommand to " 'cd \"" & location & "\"; eval \"$SHELL -il\"'"
		set sshCommand to "ssh -t " & "'" & remoteHost & "'"
	else
		set cdCommand to "cd \"" & location & "\""
	end if

	if (serverPort is greater than 0) then
		set sshCommand to sshCommand & " -p " & serverPort
	end if

	set sshCommand to sshCommand & cdCommand

	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
		if ((count of sshCommand) is greater than 0) then
			tell current session to write text sshCommand
			
	end if

	end tell
end tell

end openTerminal

@uryossa
Copy link

uryossa commented Mar 27, 2019

@aviman1109
thx
it works at transmit 5 and iTerm2.

@dsculptor
Copy link

Thanks @johnfmorton.

@dsculptor
Copy link

BugFix:

@igormakovsky
Copy link

Thanks @johnfmorton! I'm fairly a newbie, how do I implement this?

@johnfmorton
Copy link
Author

Updated per @aviman1109.

@igormakovsky, Check out the instructions at https://library.panic.com/transmit/transmit5/open-in-terminal/. Basically, you need to save the script (updated 21JUN2020) to a directory on your Mac. Then run the command mentioned on that page:

$ defaults write com.panic.Transmit OpenTerminalScriptPath ~/Scripts/TransmitOpenTerminal.txt

That tells Transmit to user your custom script instead of the one built into Transmit by default.

@PrestaSafe
Copy link

Hi, there is a way to include the password in the command ?

@robetus
Copy link

robetus commented Jul 9, 2022

Is there a wall to pull the User Name from transmit and put it into the Open in Terminal script? I noticed on macos Monterey it wants a username and when I use the default open in terminal script it doesn't show the User Name from transmit.

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