Automation and Scripting

The URL and AppleScript integration

The SSH Config Editor supports two automatization technics. You can use an URL to instruct app to open connection to specific server and AppleScript or JavaScript for automate some tasks as connect to, create, edit or delete host configurations.

Scripting preferences view

Enable Script Interaction

Before you create some script or call application URL you must allow Script interaction in app Preferences.

URL Handling

The application processes the incoming URL with the schema sshce:// and host's alias to open a connection to that host. The connection opens in the same way as it were started from the application itself.

For example URL sshce://test-server will open connection to the host with alias test-server

You can open URL from any terminal:

$ open sshce://test-server

or from AppleScript:

open location "sshce://test-server"

AppleScript

AppleScript is a scripting language created by Apple. It allows users to directly control scriptable applications, as well as parts of macOS itself. You can create scripts—sets of written instructions—to automate repetitive tasks, combine features from multiple scriptable applications, and create complex workflows. For control scriptable applications you can also use JavaScript for Automation.

The SSH Config Editor also supports some automation tasks, such as create and delete host configurations, create new config options, connect to host by alias and more.

I think an example is better than words, so here it is:

tell application "SSH Config Editor"
    
    # create a new host
    set newHost to make new host {alias:"test-server", user:"hejki", hostname:"10.0.0.7", port:32}
    
    # create a new host config option
    make new option {key:"IdentityFile", value:"id_rsa.pub"} on newHost
    
    # get all host aliases
    set aliasList to get alias of every host
    
    # get all entries with host name
    set hostsToChange to every host whose hostname is "10.0.0.7"
    
    # change port for selected hosts
    repeat with h in hostsToChange
        set the port of h to 200
    end repeat
    
    # select specific host and connect to it
    set myHost to first host whose alias = "test-server"
    connect to myHost
    
    # another way to connect (with alias)
    connect with alias "test-server"
    
    # and another way to connect (with host id)
    connect with id (get id of myHost)
    
    # get host config property (id, alias, connection_alias, user, hostname, port, canBeUsedForConnection)
    get alias of myHost
    get hostname of myHost
    
    # get host other config options (option have key and value property)
    get options of myHost
    
    # delete host
    delete myHost
    
    # save config file
    save configuration
end tell

You can find more about these automation techniques on the Internet

Ready to Use Automations

Here is some ready to use automations build for SSH Config Editor. If you have any suggestion for other automation or have one, please send me info.

Alfred 4 Workflow

  • Suggest hosts for connection and open connections to them directly from Alfred
  • Made for Alfred 4, requires Alfred Workflows
  • Download workflow file and open it inside Alfred
  • Usage is simply. Enter ssh alias and Alfred will show suggested hosts. Select one press ↵ and do your ssh stuff ;)
Alfred suggestion

Raycast

  • Open ssh connections from Raycast
  • Download script extract it somewhere and add that directory in Extensions preferences in Raycast - see documentation for more info
  • You must enter ssh and complete host alias to open connection. This script cannot suggest host entries.
Raycast integration