Applescript: Run or Call a Shell Script

Applescript: Run or Call a Shell Script

To run or call a shell script using AppleScript, you can use the do shell script command. This command allows you to execute a shell script or any other command-line utility from within an AppleScript script.

Here is an example of how you can use the do shell script command to run a shell script called "myscript.sh":

do shell script "/path/to/myscript.sh"
Source‮w:‬ww.lautturi.com

If you want to run the script with root privileges, you can use the with administrator privileges option, like this:

do shell script "/path/to/myscript.sh" with administrator privileges

You can also pass arguments to the script by including them after the script name, separated by spaces. For example, to pass two arguments, "arg1" and "arg2", to the script "myscript.sh", you can use the following command:

do shell script "/path/to/myscript.sh arg1 arg2"

The do shell script command can also be used to execute any other command-line utility, such as grep, awk, sed, and more.

Keep in mind that the do shell script command is a potentially dangerous command, as it allows you to execute arbitrary commands as the user running the script. Therefore, you should use it with caution and only run scripts that you trust.

Created Time:2017-10-27 14:56:33  Author:lautturi