温馨提示:本文翻译自stackoverflow.com,查看原文请点击:xcode - Install ffmpeg with applescript
applescript ffmpeg homebrew install xcode

xcode - 使用AppleScript安装ffmpeg

发布于 2020-04-10 10:21:20

我正在尝试创建一个安装ffmpeg的applescript。我有两个问题。

  • 我想一次安装Xcode,自制软件,ffmpeg,节点,授予权限和ffmpeg-progressbar-cli。并非一次都按顺序进行。ffmpeg依赖于xcode,因此它需要等待xcode安装完成。
  • 自制程序的命令要求"哪个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)'

单引号不起作用。

帮助和建议不胜感激!

查看更多

提问者
Andy Tailor
被浏览
77
Ted Wrigley 2020-02-03 01:16

好的,尝试以下脚本,但请注意以下警告:

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

注意事项:

  1. 如果以前安装了自制软件,则第一行可能会因权限错误而失败;在我的系统上,它想将某些东西从Xcode包复制到/usr/local/Homebrew/.git / ...,但是需要root特权。我通过完全删除文件夹/ usr / local / Homebrew解决了该问题,但是对于一般情况来说可能有点过分。您必须查看问题是否再次发生。
  2. chown在第2行和第4行中添加了一些命令。运行ruby脚本和时,这些命令会弹出错误brew install...您可能会在不同系统中基于特殊性遇到其他此类错误,但是添加更多此类命令来理顺/ usr / local中的权限应该没有什么坏处。
  3. 该脚本应在最少的用户交互下运行,但确实需要偶尔输入“确定”或密码。这些可以自动化,但是我不确定是否值得。