Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save NicolasReibnitz/6a5fd0f7cc0a84776dd38a729eef455d to your computer and use it in GitHub Desktop.

Select an option

Save NicolasReibnitz/6a5fd0f7cc0a84776dd38a729eef455d to your computer and use it in GitHub Desktop.

Revisions

  1. @johnfmorton johnfmorton revised this gist Jun 21, 2020. 1 changed file with 35 additions and 35 deletions.
    70 changes: 35 additions & 35 deletions TransmitOpenTerminal.txt
    Original file line number Diff line number Diff line change
    @@ -1,44 +1,44 @@
    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 ""
    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
    set sshCommand to "ssh " & remoteHost
    else
    set cdCommand to "standalone"
    end if
    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
    if (serverPort is greater than 0) then
    set sshCommand to sshCommand & " -p " & serverPort
    end if

    set command to sshCommand
    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
    tell current session to write text cdCommand
    end if
    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 tell
    end tell

    end openTerminal
  2. @johnfmorton johnfmorton created this gist Jul 19, 2017.
    44 changes: 44 additions & 0 deletions TransmitOpenTerminal.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    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
    set sshCommand to "ssh " & remoteHost
    else
    set cdCommand to "standalone"
    end if

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

    set command to sshCommand

    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
    tell current session to write text cdCommand
    end if

    end tell
    end tell

    end openTerminal