Skip to content

Instantly share code, notes, and snippets.

@derralf
Last active May 22, 2020 16:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save derralf/09c2d85a65931a287b5206d230d05ed7 to your computer and use it in GitHub Desktop.
Save derralf/09c2d85a65931a287b5206d230d05ed7 to your computer and use it in GitHub Desktop.
Transmit 5 open in Terminal (local and remote with delay)
on openTerminal(location, remoteHost, serverPort)
#
# Problem with original script:
# on some hosters the shell is not recognized as interactive and some features like aliases and colors do not work
# so we dont use the combined command:
# ssh -t me@myserver.com "cd /directory/wanted ; eval $SHELL -il"
# but write the 2 commands (ssh + cd) separately into the terminal window with a delay(!) in between
#
# the original script:
# https://library.panic.com/transmit/transmit5/open-in-terminal/
#
tell application "Terminal"
activate
set targetTab to ""
set sshCommand to ""
if ((count of remoteHost) is greater than 0) then
## original: we don't use that
#set cdCommand to " 'cd \"" & location & "\"; eval \"$SHELL -il\"'"
#set sshCommand to "ssh -t " & "'" & remoteHost & "'"
# our own:
set cdCommand to "cd " & location
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
## original: don't put it together here
## we call it below separated from each other, with delay
#if ((count of location) is greater than 0) then
# set sshCommand to sshCommand & cdCommand
#end if
if (window 1 exists) and (window 1 is visible) and not (selected tab of window 1 is busy) then
set targetTab to selected tab of window 1
if ((count of sshCommand) is greater than 0) then
# remote
do script sshCommand in targetTab
delay 4
do script cdCommand in targetTab
else
# local
do script cdCommand in targetTab
end if
else
if ((count of sshCommand) is greater than 0) then
# remote
set targetTab to do script sshCommand
delay 4
do script cdCommand in targetTab
else
# local
set targetTab to do script cdCommand
end if
end if
end tell
end openTerminal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment