我正在尝试创建一个安装ffmpeg的applescript。我有两个问题。
"
哪个applescript使我更改为,'
然后才能运行它,但是在这种情况下它不起作用。这是我到目前为止的脚本。
tell application "Terminal"
do script "xcode-select --install && ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" && brew install ffmpeg && brew install node && sudo chown -R $(whoami) /usr/local/bin /usr/local/etc && npm install --global ffmpeg-progressbar-cli"
activate
end tell
我试过了,它似乎没有按预期工作。
tell application "Terminal"
do script "sudo chown -R $(whoami) /usr/local/bin /usr/local/etc && xcode-select --install"
display dialog "Select OK once Xcode has installed" buttons {"OK"} default button 1
do script "ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)""
display dialog "Select OK once Homebrew has installed" buttons {"OK"} default button 1
do script "brew install ffmpeg"
display dialog "Select OK once ffmpeg has installed" buttons {"OK"} default button 1
do script "brew install node"
display dialog "Select OK once node has installed" buttons {"OK"} default button 1
do script "npm install --global ffmpeg-progressbar-cli"
display dialog "Select OK once ffmpeg-bar has installed" buttons {"OK"} default button 1
activate
end tell
对于第二个问题,它需要
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
但是applescript让我将其更改为
ruby -e '$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)'
单引号不起作用。
帮助和建议不胜感激!
好的,尝试以下脚本,但请注意以下警告:
shellScriptHandler("xcode-select --install", false)
shellScriptHandler("sudo chown -R $(whoami) /usr/local/Cellar", true)
shellScriptHandler("ruby -e \"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)\" <<< " & return, false)
shellScriptHandler("sudo chown -R $(whoami) /usr/local/var/homebrew /usr/local/share/zsh /usr/local/share/zsh/site-functions", true)
shellScriptHandler("/usr/local/Homebrew/bin/brew install ffmpeg", false)
shellScriptHandler("/usr/local/Homebrew/bin/brew install node", false)
shellScriptHandler("sudo chown -R $(whoami) /usr/local/bin /usr/local/etc", true)
shellScriptHandler("/usr/local/bin/npm install --global ffmpeg-progressbar-cli", false)
on shellScriptHandler(command, usesAdmin)
log command
(*
The try block catches any errors and reports them; the user can choose
to continue execution if it's a warning, or cancel execution outright.
The 'eval' statement forces do shell script to read the standard
interactive $PATH variable, so that it sees /user/local/, otherwise it
can't find the files it needs.
*)
try
do shell script "eval `/usr/libexec/path_helper -s`; " & command administrator privileges usesAdmin
on error errstr
display dialog errstr buttons {"Continue", "Cancel"} default button "Continue"
end try
end shellScriptHandler
注意事项:
chown
在第2行和第4行中添加了一些命令。运行ruby脚本和时,这些命令会弹出错误brew install...
。您可能会在不同系统中基于特殊性遇到其他此类错误,但是添加更多此类命令来理顺/ usr / local中的权限应该没有什么坏处。
我已经对其进行了测试,并且效果很好。再次感谢Ted!
对于以后遇到此问题的任何人,我的确发现了在此命令中使用“的变通方法。
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
此处找到:stackoverflow.com/questions/14737414/…。这使applescript命令起作用:do script "ruby -e \"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)\"
但是Ted的解决方案更好。