0

I'm new to OSX and all I want it an application shortcut in Dock that opens the terminal and types the first command and waits for me to provide the password. Here is the script I want to run:

#!/usr/bin/env bash
sudo openconnect --user={username} {host}

And here is the AppleScript I created using Automator:

do shell script "/usr/local/bin/openconnect --user={user} {host}" with administrator privileges

But when I run it, it exits when it asks for username and password. What am I missing here?

1

Alright, I think I found the answer:

tell application "Terminal"
    do script "sudo /usr/local/bin/openconnect --user={user} {host}"
    activate
end tell
1

Instead of having an Automator/AppleScript applet to run this command, you can use Terminal to automatically run that command upon launch.

  1. In Terminal, go to Terminal > Preferences.
  2. In the General pane, under "Shells open with:", select "Command (complete path):"
  3. Enter your command in the text field.

Now, when Terminal opens, that command will execute automatically.

If you wish to be able to launch Terminal and open a window that doesn't run the command automatically, disregard the above steps, and follow the following steps:

  1. In Terminal, go to Terminal > Preferences.
  2. In the Profiles pane, on the list on the left, find the default profile, and select it.
  3. At the bottom left, click the sprocket ⚙ icon, and click "Duplicate Profile". Label the duplicate with something that indicates that the command won't run on this profile.
  4. Back on the default profile, under the Startup label, tick the "Run command:" checkbox, and enter your command in the text box. Ensure that "Run inside shell" is ticked also.
  5. Close Terminal, and relaunch. When a window opens, it should run your command by default. To open a Terminal window without your command running, go to Shell > New Window > Name of the duplicate profile.
  • Thanks, but I wanted to have an application icon in my Dock to avoid opening the terminal. Is possible to have a terminal launcher in Dock which opens a specific profile by default? – norbertpy Jul 21 '15 at 22:47
  • There doesn't seem to be anything in the Terminal dictionary for profile-related objects. Why not put the Terminal in the dock, after following the second set of steps in my answer? The Terminal will open no-matter-what, so why not dock it? – Thomas Jones Jul 21 '15 at 23:01
  • With my approach, I have the terminal in dock but I also have another icon in dock just for my vpn connection. What if I want to open a terminal without running the VPN? How many clicks do I need to switch between the profiles? Also, the VPN is sticky. It's there as long as I'm connected so I can't use the same terminal for other stuff. I'll need another window. Unless I make two windows which will be opened by default when terminal is launched. – norbertpy Jul 21 '15 at 23:29

You must log in to answer this question.

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