Passing a password to an Automator application

applescriptautomatorpasswordterminal

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

Best Answer

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: