Need a help to correct script for MacOS update and restart popup message to user

Bhaskar
New Contributor

Hi Everyone,

 

I have written a script to download the Mac OS update in background but its suck on admin password and followed by the user interaction to save all file and click on restart button to install the update. 

but somehow script works till popup message display. below is the script

 

to update update os 

#!/bin/bash

 

loggedInUser=$(stat -f%Su /dev/console)

jamfHelper="/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper"

windowType="hud"

description="There is a critical security update available for your Company issued computer.

 

To perform the update, Click on 'UPDATE' below and the security update will begin to run.

 

This update can take upwards of 45 minutes.

 

 

NOTE: Before clicking on 'UPDATE', save all working documents and Connected the Charger.

 

 

If you require assistance, please contact ********** on Slack or by email at."

 

button1="MacOS update"

icon="/Library/Application Support/JAMF/logs/**********.png"

title="Critical: Apple Security Update Available"

alignDescription="left"

alignHeading="center"

defaultButton="2"

timeout="900"

 

# JAMF Helper window as it appears for targeted computers

userChoice=$("$jamfHelper" -windowType "$windowType" -lockHUD -title "$title" -timeout "$timeout" -defaultButton "$defaultButton" -icon "$icon" -description "$description" -alignDescription "$alignDescription" -alignHeading "$alignHeading" -button1 "$button1")

 

# If user selects "UPDATE"

if [ "$userChoice" == "0" ]; then

   echo "User clicked UPDATE;

# Trigger Mac OS update

   softwareupdate -i -a

   osascript -e 'tell app "loginwindow" to «event aevtrrst»'

 

   echo "Dialog dismissed. Beginning install"

   exit 0

fi

___

 

2. Restart system

 

#!/bin/bash

 

# Display a popup message to the user using AppleScript

osascript -e 'display dialog "A system update is ready to install. Please save your work, connect the charger, and click OK to restart." buttons {"OK"} default button "OK"'

 

# Check if the user clicked OK in the popup

if [ $? -eq 0 ]; then

 

                  # Restart the system

    sudo reboot

    # Restart the system with the charger connected

    jamf policy -trigger restart_with_charger

 

                  echo "Dialog dismissed. Beginning install"

                  exit 0

fi

 

Need your expertise to automate the process.

 

Thank you 

5 REPLIES 5

dsavageED
Contributor III

I'd suggest you look at - https://github.com/Macjutsu/super

Either you can try to update your code, using it as an example, or more easily implement it...

jtrant
Valued Contributor

Just go with SUPER, you're wasting your time trying to build something yourself.

markdmatthews
Contributor

JamfHelper is easy to use and built-in. IF struggling to figure out the options the "jamfHelper Constructor" at https://github.com/BIG-RAT/jhc

Ismere
Contributor

I would recommend using SUPER or NUDGE too. But for your script: Keep in mind that if you run a script trough Jamf it will run trough the binary, which generally means as root. That means you will need some RunAsUser Function to call your osascript, otherwise it will try to do it in the environment of root but not your user... alternatively just do everything with the JamfHelper Tool you already used for the first Part.

AJPinto
Honored Contributor II

Looking at your script directly, you are using softwareupdate -a -i for install all. If you actually want the updates to install you must also use the -R switch to reboot. A reboot command that comes from any source other than the softwareupdate binary, will not install the OS updates. Also, with the workflow of softwareupdate -aiR, it will force reboot the device breaking your script and the policy will never report back to Jamf. This is not a "problem" but rather the binary working as intended. 

 

I would suggest using a Jamf Helper policy to pester users to going into System Preferences > General > Software Update and installing OS updates themselves. For users who do not self-update issue a MDM command to install OS updates. This is basically all Nudge and Super can do, and I don't see a point in adding a 3rd party tool like Nudge and Super when all they can do is notify users just like Jamf Helper.

 

You can submit feedback to Apple pushing back on deprecating CLI, but there is no point in fighting apple on this and trying to force the dead horse to keep working; update your processes to modern standards.

 

https://learn.jamf.com/bundle/technical-paper-deploying-macos-upgrades-current/page/Introduction.htm...