Skip to content

Instantly share code, notes, and snippets.

@codemedic
Last active April 5, 2022 01:39
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 codemedic/685c625daa86617ab24e28ec4402c5d3 to your computer and use it in GitHub Desktop.
Save codemedic/685c625daa86617ab24e28ec4402c5d3 to your computer and use it in GitHub Desktop.
Add SSH URL Handler for macOS

Dependencies

How to

Use Platypus to create org.codemedic.SSHHandler app, as an ssh URL handler, making use of the applescript below.

Not sure, but I am told to run it once to get the URL handler registered.

open -a org.codemedic.SSHHandler

Now we need to register the app as the default SSH URL handler. For this, make use of swda from SwiftDefaultApps.

./swda setHandler --URL ssh --application org.codemedic.SSHHandler

Thats it!

Now you can try it using open ssh://server.myhost.com from terminal.

#!/usr/bin/osascript
on openURL(theURL)
set colonIndex to offset of ":" in theURL
set sshCommand to "ssh " & (text (colonIndex + 3) thru (length of theURL) of theURL)
tell application id "com.googlecode.iterm2"
activate
if not (exists window 1) then
reopen
else
tell current window to create tab with default profile
end if
tell current session of current window
write text sshCommand
end tell
end tell
end openURL
-- For this script to behave as a URL handler
on open location theURL
openURL(theURL)
end open location
-- For testing
on run argv
if (count of argv) ≤ 0 then
openURL("ssh://srv.example.com")
return
end if
set theURL to item 1 of argv
openURL(theURL)
end run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment