【发布时间】:2014-07-06 00:29:37
【问题描述】:
请先参考这个问题,
unable to read opensslv.h:No such file or directory
基于此,我需要使用 AppleScript 运行以下三行终端命令,
/tmp/ssl/openssl-1.0.1h/Configure darwin64-x86_64-cc ––prefix=/usr no-threads shared
make -f /tmp/ssl/openssl-1.0.1h/Makefile
sudo make -f /tmp/ssl/openssl-1.0.1h/Makefile install
我尝试了两种方法,我创建了具有 .command 和 .sh 扩展名的文本文件并添加了上述内容三行。然后尝试从 AppleScript 运行它,
do shell script "/Users/Username/Desktop/RunScript.sh"
但是得到了这个错误,
error "/Users/Username/Desktop/RunScript.sh: line 1: /tmp/ssl/openssl-1.0.1h/Configure: No such file or directory
/Users/Muhriz/Desktop/InstallOpenSSL.sh: line 2: make: command not found sudo: no tty present and no askpass program specified" number 1
这可以工作,
tell application "Terminal" to activate
tell application "Terminal"
do script ("/tmp/ssl/openssl-1.0.1h/Configure darwin64-x86_64-cc ––prefix=/usr no-threads shared") in window 1
do script ("make -f /tmp/ssl/openssl-1.0.1h/Makefile") in window 1
do script ("sudo make -f /tmp/ssl/openssl-1.0.1h/Makefile install") in window 1
end tell
但它在第三行的终端中要求输入密码并等待用户响应。 AppleScript 中显示的密码对话框(使用with administrator privileges 时)正常。但是在运行命令时,它不能通过终端询问密码。 AppleScript 执行时只需要询问一次,并在终端中运行所有sudo 相关命令,而不需要输入密码。
从 AppleScript 运行需要使用哪些代码?
【问题讨论】:
标签: macos bash shell terminal applescript