I'm trying to create an applescript that installs ffmpeg. I have two issues.
"
which applescript makes me change to a '
before I can run it but in this case it doesn't work. Here is the script I have so far.
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
I tried this and it doesn't seem to work as intended.
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
For the second issue it needs to be
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
but applescript makes me change it to
ruby -e '$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)'
with single quote which doesn't work.
Help and suggestions apreciated!
Ok, try the following script, but see caveats below:
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
Caveats:
chown
commands in lines 2 and 4. These popped up as errors when I ran the ruby script and brew install...
. You may run across other such errors based on idiosyncrasies in different systems, but it shouldn't hurt to add more such commands to straighten out the permissions in /usr/local.
I've tested it and it is working great. Thanks again Ted!
For anyone who comes by this in the future I did discover this workaround for using " in this command
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Found here: stackoverflow.com/questions/14737414/… . which makes the applescript command work:do script "ruby -e \"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)\"
But Ted's solution is better.