I had been fairly busy with both the JNUC and MacSysAdmin presentations, but work on Installomator has continued.
I also did an overview of what Installomator does in my MacSysAdmin Online presentation: “Practical Scripting”.
Many of these new features have been provided from others, either through GitHub issues, pull requests, or through comments in the #installomator channel on MacAdmins Slack. Thanks to all who contributed.
What’s new in v0.4:
you can now set script variables as an argument in the form VARIABLE=value. More detail on this in the README file, ‘Configuration from Arguments.’
change downloadFromGit to match file types better
implemented a workaround for changed behavior of xpath in Big Sur
added an option prompt_user_the_kill to BLOCKING_PROCESS_ACTION which will kill the process after the third unsuccessful attempt to quit
added several new labels for total of 116
Get the script and find the instructions on the GitHub repo.
If you have any feedback or questions, please join us in the #installomatorchannel on MacAdmins Slack.
We got the expected new iPhones 12 this week, all four models, and a new HomePod mini. I am actually looking forward to a smaller iPhone 12 mini to replace my iPhone X.
In other (some would say good) news, macOS 11 Big Sur was not released this week, but we got beta 10 instead. There is an expectation for another Apple event introducing the first Apple Silicon based Macs in the upcoming weeks and that would be an obvious time to release Big Sur to everyone.
William Smith: “Tomorrow (October 13, 2020): Support for Microsoft Office 2016 for Mac — any version 16.16.x and lower— ends. No more software updates to fix: • Bugs • Compatibility problems • Security vulnerabilities – No macOS Big Sur support”
If you want to support me and this website even further, then consider buying one (or all) of my books. It’s like a subscription fee, but you also get a useful book or two extra!
For now this has been a quiet week. Since Apple announced another event next week, possibly a calm before the storm. After Apple announced iOS 14 with 24 hours notice, MacAdmins are understandably a bit nervous. Also, no new betas this week (so far).
On the other hand, after JNUC last week, we had MacSysAdmin this week. I have not been able to watch all presentations yet, but those that I have seen have been worth it and I am looking forward to the rest.
In other news, this newsletter just passed the 1000 email subscribers number! Thank you all for reading, and on to the next thousand!
Eliz: “Please don’t say just “Hello” in a chat #NoHello” (Read thread and links for background. I find myself doing that a lot, too, and have resvoled to do better.)
If you want to support me and this website even further, then consider buying one (or all) of my books. It’s like a subscription fee, but you also get a useful book or two extra!
Virtual JNUC 2020 was on and had some great sessions. If you have registered you can (re-)view the sessions in the portal for three more weeks and then they will be moved to the Jamf YouTube channel. Thanks to everyone who presented a session, I have not been to watch the all (not even close) but will try to over the next few weeks. Thanks also, to everyone who watched my session live and for all the kind feedback I have already gotten. You can find the slides, notes and links for my session here.
Steve Hayman: “Your grep one-liner du jour. Count how many words of each length appear in the /usr/share/dict/words dictionary. for n in $(jot 25); do printf "%2d letter words: " $n; grep -E "^.{$n}\$" /usr/share/dict/words | wc -l; done” (Thread)
If you want to support me and this website even further, then consider buying one (or all) of my books. It’s like a subscription fee, but you also get a useful book or two extra!
The session should be available “on demand” in the JNUC2020 portal within an hour or so. I believe all sessions will be available on YouTube eventually and will update the links then!
I hope you enjoyed the session, and if you have any more questions or comments, then I am @scriptingosx on the MacAdmins Slack and Twitter.
AppleScript on macOS is a useful tool for pro users and administrators alike. Even though it probably is not (and shouldn’t be) the first tool of choice for many tasks, there are some tasks that AppleScript makes very simple. Because of this it should be a part of your ‘MacAdmin Toolbelt.’
AppleScript’s strength lies in inter-application communication. With AppleEvents (or AppleScript commands) you can often retrieve valuable information from other applications that would be difficult or even impossible, to get any other way. With AppleScript, you may even be able to create and change data in the target applications.
If you are in any way security and privacy minded this should raise your hairs. Up to macOS 10.13 High Sierra, any non-sandboxed app could use AppleScript and AppleEvents to gather all kinds of personal and private data from various script-enabled apps and services. It could even use script-enabled apps like Mail to create and send email in your name.
Since macOS Mojave, the Security and Privacy controls restricts sending and receiving AppleEvents. A given process can only send events to a different process with user approval. Users can manage the inter-application approvals in the Privacy tab of the Security & Privacy preference pane.
MacAdmins have the option of pre-approving inter-application events with a PPPC (Privacy Preferences Policy Control) configuration profile that is pushed from a DEP-enrolled or user-approved MDM.
Privacy approval
You can trigger the security approval from Terminal when you send an event from the shell to another process with osascript:
> osascript -e 'tell application "Finder" to get POSIX path of ((target of Finder window 1) as alias)'
When you run this command from Terminal, you will likely get this prompt:
You will not get this prompt when you have approved or rejected the Terminal app to send events to this particular target application before. You can check the permissions granted by the user in the Automation section of Privacy tab in the Security & Privacy pane of System Preferences.
For any given source/target application combination, the prompt will only be shown once. When the user approves the privilege (“OK” button), future events will just be allowed.
When the user rejects the connection (“Don’t Allow” button), this event and future events will be rejected without further prompts. The osascript will fail and the AppleScript will return an error –1743.
> osascript -e 'tell application "Finder" to get POSIX path of ((target of Finder window 1) as alias)'
79:84: execution error: Not authorized to send Apple events to Finder. (-1743)
If you want to get the approval dialogs again, you can reset the state of the source application (Terminal) with the tccutil command:
> tccutil reset AppleEvents com.apple.Terminal
This will remove the Terminal application and all target applications for it from the Automation (AppleEvents) area in the Privacy pane and show dialogs for every new request going forward. This can be very useful during testing.
Dealing with rejection
You should write your code in a ways that it fails gracefully when access is not granted. in this case osascript will return an error:
if ! osascript -e ' tell app "Finder" to return POSIX path of ((target of Finder window 1) as alias)'
then
echo "osascript encountered an error"
exit 1
fi
However, osascript will return errors for all kind of failures with no easy way to distinguish between them. As an example, the above will also fail when there are no Finder windows open.
If you want to distinguish AppleScript errors, you need to do so in the the AppleScript code:
if ! osascript -s o <<EndOfScript
tell application "Finder"
try
set c to (count of Finder windows)
on error message number -1743
error "Privacy settings prevent access to Finder"
end try
if c is 0 then
return POSIX path of (desktop as alias)
else
return POSIX path of ((target of Finder window 1) as alias)
end if
end tell
EndOfScript
then
echo "osascript failed"
fi
Note: the -s o option of osascript makes it print AppleScript errors to standard out rather than standard error, which can be useful to find the errors in logs of management systems.
Note 2: when you are running osascript from management and installation scripts (which run as the root user) you need to run them as the current user to avoid problems.
Avoiding Privacy prompts
So, we know of one way to deal with the privacy prompts. Ideally, you would want to avoid them entirely. While this is not always possible, there are a few strategies that can work.
Don’t send to other Processes
In past versions of Mac OS X (I use this name intentionally, it’s that long ago.), scripts that showed dialogs might not display on the highest window layer. In other words, the dialog was lost behind the currently active windows. To avoid “lost” dialogs, it became best practice to send the display dialog command (and similar) to a process that had just received an activate command as well:
tell application "Finder"
activate
display dialog "Hello, World!"
end tell
As an alternative for Finder, the System Events process is often used as well. Jamf MacAdmins often used “Self Service.” This had the added bonus, that the dialog looks as if it comes from the Finder or Self Service, including the bouncing dock icon.
Over time, even though the underlying problem with hidden dialog has been fixed, this practice has persisted. You often even see AppleScript code use this with commands other than user interaction, where it wouldn’t have made sense in the first place. With the privacy restrictions in macOS Mojave, this practice has become actively trouble some, as you are sending the display dialog (or other) command to a separate process. The process running this script will require approval to send events to “System Events.”
In current versions of macOS, you can just use display dialog and may other commands without an enclosing tell block. Since your AppleScript code isn’t sending events to another process, no privacy approval is provided. This code has the same effect as above, but does not trigger an approval request.
To determine whether an AppleScript command requires a tell block, you have to check where it is coming from. Many AppleScript commands that are useful to MacAdmins are contained in the ‘StandardAdditions’ scripting extension. Scripting extensions, as the name implies, extend the functionality of AppleScript without requiring their own process.
The useful commands in the Standard Additions extension include:
user interaction: choose file/folder/from list, display dialog/alert/notification
file commands: mount volume
clipboard commands: get the clipboard, set the clipboard to
sound control: set volume, get volume settings
system info
When your script uses only these commands, make sure they are not contained in tell blocks. This will avoid unnecessary prompts for access approval.
Exempt AppleScript commands
Some AppleScript commands are treated differently and will not trigger privacy approval:
activate: launch application and/or bring to front
open: open a file
open location: open a URL
quit: quit the application
For example, this will work without requiring approval:
osascript <<EndOfScript
tell application "Firefox"
open location "https://scriptingosx.com"
end
EndOfScript
Use non-AppleScript alternatives
Sometimes, similar effects to an AppleScript can be achieved through other means. This can be difficult to figure out and implement.
As an example, I used this AppleScript command frequently for setup before Mojave:
tell application "Finder" to set desktop picture to POSIX file "/Library/Desktop Pictures/BoringBlueDesktop.png"
While Mojave was in the beta and it wasn’t really clear if or how the PPPC exemptions could be managed, I looked for a different means. I discovered Cocoa functions to read and change the desktop picture without triggering PPPC, and built a small command line tool out of that: desktoppr.
The downside of this approach is that you know have to install and/or manage a command line tool on the clients where you want to use it. There are different strategies for this, but it is extra effort compared to “just” running an AppleScript.
Build PPPC profiles to pre-approve AppleEvents
Even after you have considered the above options to avoid sending AppleEvents to another process, there will still be several situations where it is necessary. For situations where a MacAdmin needs to run a script on several dozens, hundreds, or even thousands of Macs, user-approval is simply not a feasible option.
MacAdmins can pre-approve AppleEvents (and most other privacy areas) between certain processes with a Privacy Preferences Policy Control (PPPC) configuration profile. PPPC profiles can only be managed when pushed from a user-approved or automatically enrolled MDM.
You can build such a profile manually, but it is much easier to use a tool to build these:
Your MDM solution might have a specific tool or web interface for this, consult the documentation or ask you vendor.
There is one big requirement here, though: only applications and tools that are signed with a valid Apple Developer ID can be pre-approved this way, as the signature is used to identify and verify the binary.
Determining the process that needs approval
While you can sign shell scripts and other scripts this is often not necessary. As we have seen earlier, when we ran our script from Terminal, it wasn’t the script that requested approval but the Terminal application. When your scripts run from a management system or another tool, it may not be easy to determine which process exactly needs approval.
The most practical approach to determine this, is to log the output of the ’Transparency, Consent, and Control” system (tcc) and look which process is sending the requests.
First, either use a clean test system, or reset the approvals for the processes that you suspect may be involved with tccutil.
Then open a separate Terminal window and run this command which will show a stream of log entries from the tcc process:
Then run the script in question, the way you are planning to run it during deployment. If you are planning to run the script from a management system, then do that right now. You will get a lot output in the stream above.
Even when you don’t have a good idea what the parent process is going to be, you can filter the output for osascript since this is usually the intermediary tool used.
In my example I found several entries similar to this:
The important information here is the responsible path which give me the binary and the enclosing application that tcc considers ‘responsible.’ This is the application you need to approve.
When you are running your scripts from a management system, your MDM vendor/provider should already have documentation for this, to save you all this hassle.
With all this information, you can build the PPPC profile with one of the above tools, upload it to your MDM and push it to the clients before the deployment scripts run.
Conclusion
While the added privacy around AppleEvents is welcome, it does add several hurdles to automated administration workflows.
There are some strategies you can use to avoid AppleScripts triggering the privacy controls. When these are not sufficient, you have to build a PPPC profile to pre-approve the parent process.
If you thought that the week after the iOS 14 release would be a quiet week, you would have been wrong.
We got updates for the Keynote, Pages, Numbers, and iMovie, the first bug fix updates for iOS 14 and siblings, macOS Big Sur beta8 and, quite surprisingly: 10.15.7.
It makes you wonder why this update got the 10.15.7 and not “yet another Supplemental Update,” but this is a very welcome change. Many thanks to Mr Macintosh and Howard Oakley for covering the updates so well.
Steve Hayman: “Well that’s easy.” (Read the thread for some Hayman scripting wisdom.)
Carl Ashley: “The elephant in the room: Keeping up to date with OS/app releases isn’t always important. Sometimes, being able to get s**t done with something that works is more important.” (Thread)
William Smith: “Next month, support for Microsoft Office for Mac changes in two ways: 1. With the release of Big Sur, only these N–2 versions are supported: macOS Big Sur macOS Catalina macOS Mojave 2. Office 2016 for Mac is end-of-lifed. Updates end. Support ends. KB docs begin retiring.”
mikey: “TIL there’s an osascript cache at ~/Library/Caches/com.apple.osascript/Cache.db”
Carl Ashley: “Why is it, that in 2020, after many years of having MDM available, are we still not yet able to specify values to pass on to Setup Assistant, or even values for the settings that Setup Assistant sets that we can use in normal profile payloads?” (Thread)
If you want to support me and this website even further, then consider buying one (or all) of my books. It’s like a subscription fee, but you also get a useful book or two extra!
Update season has started. After the event on Tuesday, where Apple announced new Watches and iPads, iOS 14 shipped on Wednesday, giving developers and admins less than 24 hours advance warning and probably the shortest lived GM ever.
We also got macOS Big Sur beta 7 and new betas for iOS 14.2 and siblings.
The future releases of hardware and software this year should remain interesting. I expect at least two more events like this, one focussing on the new iPhones and the other for a new Apple Silicon Mac (or more). I would also guess that we will get the “missing” iOS 14.1 with the new iPhones, and 14.2 shortly after.
The reason this newsletter is a bit later than usual, is that I was finishing recording and editing my presentation for MacSysAdmin Online to submit it today, just in time for the deadline. This is the second presentation for a major MacAdmin conference that I recorded and finished this month. It feels strange that neither of these presentations will be streamed until October, but I am very much looking forward to when you get to see them and all the other presentations from both conferences.
Virtual JNUC 2020 is happening September 29 through October 1. My session will be on “Scripting Jamf Pro: Best Practices” on Oct 1 at 11am CDT (18:00 Central European). There will be a live Q&A during and after the session. You can still register for free.
Mr. Macintosh: “I’m hearing that the Jamf Pro 10.24 beta Big Sur fixes are in 10.24.1. Official support will be listed in the patch notes of 10.25 (not sure on 10.25 version numbering). 10.24.1 = Big Sur compatible. 10.25 = Big Sur official supported version.”
Andreas Schenk: “Using an iPad as an additional screen for macOS with sidecar seems to still deliver notifications from iPadOS, even if macOS is in DND mode. So if you happen to run a presentation using sidecar, first set the iPad to do not disturb, then use sidecar.”
If you want to support me and this website even further, then consider buying one (or all) of my books. It’s like a subscription fee, but you also get a useful book or two extra!
Apple has announced an event next week September 15, 10am PDT. They have seeded many people in the press and on social media with the information that there will be no iPhones at this event. Expectations are for a new watch and iPad Air.
A new watch will likely require watchOS 7, which will require iOS 14, so the Apple systems upgrade season will start soon after this event. If previous years can be used to extrapolate (not at all certain this year) the iOS system upgrades could be available Friday, September 18 or September 25.
I am not concerned at all about no iPhones or Macs at this event. These will probably be remote, pre-recorded events like they did at WWDC. Apple can easily do multiple of these events until well into October, giving every product full attention.
Arek Dreyer: “On your Mac, you can Option-Click the Notification Center icon to toggle Do Not Disturb.”
Arek Dreyer: “A bunch of Apple Reference and User Guide pages now have a ”Search the user guide” field, nice!”
Nathaniel Strauss: “Still true in Big Sur beta 6. Apple privacy/security team won a stupid fight… and everyone else lost. PPPC is needlessly confusing for most people. Schools won’t use Big Sur for at least 4–6 months after release. What a mess.” (More info from Michael Tsai)
Corey Quinn: “Myth: Companies are accelerating their cloud migrations due to COVID19. Fact: Companies are suddenly making better decisions since their executives aren’t being exposed to enterprise software ads in airports.”
If you want to support me and this website even further, then consider buying one (or all) of my books. It’s like a subscription fee, but you also get a useful book or two extra!