1

I was hoping to configure a keystroke command using BetterTouchTool to open a terminal window and run an ssh session. I do this a lot to connect to a RaspberryPi on my network. The execute terminal command seems to execute the command without opening a window, and all the help I can turn up on Google is people asking how to run commands without opening a window. So what would be the best method for me to open a terminal window and execute ssh [email protected] in that window?

1 Answer 1

3

So, if I understand you correctly, you want to just click on a shortcut on your Desktop (or somewhere else) that will open Terminal.app and connect to a particular host via SSH.

The quickest way would be to create an AppleScript that opens Terminal and executes the command ssh <user>@<ipaddress>

First... Here's the code you are going to need:

Make sure you change the "user" and "host" to its appropriate values; your username and the host/ip address you wish to connect to.

tell application "Terminal"

    activate
    do script "ssh user@host" in front window

end tell

You have to put that into an AppleScript script then "bundle" it as an Application.

Open AppleScript Editor

You can find AppleScript Editor in the Utilities folder, but I find it much easier to hit Command + Spacebar to invoke Spotlight Search and just start typing "AppleScript" and hitting RETURN when it's found.

Once launched, create a new document and past the code I provided.

Save your Code as an "Application"

When you save your App, save it to your Desktop, give it a useful name and make sure you select "Application." You can ignore the "Options" at the bottom.

Save Diaglog

Launch Your App...

An icon will appear on your desk with the name that you gave it in the previous step. Click on it to Launch your newly created app.

enter image description here

Results

Your terminal window will launch issuing the command you programmed:

Results

2
  • Wow thank you! That is an excellent solution to the question and really well laid out. I appreciate the effort in making it as easy to follow as possible. One follow up question: when the script is opened and Terminal is not open, it opens two Terminal windows. When the script is activated if Terminal is already open, it only opens one window. Is there a line to add that will only open one terminal window when the application is launched?
    – Ubermaan
    Feb 22, 2016 at 20:04
  • add in front window to your " do script line. I updated the code above.
    – Allan
    Feb 22, 2016 at 20:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .