使用 applescript 安装 ffmpeg
Install ffmpeg with applescript
我正在尝试创建一个安装 ffmpeg 的 applescript。我有两个问题。
- 我想一次安装一个 Xcode、homebrew、ffmpeg、node、grant permissions 和 ffmpeg-progressbar-cli。不是一次全部,而是按顺序。 ffmpeg 依赖于 xcode,因此需要等待 xcode 安装完成。
- 自制软件的命令需要
"
which 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
注意事项:
- 如果之前安装过homebrew,第一行可能会因为权限错误而失败;在我的系统上,它试图从 Xcode 包复制一些东西到 /usr/local/Homebrew/.git/...,但需要 root 权限。我通过完全删除文件夹 /usr/local/Homebrew 解决了这个问题,但对于一般情况来说这可能有点过激。您必须查看问题是否再次出现。
- 我在第 2 行和第 4 行添加了几个
chown
命令。当我 运行 ruby 脚本和 brew install...
时,这些命令作为错误弹出。您可能会 运行 根据不同系统的特性遇到其他此类错误,但添加更多此类命令以理清 /usr/local. 中的权限应该不会有什么坏处
- 此脚本应 运行 具有最少的用户交互,但偶尔需要 'ok' 或密码输入。那些 可以 自动化,但我不确定它是否值得。
我正在尝试创建一个安装 ffmpeg 的 applescript。我有两个问题。
- 我想一次安装一个 Xcode、homebrew、ffmpeg、node、grant permissions 和 ffmpeg-progressbar-cli。不是一次全部,而是按顺序。 ffmpeg 依赖于 xcode,因此需要等待 xcode 安装完成。
- 自制软件的命令需要
"
which 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
注意事项:
- 如果之前安装过homebrew,第一行可能会因为权限错误而失败;在我的系统上,它试图从 Xcode 包复制一些东西到 /usr/local/Homebrew/.git/...,但需要 root 权限。我通过完全删除文件夹 /usr/local/Homebrew 解决了这个问题,但对于一般情况来说这可能有点过激。您必须查看问题是否再次出现。
- 我在第 2 行和第 4 行添加了几个
chown
命令。当我 运行 ruby 脚本和brew install...
时,这些命令作为错误弹出。您可能会 运行 根据不同系统的特性遇到其他此类错误,但添加更多此类命令以理清 /usr/local. 中的权限应该不会有什么坏处
- 此脚本应 运行 具有最少的用户交互,但偶尔需要 'ok' 或密码输入。那些 可以 自动化,但我不确定它是否值得。