setup-your-mac / Setup-Your-Mac

Setup Your Mac aims to simplify initial device configuration by leveraging swiftDialog and Jamf Pro Policy Custom Events to allow end-users to self-complete Mac setup post-enrollment.
https://snelson.us/sym
MIT License
246 stars 54 forks source link

Fix osascript command for pre-Big Sur OSes #10

Closed meschwartz closed 1 year ago

meschwartz commented 1 year ago

The osascript command crashes when run on pre-Big Sur OSes. This adds Tell application "system events" to which works around the issue. This could cause issues on later OSes, so the change is restricted to just the pre-Big Sur block.

dan-snelson commented 1 year ago

Thanks for the PR, @meschwartz.

In Terminal, on macOS 13.2.1 (22D68), after first elevating to root, when executing the following …

osascript -e 'Tell application "system events" to display dialog "Please advise your Support Representative of the following error:\r\rExpected macOS Build '${requiredMinimumBuild}' (or newer), but found macOS '${osVersion}' ('${osBuild}').\r\r" with title "Setup Your Mac: Detected Outdated Operating System" buttons {"Open Software Update"} with icon caution'

… I observe:

36:295: execution error: Not authorized to send Apple events to System Events. (-1743) Screenshot 2023-03-12 at 1 52 35 PM


Also, in a single test of Mac OS X 10.15.7 (19H2026), the current command works as expected and your updated command generates the following message:

Screen Shot 2023-03-12 at 2 00 24 PM
meschwartz commented 1 year ago

Oh, interesting... I might need to do some more testing. It looks like we have a config profile in place that gives Terminal the PPPC permissions for systemevents, so I think that's why we're not seeing that dialog.

When you tested on Catalina, were you running the script via Jamf? (We only saw the crash when running via Jamf; not when running it directly from Terminal.)

dan-snelson commented 1 year ago

Ah … OK.

I'm only testing via Terminal; our pre-Big Sur Macs can only see two policies in Self Service:

dan-snelson commented 1 year ago

@meschwartz:

Unless you have any objections, I'd like to close this PR.

Please advise. Thanks.

meschwartz commented 1 year ago

Yes, you can go ahead and close it. We get so few machines with Catalina or older it's been such a low priority to do any testing with it. Thanks!

(Oh it looks like I could close it myself... but I'm so inexperienced with github I don't want to do the wrong thing!)

dan-snelson commented 1 year ago

Hehe … thanks, @meschwartz.

My preference is that you close your own request that you no longer need; please let me know if your mileage varies too greatly.

meschwartz commented 1 year ago

Closing, as this is a fairly niche use-case these days and is too inconvenient to test thoroughly. 🙂