how to create AppleScript app to run a set of terminal commands
You don't actually need to use AppleScript for this - just put all the shell commands in a text file and give it a .command
suffix and make sure it's executable (e.g. chmod +x my_script.command
) - this will make it double-clickable in the Finder.
Yes, you would use do shell script
.
However, for the commands where you execute as super user (sudo
) you would instead use with administrator privileges
. So, for sudo rm /usr/local/mysql
you'd do:
do shell script "rm /usr/local/mysql" with administrator privileges
If your list of commands is long, then it might just be easier to put all your commands into a single shell script file, and then execute that shell script using do shell script
:
do shell script "/path/to/shell/script" with administrator privileges
I find that .scpt files work best but this is just a preference thing.
Open "Script Editor" and add the following command:
sudo rm -rf /usr/local/mysql; sudo rm -rf /usr/local/mysql*; sudo rm -rf /Library/StartupItems/MySQLCOM; sudo rm -rf /Library/PreferencePanes/My*; sudo rm -rf /Library/Receipts/mysql*; sudo rm -rf /Library/Receipts/MySQL*; sudo rm /etc/my.cnf; say job completed successfully" with administrator privileges