MacOS – Dock shortcut for an interactive bash script

applescriptbashdockmacosterminal

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?

Best Answer

Alright, I think I found the answer:

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