Apple Script to start System Preferences not showing frontmost

nchan-jn
New Contributor II

I've been working on a script to launch System Preferences -> Software Update to guide users to run their own updates. Instead of simply launching Software Update.app, I wanted it to automatically select "More Info" so they can view all other updates instead.

When running this Apple Script locally, everything works perfectly. System Preferences launches, is set to the front of all windows, navigates to Software Update, checks for updates, and clicks on More Info if available.

However, when running this from a Jamf policy (check-in), it will launch System Preferences only in the background and doesn't bring it to the front. Any advice on what I might be overlooking?

Testing on macOS 10.14.2
PPPC for Jamf to control Apple Events is installed for:
com.apple.systemevents
com.apple.systemuiserver
com.apple.finder

Also added PPPC for Jamf to control
appleeventssd
com.apple.systempreferences
com.apple.preferences.softwareupdate
/usr/bin/osascript

Here's the script that I'm using:

tell application "System Preferences"
    activate
    tell application "System Events"
        tell process "System Preferences"
            set frontmost to true
        end tell
    end tell

    if exists window "Software Update" then
        tell window "Software Update" to if it is miniaturized then set miniaturized to false
    else
        set the current pane to pane id "com.apple.preferences.softwareupdate"
    end if
    tell application "System Events"
        tell process "System Preferences"
            repeat until (exists window "Software Update" of application process "System Preferences" of application "System Events")
                delay 1
            end repeat

            if (exists static text "Checking for updates…" of group 1 of window "Software Update" of application process "System Preferences" of application "System Events") then
                repeat
                    set itExists to exists busy indicator 1 of group 1 of window "Software Update" of application process "System Preferences" of application "System Events"
                    if itExists then
                        delay 1
                    else
                        exit repeat
                    end if
                end repeat
            end if

            if (exists button "More info…" of group 1 of window "Software Update" of application process "System Preferences" of application "System Events") then
                click button "More info…" of group 1 of window "Software Update" of application process "System Preferences" of application "System Events"
            end if
            set frontmost to true
        end tell
    end tell
end tell
2 REPLIES 2

sdagley
Esteemed Contributor II

@nchan-jn You need to run your AppleScript as the logged in user (a script running from a check-in policy is running as root). See this post for an example of how to do that: AppleScript prompt after DEP enrollment

nchan-jn
New Contributor II

@sdagley that was it...thank you!