如何创建 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
还有另一个命令 sudo nano/etc/hostconfig
可以打开一个文件,我需要从文件中删除一行,但这似乎很难编码,所以我想我可以手动完成.但是,使用单个脚本自动执行此操作将有很大帮助.
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 (...)
谢谢,赫里斯托
推荐答案
是的,你会使用做shell脚本
.
但是,对于以超级用户身份执行的命令 (sudo
),您将改为使用具有管理员权限的 .所以,对于
sudo rm/usr/local/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 脚本文件中,然后使用 do shell script
执行该 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屋!