使用苹果脚本安装ffmpeg

问题描述 投票:0回答:1

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

  • 我想一次安装Xcode,自制软件,ffmpeg,节点,授予权限和ffmpeg-progressbar-cli。并非一次都按顺序进行。 ffmpeg取决于xcode,因此需要等待xcode安装完成。
  • 用于自制程序的命令需要",该小脚本使我可以更改为',然后才能运行它,但在这种情况下它不起作用。

这里是我到目前为止的脚本。

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)'

单引号无效。

帮助和建议感激!

xcode ffmpeg install applescript homebrew
1个回答
0
投票

[确定,请尝试以下脚本,但是请注意以下警告:

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. [我在第2行和第4行中添加了几个chown命令。当我运行ruby脚本和brew install...时,这些错误弹出。您可能会基于不同系统中的特性而遇到其他此类错误,但是添加更多此类命令以理顺/ usr / local中的权限应该没有什么害处。
  3. 此脚本应在最少的用户交互下运行,但确实需要偶尔输入“确定”或密码。那些可能是自动化的,但是我不确定是否值得。
© www.soinside.com 2019 - 2024. All rights reserved.