Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to create AppleScript app to run a set of terminal commands

How would I go about creating an AppleScript command that when I just run the script (or double click it in Finder?), it would run a set of terminal commands? The set of commands completely remove MySQL, and it has become a pain to constantly write them out. The commands are:

sudo rm /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

There is also another command sudo nano /etc/hostconfig that opens a file and I need to delete a line from the file, but that seems like it'd be too hard to code, so I guess I can do that by hand. But it would be a huge help to do this automatically with a single script.

Would it just be a bunch of these commands?

do shell script (...)

Thanks, Hristo

like image 844
Hristo Avatar asked Jul 01 '10 01:07

Hristo


People also ask

What is replacing AppleScript?

Using Swift.

Does Apple still use AppleScript?

AppleScript is a scripting language created by Apple Inc. that facilitates automated control over scriptable Mac applications. First introduced in System 7, it is currently included in all versions of macOS as part of a package of system automation tools.


2 Answers

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
like image 128
indragie Avatar answered Oct 04 '22 22:10

indragie


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.

like image 24
Paul R Avatar answered Oct 04 '22 20:10

Paul R