MDOYVR 22 Talk: The Encyclopedia of macOS Automation

Last week I had the pleasure and honor of participating and presenting at MacDevOps YVR. The videos for the sessions are now appearing on YouTube.

There is a page for my talk “The Encyclopedia of macOS Automation,” in which I discuss the options for scripting and automation on macOS, with extra links and notes. You can go directly to the video here.

The talks this year were graphic recorded by the amazing Ashton Rodenhiser (website, twitter). The graphic at the top of this post was made by her while I was presenting.

As always, I had a lot of fun at this conference. Many thanks to the organizers and all the other speakers. Until next year!

Weekly News Summary for Admins — 2022-06-17

First week post WWDC and there are many more reactions and even some nice features, or rather dogcows discovered in the beta releases. (Moof!)


(Sponsor: SentinelOne

7 New Security Changes macOS Admins Should Be Aware Of

As WWDC 2022 closes out, here are some interesting – and potentially disruptive – changes with macOS Ventura that have received less attention.

Continue Reading Here >


Greg Neagle points out that other new features in Ventura may spell some trouble or at least extra preparation work for MacAdmins.

We also got beta3 of macOS 12.5, iOS 15.6 and siblings. So many things to test.

MacDevOps YVR is happening right now, as well as the PSU MacAdmin Campfire sessions! So many things to watch.

The M2 13″ MacBook Pro (the strange left over design with the TouchBar) can be ordered starting today, and the benchmarks look quite amazing. I am waiting for the M2 MacBook Air. I want that shiny midnight blue newness…

If your company or product is a good fit as a sponsor for this news summary, please contact me!

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 Ventura and iOS 16

Social Media

  • John C. Welch: “For ASOC folks: if you copy /Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates/Project Templates/macOS/Other/AppleScrip App.xctemplate from Xcode 13.x to /Applications/Xcode-beta.app/Contents/Developer/Library/Xcode/Templates/Project Templates/Other/ then you can still create ASOC apps with Xcode 14 beta.”
  • James Dempsey: “Ah, Xcode Server—you arrived with Xcode 5 as part of OS X Server, then became part of Xcode itself in Xcode 9, and are now deprecated in Xcode 14. Thank you for nine wonderful years of never quite working right for me.”

Security and Privacy

Support and HowTos

Scripting and Automation

Updates and Releases

To Watch

To Listen

Support

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 — 2022-06-10

WWDC! As usual, we get the previews and betas for the upcoming systems from Apple. Monterey seemed to be a some what quieter “tok”, to Big Sur’s “tik” release, mostly focusing on consolidation and stability. macOS Ventura, iOS 16 and iPadOS 16 look like substantive “tik” releases, full of new features and behaviors.


(Sponsor: Mosyle)

Mosyle Logo

The only Apple Unified Platform for Business

Mosyle is the only solution that fully integrates Enhanced MDM, Endpoint Security, Internet Privacy & Security, Single Sign-On, and Application Management on a single Apple-only platform.

Click here to learn why Mosyle is all you need to work with Apple.


AppleSeed for IT has two documents, the “macOS 13 beta 1 Release Notes” and “What’s new for Enterprise and Education” which also full of useful information for Apple Admins, only some of which was covered in the sessions relevant for admins. (Which I list below.)

Lots to process and test. There will be much feedback to file. Spin up those test devices and VMs!

If you think your company or product is a good fit to sponsor this newsletter, please contact me!

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 Ventura and iOS 16

Reactions

Interesting WWDC Sessions for Admins

macOS and iOS Updates

Social Media

  • Mr. Macintosh: “macOS Ventura hardware support MASSACRE! ☠️ Dropped Mac Hardware: 2015-2016 MacBook Pro, 2015-2017 MacBook Air, 2016 12″ MacBook, 2014 Mac mini, 2013 Mac Pro, 2015 iMac”
  • mikeymikey: “Crucial design considerations for macOS apps with regards to LaunchDaemons, LaunchAgents, and LoginItems. New APIs, design recommendations, and more with macOS Ventura
  • Mr. Macintosh: “Confirmed by @khronokernel on March 8th Apple is following a new Model ID format: DeviceID – Model ID – Description (Product ID); J413AP = Mac14,2 – MacBook Air (M2, 2022); J493AP = Mac14,7 – MacBook Pro (13-inch, M2, 2022)” (All new Macs now get a Model ID of MacXX,Y.)
  • Bart Reardon: “Two sides of #WWDC22 : Developers: ‘Shiny!’ Admins: ‘WTF DID YOU BREAK'”
  • Rosyna Keller: “Main new news is that notarization submissions via altool and via the app distribution workflow for non-Mac App Store apps in Xcode 13.x and earlier are deprecated (and slower) and are walking into the sunset in Fall of 2023” (Thread)
  • John C. Welch: “I honestly think custom, complex, customer created workflows that aren’t created by devs for devs is going to be dead in the Apple world outside of companies like MS and Adobe that can just build that into their apps. Like in two years.” (Thread)
  • mikeymikey: “There are important implementation changes with macOS 13 with regards to underlying components used routinely in non-consumer managed environments, such as SMB and SCEP For details regarding this, please sign in with AppleSeed for IT and read the IT macOS 13 Beta 1 Release Notes”

Security and Privacy

Support and HowTos

Scripting and Automation

Apple Support

Updates and Releases

To Listen

Support

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 — 2022-06-03

Scheduling my vacation right before WWDC resulted in a big summary. Lots of interesting links that should keep you distracted until the keynote on Monday.


(Sponsor: Mosyle)

Mosyle Logo

The only Apple Unified Platform for Business

Mosyle is the only solution that fully integrates Enhanced MDM, Endpoint Security, Internet Privacy & Security, Single Sign-On, and Application Management on a single Apple-only platform.

Click here to learn why Mosyle is all you need to work with Apple.


WWDC is not the only conference that is imminent. The MacAdmins Campfire Sessions have started this week and will continue for the next few weeks!

You may have noticed this newsletter was not sent out at the usual time. I am still traveling and in different time zones. Next week, I should be back in the normal rhythm, jet lag permitting. And we will have all the news from WWDC. Until then!

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 and iOS Updates

Social Media

  • Rosyna Keller: “When creating a zip file for submission to the notarization service, make sure to use the ditto command line tool, the Finder, or Archive Utility to create the zip file. The zip command line tool is unfriendly to macOS metadata (especially detached code signatures).”

Security and Privacy

Support and HowTos

Scripting and Automation

Apple Support

Updates and Releases

To Watch

To Listen

Support

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!

2022 Conference Season Speaking Schedule

With WWDC starting very soon, the MacAdmin conference season ramping up. I keep track of all the major MacAdmin conferences on my conferences page but I thought a summary of where I am going to present might be interesting:

MacDevOps YVR, June 15–17, Online

Yes, it is very disappointing that the uncertainties of the pandemic still make in-person conferences impractical. That said, I really enjoy the online format of MacDevOps YVR. Presentations are held on YouTube with Q&A and “Hallway Track” interactions on Discord. This year, most of the presentations, including my talk on ‘The Encyclopaedia of macOS Automation” will be restricted to 15 minute quick talks, which is an interesting challenge. Registration is still open!

Jamf Nation Live, Munich, Germany, June 23

Not a conference, but close. I will be presenting at the Jamf Nation Live event at the Allianz Arena near Munich on June 24. You will get the privilege of seeing me try to present in German for the first time in 17 years. Registration is still open. There are other Jamf Nation Live events in London (June 10), Amsterdam (June 16), and Paris (June 21).

Jamf Nation User Conference, San Diego, USA, September 27–29

Jamf Nation User Conference (JNUC) is going to be a hybrid event this year. You can choose to attend in person in San Diego, CA or online. Several sessions will be online only but some will be on stage. I am proud that my session on “Use Swift with the Jamf API” has been accepted to be presented on stage. Registration for both in person and online is still open.

MacSysAdmin, Göteborg, Sweden, October 4–7

In its 17th year, MacSysAdmin is going virtual again. Details are still forthcoming, but I will be providing a presentation.

So this is where you can see me present this year. Now I really should go work on those slides…

macOS 12.4 and iOS 15.5

The updates for macOS 12.4, iOS 15.5 and all the siblings dropped yesterday. Usually I would gather a list of links for these updates in the news summary on Friday, but since I will be on a vacation break and they will seem stale in two weeks, you will get them now. Enjoy!

Update 2022-05-19: added Apple Business and School Manager User Guides.

macOS Monterey 12.4

iOS 15.5 and iPadOS 15.5

watchOS 8.6

tvOS 15.5

Other Updates

User Guides

Community

Support

Update Installomator: v9.2

We have updated Installomator. This brings Installomator to 465(!) applications! Many thanks to everyone who contributed.

Note: Both Google and Mozilla recommend using the pkg installers instead of the dmg downloads for managed deployments. So far, Installomator has provided labels for both. (googlechrome and googlechromepkgor firefox and firefoxpkg, respectively) Since there are problems with the dmg downloads, a future release of Installomator will disable the firefox and googlechrome dmg labels. You should switch to using the firefoxpkg or googlechromepkg labels instead.

  • bug and documentation fixes
  • 40 new, and 26 updated labels

You can find more details in the release notes.

Weekly News Summary for Admins — 2022-05-13

Last week I mentioned that Apple often releases a few things before WWDC, because they don’t fit in the keynote. I should have been careful what I wished for: the iPod touch — the last remnant of the iPod line — is being discontinued.


(Sponsor: Mosyle)

The only Apple Unified Platform for Business

Mosyle is the only solution that fully integrates Enhanced MDM, Endpoint Security, Internet Privacy & Security, Single Sign-On, and Application Management on a single Apple-only platform.

Click here to learn why Mosyle is all you need to work with Apple.


Like the discontinuation of macOS Server, this doesn’t come as much of a surprise. The main iPod line was discontinued in 2017. I wrote an article then, and I think it still holds up well.

The functionality of the iPod has been assimilated by the iPhone, Apple Watch, HomePod, and AirPods, all of which can now play your Music nearly anywhere, anytime. The iPod may be gone, but the Music lives on.

The news summary will be taking a short vacation break. It will resume in three weeks, on “WWDC Eve”, June 3, with a summary of everything else that happens between now and then. Let’s hope Apple is done with canceling products.

Never miss a post and get the weekly newsletter by email, you can subscribe to the Scripting OS X Weekly News Summary here!! (Same content, delivered to your Inbox once a week.)

News and Opinion

Social Media

  • Jack Rhysider: “If you’re in IT, I highly encourage you to write a blog. Here are 17 reasons why you should be blogging.” (Thread, if you start a Mac IT blog, be sure to let me know!)
  • William Smith: “For Jamf admins, ensure your configuration profiles with the Exchange (macOS) and Exchange ActiveSync (iOS) payloads are set to ‘Use OAuth for authentication’ before the October 1st deadline.”

Security and Privacy

Support and HowTos

Scripting and Automation

Apple Support

Updates and Releases

To Listen

Support

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 — 2022-05-06

The month of May is like “advent for Apple fans.” WWDC is looming in a few weeks. Most of the dust from previous system releases has settled. Things have been fixed, or we have gotten used to the workarounds. Anticipation and dread for the next round of releases is rising. Sometimes, Apple even opens a door or two and releases something which didn’t fit in the keynote.


(Sponsor: Mosyle)

The only Apple Unified Platform for Business

Mosyle is the only solution that fully integrates Enhanced MDM, Endpoint Security, Internet Privacy & Security, Single Sign-On, and Application Management on a single Apple-only platform.

Click here to learn why Mosyle is all you need to work with Apple.


MacDevOps YVR have announced their speaker line-up for their virtual conference in June, and I am very proud to be among all these amazing speakers. You can still register for the event from June 15–17. You can also order MacDevOpsYVR 2022 t-shirts and hoodies!

Also the dates and location for this year’s Objective by the Sea were announced: It will go from October 3–7, in Spain, near Barcelona.

As always, I keep a list of conferences, their dates and other important links, such as calls for presentation and session video archives from previous conferences on my conferences page.

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

Social Media

  • tlark: “ATTN MDM vendors. Please take a long good look at Munki, it is what IT admin/eng want. We don’t want complex systems that require GUI clicking. We just reduced our level of effort by ripping out third party app deployment/patching from our MDM and deployed Munki in AWS” (Thread)

Security and Privacy

Support and HowTos

Scripting and Automation

Updates and Releases

To Watch

To Listen

Support

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!

Launching Scripts #4: AppleScript from Shell Script

In the last post, we discussed how to run shell commands and scripts from an Apple Script environment. In this post, we will look at how we can run AppleScript commands and scripts from the shell environment.

Open Scripting Architecture

The key to running AppleScript from the shell is the osascript command. OSA is short for ‘Open Scripting Architecture’ which is the framework that powers AppleScript. This framework allows AppleScript to have its native language, but also use JavaScript syntax.

The osascript command allows us to run AppleScript commands from Terminal and shell. The most common use is the user interaction commands from AppleScript, like display dialog:

osascript -e 'display dialog "Hello from shell"'

The -e option tells osascript that it will get one or more lines of statements as arguments. The following argument is AppleScript code. You can have multiple -e options which will work like multiple lines of a single AppleScript:

> osascript -e 'display dialog "Hello from shell"' -e 'button returned of result'
OK

osascript prints the value of the last command to stdout. In this case, it is the label of the button clicked in the dialog. (The ‘Cancel’ button actually causes the AppleScript to abort with an error, so no label will be returned for that.)

When you have multiple lines of script, using multiple -e statements will quickly become cumbersome and unreadable. It is easier to use a heredoc instead:

osascript <<EndOfScript
   display dialog "Hello from shell"
   return button returned of result
EndOfScript

This also avoids the problem of nested quotation marks and simplifies shell variable substitution.

Shell variables and osascript

There are a few ways to pass data into osascript from the shell.

Since the shell substitutes variables with their value before the command itself is actually executed, this works in a very straightforward manner:

computerName=$(scutil --get ComputerName)

newName=$(osascript -e "text returned of (display dialog \"Enter Computer Name\" default answer \"$computerName\")")

echo "New Name: $newName"

This works well, but because we want to use shell variable substitution for the $computerName, we have to use double quotes for the statement. That means we have to escape the internal AppleScript double quotes and everything starts to look really messy. Using a heredoc, cleans the syntax up:

computerName=$(scutil --get ComputerName)

newName=$(osascript <<EndOfScript
    display dialog "Enter Computer Name" default answer "$computerName"
    return text returned of result
EndOfScript
)

echo "New name: $newName"

I have a detailed post: Advanced Quoting in Shell Scripts.

Environment Variables

Generally, variable substitution works well, but there are some special characters where it might choke. A user can put double quotes in the computer name. In that case, the above code will choke on the substituted string, since AppleScript believes the double quotes in the name end the string.

If you have to expect to deal with text like this, you can pass data into osascript using environment variables, and using the AppleScript system attribute to retrieve it:

computerName=$(scutil --get ComputerName)

newName=$(COMPUTERNAME="$computerName" osascript <<EndOfScript
    set computerName to system attribute "COMPUTERNAME"
    display dialog "Enter Computer Name" default answer computerName
    return text returned of result
EndOfScript
)

echo "New name: $newName"

The shell syntax

VAR="value" command arg1 arg2...

sets the environment variable VAR for the process command and that command only. It is very useful.

Retrieving environment variables in AppleScript using system attribute is generally a good tool to know.

Interpret this!

osascript can also work as a shebang. That means you can write entire scripts in AppleScript and receive arguments from the shell. For example, this script prints the path to the front most Finder window:

#!/usr/bin/osascript

tell application "Finder"
    if (count of windows) is 0 then
        set dir to (desktop as alias)
    else
        set dir to ((target of Finder window 1) as alias)
    end if
    return POSIX path of dir
end tell

You can save this as a text file and set the executable bit. I usually use the .applescript extension.

> print_finder_path.applescript
/Users/armin/Documents

To access arguments passed into a script this way, you need to wrap the main code into a run handler:

#!/usr/bin/osascript

on run arguments
    if (count of arguments) is 0 then
        error 2
    end if
    return "Hello, " & (item 1 of arguments)
end

You can combine this into a longer script:

macOS Privacy and osascript

When you ran the above script, you may have gotten this dialog:

If you didn’t get this dialog, you must have gotten it at an earlier time and already approved the access.

AppleEvents between applications are controlled by the macOS Privacy architecture. Without this, any process could use AppleEvents to gather all kinds of data from any process. These dialogs are easy enough to deal with when running from Terminal. But if you put your AppleScript code (or shell scripts calling AppleScript) into other apps or solutions, it could get messy quite quickly.

Mac Admins generally want their automations to run without any user interactions. You can avoid these dialogs by creating PPPC (Privacy Preferences Policy Control) profiles that are distributed from an MDM server. In this case you have to pre-approve the application that launches the script, which can sometimes also be challenge. The other option is to find solutions that avoid sending AppleEvents altogether.

I have a longer post detailing this: Avoiding AppleScript Security and Privacy Requests

osascript and root

Management scripts often run as a privileged user or root. In this case, certain features of AppleScript may behave strangely, or not at all. I generally recommend to run osascript in the user context, as detailed in this post: Running a Command as another User

Conclusion

AppleScript’s bad reputation may be deserved, because its syntax is strange, and often very inconsistent. Nevertheless, it has features which are hard to match with other scripting languages. You can use the strategies from this and the previous posts to combine AppleScript with Shell Scripting and other languages to get the best of both worlds.