Weekly News Summary for Admins — 2018-08-31

Things are heating up in the iOS 12 and macOS Mojave beta cycle. Apple has announced an event on September 12, which will presumably present the new iPhones and Apple Watch. There may or may not be new Macs at that event, though in the past Apple would often have a second event later in the fall.

From the September 12 date and the schedule of past years, you can extrapolate the release dates and you will realize that we merely have weeks and not months left.

Even more concerning is that Apple has just recently released working versions of the profile payload to control the new privacy settings, especially for Apple Events. You can learn the details in this excellent post by Felix Schwarz. I need to highlight this piece from his summary:

I feel, though, that the most responsible way for Apple to handle this situation would follow the playbooks for Group FaceTime and 32 Bit deprecation: postpone the feature until it has matured – and make it available to developers behind a feature toggle until then.

Also, minor milestone: this newsletter has passed 300 subscribers! Thank you all for reading and recommending! (and don’t stop spreading the news!)

If you would rather get the weekly newsletter by email, you can subscribe to the Scripting OS X Weekly Newsletter here!! (Same content, delivered to your Inbox once a week.)

News and Opinion

macOS Mojave

MacAdmins on Twitter

  • Aron Griffis: “Working on a new Bash book. So far: Intro: You chose the wrong tool. Ch 1: Have you considered Python? Ch 2: Try calling Python from your Bash script. Ch 3: If you’re still here, try adding quotes.”
  • Jason Broccardo: “Tea leave reading: Once Apple is shipping Macs with their own A-series ARM chips, VMware Fusion will still works”
  • MacDevOpsYVR: “The next MacDevOps:YVR conference will be in Vancouver, Canada, June 12–14, 2019”
  • Zack McCauley: “Per @Contains_ENG recommendation to post this #MacAdmins please @Apple give us documentation, give us feedback, and for the love all that is left please don’t give us a feature that makes this so much worse on users” (Video)
  • mikeymikey: “! HEY #MACADMINS HEADS UP ! 2017 iPhone event: Sept 12 (T) iOS 11: Sept 19 (T) macOS 10.13: Sept 25 (M) ’16: 7 (W) iOS 10: 13 (T) mac 10.12: 20 (T) ’15: 9 (W) iOS 9: 16 (W) mac 10.11: 30 (W) NOW: 2018: 12 (Wed) iOS 12: 19 (Wed)? macOS 10.14: 26 (Wed)?”
  • Jason Broccardo: “Sys Admin’s idea of winning the lotto: You automatically get elevated past tier 1 on any support call because you’ve already covered all those steps in your troubleshooting before you filed a ticket.”
  • Patrick Gallagher Jr: “Firefox 63 for Mac will add support for using keychain certs.” (but with limitations, read this thread)
  • Carl Ashley: “Remember when we all though SIP was the worst thing?”
  • Kyle Crawford: “Our Apple SE said last year that they regretted how they handled Kext restrictions. Yet here we are again with #AEpocalyse.”

Bugs and Security

Support and HowTos

Scripting and Automation

Apple Support

Updates and Releases

To Listen

Support

There are no ads on my webpage or this newsletter. If you are enjoying what you are reading here, please spread the word and recommend it to another Mac Admin!

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!

Weekly News Summary for Admins — 2018-08-24

As we are getting closer and closer to the iOS 12 and Mojave release, more information is being released and discovered.

Mojave will disable Find-My-Mac, so the application Screens from Edovia has been “reverse Sherlocked!”

Scripting will become much harder for MacAdmins with the new privacy controls in Mojave.

If you would rather get the weekly newsletter by email, you can subscribe to the Scripting OS X Weekly Newsletter here!! (Same content, delivered to your Inbox once a week.)

Headlines

#! On Scripting OS X

News and Opinion

macOS Mojave

MacAdmins on Twitter

  • Thomas Reed: “There appears to be an issue in macOS where removing the ‘restricted’ flag from /Library/StagedExtensions/ causes installation of kernel extensions to always fail.”
  • Guillaume: “If you’re part of a IT or security team managing Mac, make sure you watch at least one of these talks before every Mac out there has a T2 Chip! https://t.co/1MGo5zqPk1 by @gregneagle And https://t.co/kIdpnP5xwh by @grahamgilbert”
  • Laurent Guigo:
    “after .local now .dev extension not enable for localhost develop built in server (no ssl)”

Bugs and Security

Support and HowTos

Scripting and Automation

Apple Support

Updates and Releases

To Watch

Just for Fun

Support

There are no ads on my webpage or this newsletter. If you are enjoying what you are reading here, please spread the word and recommend it to another Mac Admin!

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!

User Interaction from bash Scripts

As MacAdmins our goal is to automate workflows when ever possible. The advantages of automation are great. You immediately reduce the workload, but also reduce the potential for someone to make a mistake, which would mean even more work later.

In nearly all cases, we want the automation to happen “magically” in the background, without any user interaction. User interaction slows down the process as the script is waiting for the user to confirm or enter data. User input also requires validating and checking user entered data.

In most cases, when you believe you need to prompt the user for, well, anything, you should take that moment to re-think your workflow. Maybe you can come up with a different workflow that can provide the data from a source that can be automated without user interaction.

If, however, you really are convinced that user interaction is necessary, then you need be aware there are many potential pitfalls in writing shell scripts with user interaction.

macOS Mojave will introduce even more pitfalls with its increased security features.

Do you really need UI?

A common example for user interaction is to get and set the Computer Name or Asset Tag/ID/Number from manual input.

This is a task that can be fully automated in many situations. As an admin you could provide a text file mapping serial numbers to a name and/or asset tag on a server, that a script can download (curl) and parse. If you have a management system or asset database, there is probably an XML or JSON API, you can use to retrieve this information from a script. You could read or scan the serial numbers from the labels of the Mac’s boxes or even get the list with the purchase order from most vendors. With that data you can pre-fill your text files or databases.

However, in some cases, especially DEP workflows it may be difficult or impossible to predict which computer will end up on which desk, especially with zero-touch deployment workflows, where a device can be sent to a user directly.

In this case, you have to question whether you need a unique, specific computer name or asset tag. Maybe the data which your management system already gathers, such as the user who enrolled the device and its serial number will (have to) be sufficient?

In many cases, however, the reasons to prompt for and set a computer name will not be technical but stem from other, external factors that the IT department may or may not have influence on.

AppleScript’s Moment of Glory

bash was built to run in a text based terminal on many different operating systems. It has (and should have) no concept of a graphical user interface. bash alone is not useful to interact with the user, unless you want to open a terminal window.

However, AppleScript does have some (basic) commands to present dialogs and notifications to the user. We can call AppleScript command from the shell with the osascript command (OSA = open scripting architecture, the underlying framework that AppleScript uses)

There are other tools that allow to display user interface from a shell script. However, they all require an additional installation. AppleScript/osascript is simpler and built-in to the OS, so it is my first choice. That doesn’t mean it is always the appropriate choice, though.

You can go to Terminal and make a dialog appear with

$ osascript -e 'display dialog "Hello from bash!"'

The display dialog AppleScript command is documented in the “StandardAdditions” dictionary. You can see it when you choose ‘Open Dictionary…’ from the File Menu in Script Editor. Then select the “Scripting Additions.osax” dictionary and choose the “User Interaction” category.

This command has a lot of options that allow us to configure the dialog. You can experiment and test with these commands in the Script Editor application. For example, you can change the names of the buttons:

display dialog "Are you sure!?" buttons {"No", "Yes"}

You can also have just one button:

display dialog "Just accept it!" buttons {"Accept"} default button 1

Or three: (three is the maximum)

display dialog "The answer is C" buttons {"A", "B", "C"} default button 3
button returned:C

The script will return which button the user clicked. However, instead of parsing the output with shell tools, you should let AppleScript do the work:

button returned of (display dialog "Are you sure!?" buttons {"No", "Yes"})

The choice variable will be No or Yes.

Adding icons

You can also add an icon to the dialog:

display dialog "Hello" with icon note

Will show the current application’s icon. You can also use stop or caution for different icons.

You can also add a path to an icns file:

display dialog "Hello!" with icon POSIX file "/Applications/Notes.app/Contents/Resources/AppIcon.icns"

Asking for Input

In some cases you want to get information back from the user. You can add a text field to the dialog with the default answer argument. The default answer can be an empty string:

display dialog "Who are you?" default answer "nobody"
display dialog "Who are you?" default answer ""

You can get the result of the dialog with the text returned property:

text returned of (display dialog "Who are you?" default answer "nobody")

You can combine the default answer argument with all the above arguments as well.

Notifications

In some case you just want to notify the user that something happened, and not stall everything while the script waits for confirmation. You can use display notification for these situations:

display notification "Hello, again" with title "Hello"

Running from Shell

You can execute AppleScript from the shell with the osascript command.

osascript -e 'display dialog "Hello!" with icon note'

This works well enough. You also use shell variable substitution:

title='Hey, there!'
osascript -e "display dialog \"What's up?\" with title \"$title\""

When you use variable substitution, you have to use double quotes for the command strings. And then you have to escape any additional double quotes in the AppleScript command. With more complex commands and arguments this will get unwieldy very quickly.

In a bash script you can use a here document instead:

title='Hey, there!'
osascript <<-EndOfScript
display dialog "What's Up?" with title "$title"
EndOfScript

You start a here document with the <<- characters followed by a limit string of your choice (I chose EndOfScript). Then all the text until the limit string is repeated will be fed into the osascript command.

Bash variables will be substituted in the here document, so $title will be substituted with its contents.

Note: I prefer the <<- syntax over the << syntax with osascript. The <<- syntax will ignore leading white space in the following lines, allowing me to properly indent the AppleScript code, making the entire script more legible.

The Trouble with root

Management scripts will run with root privileges. They may also be run in situations where no user is logged in. AppleScript requires a user to be logged in (and a window server to be present) to display the alert.

In many situations all of this will ‘just work’ even when the script is executed from a root process, in others, the script will fail. It is generally safer to always check the current user and run the osascript command as the currently logged in user. You can learn about how and why to do this in this article on ‘Root and Scripting’.

This also gives your script an option to continue silently or fail when no user is logged in.

user=$(python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "\n");')
if [[ $user != "" ]]; then
    uid=$(id -u "$user")
    launchctl asuser $uid /usr/bin/osascript -e "button returned of (display dialog \"Hello\")"
fi

Putting it all Together

While all of these examples are simple enough, you can already see that, once you consider all the possible combinations, everything will get fairly complex.

Over time I have put together a few bash functions that I use in my scripts. Even they only cover quite simple workflows, but can be useful as a sample for more complex needs:

System Events, Privacy and macOS Mojave

In many scripts the author wraps the display dialog command wrapped in a tell statement:

osascript -e 'tell app "System Events" to display dialog "Hello"'

or, like this:

osascript <<-EndOfScript
tell application "Finder"
    activate
    display dialog "Hello"
end tell
EndOfScript

The reason for this is that it will ensure that the dialog is displayed on top of all other windows. The activate command will push the targeted process to the front. Both “System Events” and “Finder” are used frequently.

In most cases this is not necessary, as the dialog will properly display on top of all other windows, even as a standalone command. There may be some weird conditions when other applications are launched in the same time frame, though. In other cases it may be better to use display notification, anyway.

In macOS Mojave, Apple Events (AppleScript Commands) can only be sent to another application with user permission.

When you try this command in macOS Mojave, the user will be prompted to allow the Terminal application to control the System Events application

Apple Event permission dialog

If the user denies this request, the osascript command will fail with an error:

$ osascript -e 'tell app "System Events" to display dialog "Hello"'
28:50: execution error: Not authorized to send Apple events to System Events. (-1743)

Once a user has denied access, they will not be prompted again. They will have to go to the ‘Privacy’ tab in the ‘Security & Privacy’ pane in System Preferences, search for ‘Automation’ and allow access for Terminal.

Security & Privacy Pane in macOS Mojave

However, management scripts will usually not be executed from Terminal, but from within the context of an installation script or management agent. It may be possible to pre-approve configurations with a UAMDM configuration profile, but it will be impossible to anticipate all contexts in which your scripts may run.

For macOS Mojave it will be better to either modify your script to not wrap the command in a tell statement. Alternatively, you can use a different solution for the UI altogether. (e.g. jamfHelper, Yo, Pashua or CocoaDialog)

All of these wrapped commands in scripts will break in macOS Mojave!

MacAdmins need to go through all their management scripts and check for AppleScript UI commands wrapped in tell statements.

When you use the standalone display dialog it will be the AppleScript process itself that displays the dialog. This requires no specific permission.

Even if your dialogs may not appear on top of all the windows, this is a preferable solution.

This will also affect scripts using osascript to control or receive data from other applications.

Summary

  • question and revisit every use of user interaction in your workflow
  • when you really have to, you can use osascript with the display AppleScript commands
  • to be safe, run the commands as the current user
  • increased macOS Mojave security will require you to verify all your scripts using osascript

Weekly News Summary for Admins — 2018-08-17

Days are getting shorter, summer is starting to wane, and the Apple System release date is getting closer and closer.

Apple released new betas and finally updated the MDM and Configuration Profile References, leaving MacAdmins little time to test and file bugs to be fixed. MacAdmins took to Twitter to complain.

Also Twitter finally turned off many API features, thus crippling third party Twitter apps TweetBot and Twitteriffic.

If you are considering moving away from Twitter – there certainly enough reasons, technical and non-technical – Scripting OS X and this newsletter are available on many other channels, including Micro.blog, Mastodon.social, and Apple News. You can find all ways to follow at the end of this post.

If you would rather get the weekly newsletter by email, you can subscribe to the Scripting OS X Weekly Newsletter here!! (Same content, delivered to your Inbox once a week.)

News and Opinion

macOS Mojave

MacAdmins on Twitter

  • Objective-See: “Announcing ”Objective by the Sea“ a new Mac Security Conference: Nov 3rd/4th in Maui Hawaii @ the stunning Wailea Beach Resort Talks by @thomasareed @iamevltwin @patrickwardle @rrcyrus @jbradley89 & more! …and free for Objective-See patrons”
  • Federico Viticci: “Nice to see a new Shortcuts beta on Aug. 10th”
  • Guilherme Rambo:
    “They AirPlay2’d Group FaceTime…”
  • Erik Gomez: “Apple releases MDM changes on beta 7 and asks for feedback/regression testing. The reports wont be fixed in 10.14.0. Remember when you warned people to get tickets in before beta 2 to ensure they make it into the GM? These changes should be delayed to the Spring Release”
  • Erik Gomez:
    “#macadmin #macadmins – if you’re interested in testing some important changes coming to Mojave, please join the #tcc channel on macadmin’s slack Also here is a google doc for tracking this, much like we did with kexts/32-bit apps https://docs.google.com/spreadsheets/d/1sai3Q8qj9HdyDJfcSAchRELD0mOpik1NPYxr0F9AJRc/edit#gid=0”
  • Tim Sutton: “If you would ever like the automated creation of a macOS Mojave system image to be possible – (asr imaging or creation of VMs via vfuse or similar).. you may want to dupe Mike’s rdar quoted below, and/or mine: http://www.openradar.me/radar?id=5004136198176768”
  • Per Olofsson:
    “I posted a new beta of AutoDMG with a couple of Mojave workarounds”
  • mikeymikey: “Honestly – between you and me – with what this bug does and what beta 7 just added, 10.14 feels like it’s shaping up to be “10.13 Part 2” / “The Revenge of 10.13” for #macadmins”
  • William Smith: “New installs of Office for Mac 16.16 (this month’s release) and higher will install Microsoft AutoUpdate 4.2. Going forward, it will default to Automatically Download and Install. #MacAdmins, if you need to manage this, the best method is use a configuration profile.…”
  • Rich Trouton:isnetbootdead.com

Bugs and Security

Support and HowTos

Scripting and Automation

Apple Support

Updates and Releases

To Listen

Just for Fun

Support

There are no ads on my webpage or this newsletter. If you are enjoying what you are reading here, please spread the word and recommend it to another Mac Admin!

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!

Weekly News Summary for Admins — 2018-08-10

Summer is progressing. Fall is nigh. Mojave beta 6 dropped. The first Mojave posts are appearing.

If you would rather get the weekly newsletter by email, you can subscribe to the Scripting OS X Weekly Newsletter here!! (Same content, delivered to your Inbox once a week.)

News and Opinion

macOS Mojave

MacAdmins on Twitter

  • mikeymikey: “This thread contains a good reminder of one of the few things I’ll tell you mobileconfig profiles are great at… ”
  • Scott Knight: “I created an osquery extension so #MacAdmins could query 32-bit usage across their fleet once 10.14 is released. Hopefully this makes it even easier to identify software that needs to be upgraded prior to 10.15.”
  • macshome: “Oh cool! The Apple developer docs now go all the way back to 1985! Presenting Technical Note OS01”

Bugs and Security

Support and HowTos

Scripting and Automation

Apple Support

Updates and Releases

To Watch

Support

There are no ads on my webpage or this newsletter. If you are enjoying what you are reading here, please spread the word and recommend it to another Mac Admin!

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!

Weekly News Summary for Admins — 2018-08-03

Briefly resurfacing from vacation. Much has happened in the last three weeks. This is a long one: find a nice sunny (or shady) spot to settle down, read, and enjoy.

(Vacation time isn’t over. Updates will remain irregular until the end of August.)

Mojave and iOS 12 are now at beta 5. There may be Photoshop on iPad. Apple had a record quarter (once again) and is the first company to be traded at a market cap of 1 trillion USD. They also cancelled the affiliate program for Apps on iOS and macOS.

About the last topic: I use affiliate links for apps and books in this newsletter and other posts on the weblog. I don’t make much money from them – it adds up to be enough to afford a movie on iTunes every month or so. The affiliate rate for books remains unchanged (for now). Only Apple has the full insight to the numbers involved, but this still seems like a petty move from Apple.

In this time of free services and apps, writing a review or article that convinces someone to part with their money is not easy. If you can pull that off, affiliate links can be a way to earn money from writing (or podcasts, or videos) without filling up your site with obnoxious ads that are not under your control.

Doing so on a scale that the payout is actually worth the effort is incredibly hard. You have to build up a reputation and trustworthiness with your writing (or videos or podcasts). This takes a lot of time and effort. In the end, Apple and the producer (developer, author, etc.) profit from a good review or recommendation. This should have been a win-win-win situation.

Of course, Apple can do what they want and is not and has never been obliged to provide or continue this program. But I am sad that the affiliate program for Apps is going away, as many sites that I enjoy and appreciate will suffer from it. I believe this is a wrong step for the community and eco-system.

If you want to support this newsletter and my weblog (so I can keep buying new movies), buy my books!

In other book- and milestone-related news: This week I sold my 1000th book on the iBooks Store.

A huge “thank you” to everyone who put enough trust in my writing to buy one or more of my books. Even more thanks to those who recommend the books on Slack, conferences, in personal discussion and with reviews on the store. (Seriously, please leave a review!) Writing and publishing continues to be an exhilarating, rewarding and humbling experience.

On to the next book and the next 1000 sales!

If you would rather get the weekly newsletter by email, you can subscribe to the Scripting OS X Weekly Newsletter here!! (Same content, delivered to your Inbox once a week.)

Headlines

On Scripting OS X

News and Opinion

macOS Mojave

MacAdmins on Twitter

  • William Smith: “After two days of trying to reformat PDF text and pictures on my #psumac slides to fit all my presenter notes, a simple 2-minute AppleScript fixes my problem. tell application ”Keynote“ to set size of presenter notes of every slide of front document to 18 #voilà”
  • Nigel Kersten: “It’s been a long time since I last made the NVRAM claw. ⌘ ⌥ O F Never Forget.”
  • Tim Perfitt: “Ok, so after many tried, this works reliably: power down, then power up. As soon as the apple appears, press control option on left side and shift on right along with power. Keep holding until the machine powers down and a bit more. It then goes into DFU.” (Thread)
  • Nikolaj Schlej: “macOS 10.13.6 update brings (limited) UEFI SecureBoot support for iMac Pro, so now if SecureBoot is enabled, Windows detects that and acts accordingly. PK, KEK, db and dbx are read-only (hence limited), configured to trust MS 1st-party CA only.…”
  • Emily St: “Extremely cool macOS information for mega-nerds: If you’re wondering what iCloud Drive is up to in a given moment, a command will tell you all the transactions it’s running: brctl log --wait --shorten Recommend piping that to less because it’s a huge log of output.”
  • Ryan Govostes: “Early screenshot of System Integrity Protection, MacOS 8.0 (1997)… ”
  • Jordan Morgan: “A fun bit of #macOS development history I stumbled upon today, Apple Tech Note 2034. Essentially it included a bunch of guidelines and tips on macOS development but contained such inflammatory assertions that Apple straight up pulled it down (2033/5 are still there)!” (Thread)

Bugs and Security

Support and HowTos

Scripting and Automation

Apple Support

Updates and Releases

To Watch

To Listen

Just for Fun

Support

There are no ads on my webpage or this newsletter. If you are enjoying what you are reading here, please spread the word and recommend it to another Mac Admin!

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!