How to create an AppleScript application to run a terminal command set

How do I start creating an AppleScript command, when I just run the script (or double-click it in Finder?), It will run the terminal command set? The set of commands completely removes MySQL, and it has become painful to write them all the time. Teams:

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 sudo nano /etc/hostconfig command that opens the file and I need to delete the line from the file, but it seems like it would be too hard to code, so I think I can do it manually. But it would be very useful to do this automatically with a single script.

Will it just be a bunch of these teams?

 do shell script (...) 

Thank you Christo

+6
shell applescript macos
source share
3 answers

Yes, you would use a do shell script .

However, for commands that you execute as superuser ( sudo ), you use with administrator privileges instead. So for sudo rm /usr/local/mysql you would do:

 do shell script "rm /usr/local/mysql" with administrator privileges 

If your list of commands is long, then it’s easiest to put all your commands in a single shell script file, and then execute this shell script using the do shell script :

 do shell script "/path/to/shell/script" with administrator privileges 
+15
source share

You really don't need to use AppleScript to do this - just put all shell commands in a text file and give it the suffix .command and make sure it is executable (e.g. chmod +x my_script.command ) - this will make it double -cickable in Finder .

+15
source share

I find that .scpt files work best, but this is only preference.

Open the "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 
0
source share

All Articles