Take the script that you created:
#!/bin/bash
echo "plugin L2TP.ppp">>/etc/ppp/options
echo "l2tpnoipsec">>/etc/ppp/options
Save it in your home directory, or a 'scripts' directory inside your home directory, as l2tp.sh. Allow it to be executed(write this command in Terminal):
chmod 700 ~/path/to/l2tp.sh
To execute the file using sudo (root privileges):
Method #1. In Terminal type:
$ sudo ~/path/to/l2tp.sh
Method #2. Create a file run_l2tp.command with this contents:
sudo ~/path/to/l2tp.sh
Allow it to be executed:
chmod u+x run_l2tp.command
When you double-click run_l2tp.command and enter the password the l2tp.sh file will be executed with root privileges.
Some notes:
- On UNIX like systems, ~ is short for "my home directory".
- Chmod 700 will make the file executable only by you. For more information: see this Wikipedia page.
- typing 'sudo' before a command will execute the program using root privileges. Be careful when doing this, bad things can happen if you're not sure what you're doing.
- Obviously you can omit the /path/to if you saved this script directly in your home directory.
The argument for osascript -e
can contain newlines:
osascript -e 'set x to "a"
say x'
You can also specify multiple -e
arguments:
osascript -e 'set x to "a"' -e 'say x'
Or if you use a heredoc, bash
interprets three characters (\
, $
, and `
) between <<END
and END
but no characters between <<'END'
and END
.
osascript <<'END'
set x to "a"
say x
END
Edit:
Since osascript can operate with a heredoc (ie take input from /dev/stdin) then one can just write the script as a whole file and prepend with the correct shebang line:
#!/usr/bin/env osascript
set x to "a"
say x
This also allows you to save your apple script as a actual program in ~/Applications/.app using the following procedure (changing for your script's name):
mkdir -p ~/Applications/<APP_NAME>.app/Contents/MacOS
touch ~/Applications/<APP_NAME>.app/Contents/MacOS/<APP_NAME>
open -A TextEdit ~/Applications/<APP_NAME>.app/Contents/MacOS/<APP_NAME>
Ensure that both the script file in .../MacOS/ and the matches
Best Answer
AppleScript
Wrap the shell script in a
do shell script
AppleScript command:If your script needs administrator rights, append
with administrator privileges
to the command:Using Script Editor.app in /Applications/Utilities, you can save the AppleScript as a
.applescript
text file that will launch in Script Editor on the host computer.The end user will need to select the menu item:
Alternatively, you can Export as an Application and code sign the resulting application. This assumes you have a code signing certificate available.
Automator
An Automator workflow can also include shell scripts and AppleScripts. Automator can also save as an application, with the Export… menu item also prompting to code sign the result for you.