MacOS – LaunchDaemon assistance

launchdmacos

I have the following .sh script that deletes Sierra, upon download, from the App store. This applies to any user on mac osx 10.10 or 10.11.

However can someone add the code so that the app (sierra.app) actually deletes as soon as it starts downloading as opposed to when its finished downloading which is what it presently does.

In addition the osascript display message does not display once it has deleted. How can I get that to work?

Here is the script.

#!/bin/bash

Version=$(sw_vers | grep ProductVersion | tail -c 7 | cut -d . -f 2)    

if [[ $Version -ge 12 ]]
then  
launchctl unload /Library/LaunchDaemons/net.infor.sierra.plist
rm -f /Library/LaunchDaemons/net.infor.sierra.plist
rm -f /usr/local/bin/sierra.sh
exit 0

else
rm -rf /Applications/Install\ macOS\ Sierra.app/
osascript -e 'tell app "System Events" to display dialog "macOS sierra is not allowed on computers at this time." with title "Technology Notice" buttons {"OK"} default button "OK" giving up after 30'
fi

Here is the plist.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com    /DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>net.infor.sierra.plist</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/sierra.sh</string>
</array>
<key>KeepAlive</key>
<dict>
<key>PathState</key>
<dict>
    <key>/Applications/Install macOS Sierra.app/</key>
    <true/>
</dict>
</dict>
<key>OnDemand</key>
<true/>
</dict>
</plist>

Best Answer

not really an answer, but maybe a hint as to where to go next...

To catch it earlier, you'd have to intercept it at the download folder. I'd guess the folder name will be different for everybody - mine is at
/private/var/folders/nc/c83zpk8x7kd9qrxrd3nnbfym0000gn/C/com.apple.appstore

You can find it from the App Store app > Debug > Show Download Folder... if you enable the debug menu with
defaults write com.apple.appstore ShowDebugMenu -bool true