如何创建的AppleScript应用程序运行一套终端命令 [英] how to create AppleScript app to run a set of terminal commands
问题描述
我将如何去创造一个AppleScript命令,当我刚刚运行脚本(或双击其在Finder中?),它会运行一组终端的命令?该命令集完全删除的MySQL,它已成为他们不断地写出来一种痛苦。这些命令是:
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
还有另一个命令须藤纳米的/ etc / hostconfig中
打开一个文件,我需要从文件中删除一条线,但好像它会是太难code,所以我想我可以自己动手完成的。不过,这将是一个巨大的帮助与一个脚本自动执行此操作。
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
推荐答案
是的,你可以使用做shell脚本
。
但是,对于执行作为超级用户的命令(须藤
),你会改用以管理员权限
。因此,对于 sudo的RM的/ usr /本地/ MySQL的
你会怎么做:
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
如果你的命令的列表很长,那么它可能是更容易把你的所有命令到一个单一的shell脚本文件,然后使用执行该shell脚本做shell脚本
:
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
这篇关于如何创建的AppleScript应用程序运行一套终端命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!