Bash script on macOS: prevent next command from running until GUI app exits
1
vote
1
answer
90
views
I'm trying to write a simple shell script for OS X 10.10, to install a list of applications for new Macs we're getting in. I just want to fire off each installer one at a time to install each application. I'm using a bash script, which works fine, except for some installs I'm just calling the GUI installer and installing that way clicking Next, Next Next... because that particular app didn't install properly through the terminal. (which is fine)
My problem is, that when the script opens the GUI installer for App A, it will then keep running down the script opening the commands next in line. What I want is for the script to wait to run the next command for as long as that installer window is open for. Windows DOS works this way, where you can make a batch file and it won't execute the next line until the first install is completed. So I'm looking for similar behavior.
I've tried a couple of things from reading but none of them have worked. As you can see, the places where I've put the "wait" command is where I want to to wait for the GUI installer to finish.
#!/bin/bash
# Install Script for OS X BYOD Laptops
# Installing Office 2016
open /Volumes/USB30FD/packages/Microsoft_Office_2016_Volume_Installer.pkg
wait
# sudo installer -verboseR -pkg /Volumes/USB30FD/packages/Microsoft_Office_2016_Volume_Installer.pkg -target /
sudo installer -verboseR -pkg /Volumes/USB30FD/packages/Microsoft_AutoUpdate_3.2.0_Updater.pkg -target /
sudo installer -verboseR -pkg /Volumes/USB30FD/packages/Microsoft_Excel_15.15.0_Updater.pkg -target /
sudo installer -verboseR -pkg /Volumes/USB30FD/packages/Microsoft_OneNote_15.15.1_Updater.pkg -target /
sudo installer -verboseR -pkg /Volumes/USB30FD/packages/Microsoft_Outlook_15.15.0_Updater.pkg -target /
sudo installer -verboseR -pkg /Volumes/USB30FD/packages/Microsoft_PowerPoint_15.15.0_Updater.pkg -target /
sudo installer -verboseR -pkg /Volumes/USB30FD/packages/Microsoft_Word_15.15.0_Updater.pkg -target /
defaults write com.apple.dock persistent-apps -array-add 'tile-datafile-data_CFURLString/Applications/Microsoft Word.app_CFURLStringType0'
defaults write com.apple.dock persistent-apps -array-add 'tile-datafile-data_CFURLString/Applications/Microsoft Excel.app_CFURLStringType0'
defaults write com.apple.dock persistent-apps -array-add 'tile-datafile-data_CFURLString/Applications/Microsoft PowerPoint.app_CFURLStringType0'
defaults write com.apple.dock persistent-apps -array-add 'tile-datafile-data_CFURLString/Applications/Microsoft Outlook.app_CFURLStringType0'
killall -HUP Dock
# Install ShareFile\
sudo cp -r /Volumes/USB30FD/apps/ShareFile.app /Applications/
wait
open -a /Applications/ShareFile.app
wait
# Install Absolute Computrace
# sudo installer -verboseR -pkg /Volumes/USB30FD/packages/RPClient.pkg -target /
open /Volumes/USB30FD/packages/RPClient.pkg
wait
open /Volumes/USB30FD/Ctclient103319-304806/ctmweb.app
# Install Symantec Endpoint Protection
# Run the GUI installer instead: open /Volumes/USB30FD/apps/Additional\ Resources/SEP.mpkg
sudo installer -verboseR -pkg /Volumes/USB30FD/apps/Additional\ Resources/SEP.mpkg -target /
wait
/Library/Application\ Support/Symantec/LiveUpdate/LUTool
# Install Trend Disk Encryption
open /Volumes/USB30FD/packages/Trend\ Micro\ Full\ Disk\ Encryption.pkg
I'm pretty novice when it comes to shell scripts, so the simpler the better. Thanks!
Asked by Fish
(11 rep)
Nov 5, 2015, 10:44 PM
Last activity: Apr 6, 2025, 09:39 AM
Last activity: Apr 6, 2025, 09:39 AM