I have written an Automator application with the following shell script to open an FTP connection on my system:

sudo -s launchctl load -w /System/Library/LaunchDaemons/ftp.plist
osascript -e 'tell app "Finder" to display alert "SFTP Opened"'

This works exactly as expected except that the sudo command needs a password. When the same command is run on Terminal, it prompts me for a password but when run as an Automator app, doesn't prompt me for any input. Is there anyway to programmatically pass the password to this sudo within the Automator script? I know this is not a safe practice but I still want to do it as my system is reasonably secure and untouched by anyone other than me.

A "do shell script...with administrator privileges" method is giving the following error:

enter image description here

2 Answers 2


AppleScript should let you do this by using with administrator privileges:

osascript -e 'do shell script "sudo -s launchctl load -w /System/Library/LaunchDaemons/ftp.plist" with administrator privileges'

This doesn't pass the password, but prompts for it with a standard OS X prompt:

You can use this in your Automator workflow in one of the two following ways:

  • 1
    @Amit osascript is for bash :) If you want pure AppleScript in the AppleScript Automator action, remove the osascript like this: do shell script "sudo -s launchctl load -w /System/Library/LaunchDaemons/ftp.plist" with administrator privileges (Do one of the following from this picture)
    – grg
    May 10, 2014 at 18:44
  • 1
    Yes, this worked like charm! Thanks for your patience...silly me!
    – TheLearner
    May 10, 2014 at 18:47


You could instead use a tool like expect to script the interaction with sudo. expect is designed for this situation.

expect - programmed dialogue with interactive programs

The following shell script may be enough for your two commands:

#!/usr/bin/expect -f
spawn sudo -s launchctl load -w /System/Library/LaunchDaemons/ftp.plist
send "my-secret-password\n"

AppleScript and with administrator privileges

An alternative approach is to use AppleScript's do shell script command. The command offers a with administrator privileges option. Apple's Technical Note 2065 covers do shell script in detail.


Other common approaches to this problem involve using echo to pass the password to sudo with a pipe. This StackOverflow answer discusses this and other related approaches, How to provide password to a command that prompts for one in bash?


You must log in to answer this question.

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