Weekly News Summary for Admins — 2018-11-10

Mac minis are real and being delivered to customers!

Apple sent out some updates for their Apps, Pages can now publish to Apple Books and iMovie on a new iPad pro can power a large external screen.

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.)

On Scripting OS X

News and Opinion

MacAdmins on Twitter

  • James F: “Here’s a script illustrating how to use the #Jamf Pro API I made for my #jnuc2018 interactive lab ”Getting Started with the Jamf Pro API“”
  • Erik Gomez: “To help foster community help, effective today, UMAD and nudge have been moved to my personal GitHub and off the pseudo joke org I made when I developed the tools.”
  • mikeymikey: “Take the hint…”
  • Brian Stucki: “The documents for the new Mac mini were just released. Includes the Essentials, the Quick Start and the Info Guide. Also includes this picture of the Retina display that Apple should definitely make and sell.”

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!

Mojave Quick Action to Package Apps

One of the new macOS features in Mojave are “Finder Quick Actions.”

They show as action buttons in the Finder in Column View and the new Gallery View. You can also access Quick Actions in any view from an item’s context menu.

You can configure Quick Actions in the ‘Finder’ section of the ‘Extensions’ Preference Pane. The four sample actions that come with Mojave are ‘Rotate,’ ‘Markup,’ ‘Create PDF,’ and ‘Trim’. While these are certainly useful, they are oriented towards media.

You can, however, build your own Quick Actions with Automator!

Custom Quick Action

When you look at it closely, Quick Actions are re-branded Automator Service Workflows. They are even stored in ~/Library/Services.

Let’s build a useful Quick Action for admins.

Quick Packaging

Recap: You can quickly build an installer package from an application bundle with pkgbuild:

$ pkgbuild --component /Applications/Firefox.app Firefox-63.0.pkg

This even works when the application is not installed on the current system, but then you have to add the --install-location argument:

$ pkgbuild --component /Volumes/Firefox/Firefox.app/ --install-location /Applications Firefox-63.0.pkg

This allows you to build an installer package from a disk image without having to install it.

Note: this method works well with ‘drag to install’ type applications. For many other applications, re-packaging is more elaborate. Learn all the details of packaging in my book: “Packaging for Apple Adminstrators

To make this simple process even simpler, I wrote a small script a while back called quickpkg, which simplifies this even further:

$ quickpkg "~/Downloads/Firefox 63.0.dmg"

(For help with downloading and installing scripts like quickpkg see this post.)

This seems like a good candidate for a Quick Action.

Bring in the Robot

Open the Automator application and create a new Workflow. Choose “Quick Action” as the type of Workflow.

New Workflow Window for a Quick Action in Finder

This will present an empty workflow window with a list of categories and actions on the left and the area where you assemble the workflow on the right. Above the workflow area is a panel where you define the input for our Quick Action. Change the popups to match this image:

Input for our QuickAction
Input for our QuickAction

Then add a ‘Run Shell Script’ action from the list on the left. The easiest way to locate the action is with the search box, or you can find the ‘Run Shell Script’ action in the ‘Utilities’ category. Drag it to the workflow area, labelled ‘Drag actions or file here to build your Workflow.’

Make sure that the shell popup is set to /bin/bash and the ‘Pass input’ popup is set to ‘to stdin’. With these settings, the selected file(s) will be passed as a list of paths, one per line to the stdin stream of the bash code we enter in the text area.

Add the following code:

destination="$HOME/Documents/"

while read -r file; do
    /usr/local/bin/quickpkg --output "$destination" "$file"
done

Your action should look like this:

First, we set a bash variable for the destination folder. You can change this to another path if you want to, but the destination folder has to exist before the workflow runs, otherwise you’ll get an error.

Then we use a while loop with the read command to read the stdin input line by line. Then we run the quickpkg tool once for each line.

You can now save the Workflow (it will be saved in ~/Library/Services/) and then ‘QuickPkg’ (or whatever name you chose) will appear in Finder, for any selected item. Unfortunately, the Automator input controls don’t allow to filter for file types other than the few given ones.

Select a dmg with an application in it, such as the dmg downloaded from the Firefox website and wait a moment. Then check the ~/Documents folder for the result.

(A rotating gear wheel will appear in the menu bar while the action is running. This is all the feedback you can get.)

Revealing the Result

It is annoying that we have to manually open the destination folder to see our result. But the nice thing is that we can let the workflow take care of that. In the action list on the left, search for ‘Reveal Finder Items’ or locate this action in the ‘Files & Folders’ category. You can drag it to the end of your workflow, below the ‘Run Shell Script’ action or just double-click in the list to add to the end of your workflow.

The extended Workflow

Save and run again from the Finder. It should now reveal the pkg file automatically.

You can add more actions to the workflow. For example, you can add actions to

  • open with Pacifist or Suspicious Package
  • tag the pkg file
  • add a comment
  • append the date to the file name
  • copy the pkg to a file share

Improving the Workflow

You may have noticed during testing that in its current form the workflow doesn’t really react well when something goes wrong.

quickpkg can work with .app, .dmg, and .zip files. Unfortunatly, Automator does not let us filter for just those file types in the input setup. The script will report an error when you try to run it against a different file type, but the error is not displayed in Finder.

It is not that difficult to extend our short script to make it a bit more resilient. Change the code in the ‘Run Shell Script’ action to this:

destination="$HOME/Documents/"

while read -r file; do
    result=$(/usr/local/bin/quickpkg --output "$destination" "$file")

    if [[ $? != 0 ]]; then
        osascript -e "display alert \"QuickPkg: An error occured: $result\""
    else
        echo "$result"
    fi
done

With this code we check result code $? of the quickpkg command for an error. If the code is non-zero we display an alert with osascript. If all went well, we echo the result (the path to the new pkg) to stdout, so that Automator can pass that into the following actions.

This is still a fairly crude error handling, but much better than nothing.

Summary

It is quite easy to turn simple shell commands into Automator workflows and Finder Quick Actions. Keep this in mind, when you find yourself performing repetetive tasks in Finder or in Terminal.

Weekly News Summary for Admins — 2018-11-02

New Mac mini! We finally got a new Mac mini!

Oh, and a new MacBook Air and some iPad Pros, too. iOS 12.1 and macOS Mojave 10.14.1, as well. But seriously, did you see the new Mac mini!?

The new Macs have the T2. Now, the majority of new Mac models and quite likely the majority of Macs units sold have Secure Boot and don’t support traditional deployment workflows any more.

The Mac mini and the new MacBook Air also require Mojave 10.14.1 and will likely have a forked build of Mojave.

If you need to learn about the new installation workflows available with High Sierra and Mojave, you can buy my book: “macOS Installation for Apple Administrators

Talking about Secure Boot and T2: among all the other new around the new Macs, iPads, macOS 10.14.1 and iOS 12.1, Apple also released a whitepaper on the T2 Chip. If you don’t read anything else this week, read this. (or at at least Rich’s or David’s summaries)

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.)

Apple October Event

On Scripting OS X

News and Opinion

MacAdmins on Twitter

  • Chapin Bryce:up – cli tool that allows you to manipulate and interact with streams to prototype modification cmds (ie grep, cut, awk). It’s easier to watch the gif then for me to describe in 140 chars” (via Erik Gomez:)
  • mikeymikey: “Heads up macadmins – if you have devices in your fleet where people installed 10.14.0 ”not labeled as beta“ build 18A389 aka ”people thought it was GM but it didn’t say GM“, the 10.14.1 update does not upgrade it.”
  • mikeymikey: “Hey #macadmins This was published in June. But you should probably look at it again. Soon.”
  • Bill Amend:
    “20 years ago I did one of my favorite strips ever. #HappyHalloween… ”

Bugs and Security

Support and HowTos

Scripting and Automation

Apple Support

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!

Include Assets in External macOS Installer Drives

Apple has included a tool to build a bootable external installer drive with the macOS Installer application for a while now. Apple actually has documentation for this tool.

The tool is called createinstallmedia and can be found in /Applications/Install macOS [[High ]Sierra | Mojave].app/Contents/Resources/.

When run, the tool requires a path to an external volume or partition, which will be erased and replaced with a bootable installer volume.

Note: Secure Boot Macs with the T2 chip cannot boot from external drives in the default configuration. As of this writing this affects the iMac Pro and the 2018 MacBook Pro. But it is expected that any new Macs released from now on (as in maybe at the Apple Event tomorrow?) will also have Secure Boot.
Nevertheless, having an bootable external installer is still every useful for ‘legacy’ (i.e. non-secure boot) Macs. Also, while it not a good general configuration, it can be very useful to enable external boot on machines that you frequently re-install for testing.

While the support article covers the basics, the tool gained a new feature in Mojave which is not documented in the article.

When you run the Mojave createinstallmedia tool without arguments you get the usage documentation:

$ /Applications/Install\ macOS\ Mojave.app/Contents/Resources/createinstallmedia 
Usage: createinstallmedia --volume <path to volume to convert>

Arguments
--volume, A path to a volume that can be unmounted and erased to create the install media.
--nointeraction, Erase the disk pointed to by volume without prompting for confirmation.
--downloadassets, Download on-demand assets that may be required for installation.

Example: createinstallmedia --volume /Volumes/Untitled

This tool must be run as root.

The new argument in the Mojave is called --downloadassets. The description is a bit sparse, but from what I gather this is download additional assets, like firmware installers and bundle them with the other installer files on the installer drive instead of downloading them on-demand during installation.

This will not remove the requirement for the Mac to be connected to the internet during the installation process but it should speed up the process quite a bit.

If you want to learn more about how to create external installers and how to use the macOS Installer app most effectively in your workflows, you can buy my book ‘macOS Installation for Apple Administrators

Weekly News Summary for Admins — 2018-10-27

Somewhat delayed summery this week-end again. Quiet week while nearly everybody was at JNUC having fun.

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.)

On Scripting OS X

News and Opinion

MacAdmins on Twitter

  • Julia Evans: “New zine: Oh shit, git! It’s based on ohshitgit.com and it tells you how to get out of git messes. By me and the amazing @ksylor.”

Support and HowTos

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!

Changing a User’s Login Picture

Nick asked a question in the comments recently:

Now only if there was as simple a tool for setting the profile pic!

There is no simple tool, but it is not that hard really.

When an individual user wants to change their login picture, they open the Users & Groups preference pane. But if want to pre-set or change it for multiple Computers or Users, then we need to script.

Update 2019-09-20: Some of this seems to have changed since I wrote this. in 10.14.6 you will need to set the JPEGPhoto  attribute as well. Read Alan Siu’s post for details.

Where is it stored?

The data for the user picture is stored in the user record in the directory. If the user is stored locally the directory is just a bunch of property list files in /var/db/dslocal/nodes. However, we do not want to, nor should we manipulate them directly. The tool to interface with directory data is dscl (directory service command line, pronounced diskel)

You can get a user’s record data like this:

$ dscl . read /Users/username

This will dump a lot of data, some of it binary. When you look more closely at the data, you can see that the binary data is in an attribute JPEGPhoto. This is promising, but converting an image file into some binary code and writing it into the attribute does not sound fun.

When you look around the user record some more, you can find another attribute labeled Picture which contains a decent file path (it may be empty on your machine). When JPEGPhoto contains data, Picture will be ignored. But when we delete the JPEGPhoto attribute, then the system will use the file path set in the Picture attribute.

Let’s Change It!

Deleting the JPEGPhoto attribute is easy:

$ dscl . delete /Users/username JPEGPhoto

And so is setting the Picture attribute to a new value:

$ dscl . create /Users/username Picture "/Library/User Pictures/Flowers/Sunflower.tif"

With this you can create a script that resets all user pictures by looping through all the available pictures in the /Library/User Pictures folder.

(Since you are affecting other users’ records, this script needs to be run as root.)

Custom Images

Of course, you don’t have to use the pre-installed User Picture images, but can install your own.

To demonstrate how this would work, I conceived of a little fun exercise. I wanted to write a script that sets the user picture to an image from the ‘User Pictures’ folder which starts with the same letter as the username.

The set of images in the default cover 19 of the 26 letters in the latin alphabet. I created images for the seven missing letters (A, I, J, K, Q, U, and X).

To run the script at login, I created a LaunchAgent. And finally a script which will set the Picture to the appropriate path.

Since LaunchAgents run as the user, we need to be a bit more careful when changing the attributes. While a user has privileges to modify and delete the JPEGPhoto and Picture attribute, they cannot create the attributes, so our sledgehammer method to overwrite any existing value from the script above will not work.

The dscl . change verb, which modifies an attribute has a weird syntax which requires you to pass the previous value as well as the new value. To get the previous value, which may contain spaces, I use the same PlistBuddy trick from this post.

Finally, I built an installer package which installs all the parts (the additional images, the LaunchAgent plist and the script) in the right places. You can get the project here. Run the buildAlphabetUserPkg.sh script to build an installer package.

Since the LaunchAgent will trigger at a user’s login, you will have to logout and back in, before you can see any changes. You could add a postinstall script that loads the launchagent for the current user (when a user is logged in), but I will leave that as an exercise for the attentive student.

You can get all the pointers on how to build installer packages with postinstall scripts in my book: “Packaging for Apple Administrators

Weekly News Summary for Admins — 2018-10-19

We have a date for the next Apple Event: Oct 30! And it happens in Brooklyn and has hundreds of Apple logo designs. (Seriously, keep reloading the event page, it’s awesome.)

Will it be iPad Pro? Macs? Both?

Also, Adobe is showing off the new Photoshop for iPad. Some news on the new Adobe CC 2019 affects the Cloud Packaging tool.

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.)

On Scripting OS X

News and Opinion

Adobe CC 2019

MacAdmins on Twitter

  • Steve Yuroff: “Today I find myself wondering why the MDM is not notified when the user approves UAMDM. I have things for the MDM to do once the approval is made… let’s get on it.”
  • Adam Langley: “Apple, Google, Microsoft, and Mozilla today jointly announced a timeline for the removal of TLS 1.0 and 1.1 from their respective browsers.” (Links in tweet)
  • Adam Codega: “@gregneagle built the best way to install/update Mac software @Contains_ENG helps fill Apple’s MDM gaps @rtrouton documents it all and makes some cool utilities @ftiff makes DEP look nice…” (read the thread)
  • Brian Stucki:
    “A happy fourth birthday to this little guy today. Old enough to start preschool. But seriously, can’t wait to meet your younger sibling.” (Happy Birthday, Mac mini!)
  • William Lam: “FYI – @Apple MacOS Mojave (10.14) is now officially supported on vSphere 6.7u1, 6.7, 6.5u1, 6.5u2 & 6.5”
  • Sacrilicious: “In tribute to @Morpheus______ ‘s ‘liberal’ take on pronunciation, I propose we rebrand anything with ctl as a suffix ‘cuddle’, and anything w/suffix ‘util’ as ‘uddle’. e.g. launchctl, ‘launch cuddle’ ‘sysadmin cuddle’ scuddle discuddle fontuddle assetk’shuddle H-duddle”
  • Tim Perfitt: “Filed this bug about feedback for bugs. I get the irony.”

Support and HowTos

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!

EraseInstall Application

The consulting team at Pro Warehouse has been working on an application. I mentioned this application in my talk at MacSysAdmin. The application is called ‘EraseInstall’ and provides a user interface which runs the startosinstall --eraseinstall command, which is part of the macOS Installer application.

Why?

The startosinstall --eraseinstall command with all its options is fairly accessible for an administrator. There have been some attempts to make the command more accessible to end users.

With Mojave, Apple is enforcing the requirement to have an active internet connection before you start the installation. The startosinstall command will fail if it cannot reach Apple’s servers. Also on Secure Boot Macs, you really want a user to have Find My Mac disabled before a system is wiped.

We chose to build an application with an interface that runs the necessary checks and displays a summary, before the startosinstall --eraseinstall is launched.

This will provide end users, techs and admins easy access to a tool which wipes the system. This will close the lifecycle loop of a Mac, from on-boarding to ‘off-boarding.’

Enter EraseInstall

EraseInstall will show three screens, the first will explain what the application does (wipe everything!) and then you will get a summary of the checks. In this initial version we check whether the system has APFS, if Find My Mac is enabled and if there is an internet connection.

EraseInstall also locates a suitable “Install macOS” application, either “Install macOS High Sierra” for 10.13.4 and higher or “Install macOS Mojave.” It is your responsibility to have the install app on the system before the EraseInstall is run. The app does not have to be installed in /Applications. (EraseInstall uses a spotlight query to locate available installer applications. It may take a few minutes after an installer app has been copied to a system for spotlight to pick it up.)

WARNING: the app as we have posted it is fully functional and will erase and install the system on which it is run. Please only run this on a test machine!

You can watch a video of the installation and workflow here:

How to get it

You can download an installer and the source code for the EraseInstall application here.

The installer will put the EraseInstall.app in /Applications/Utilities/.

You need to install, copy or download the “Install macOS” application (for 10.13.4 or higher) through your management system, VPP or manually.

Weekly News Summary for Admins — 2018-10-12

There seems to be some “conference hangover” this week. Or maybe it was because I was distracted by the Jamf 400 course I attended.

So enjoy the quiet week. If you think I missed anything important, send it to me and I will include it next week!

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

MacSysAdmin

See all the session videos and get the slides on the MacSysAdmin page. (free registration required)

MacAdmins on Twitter

Support and HowTos

Scripting and Automation

Apple Support

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

This newsletter is a bit late. The excuse for this is that I was attending (and speaking at) MacSysAdmin in Gothenburg all week.

Usually I gather the links to the speakers’ notes and slides. But for MacSysAdmin I don’t need to, because the event team has already gathered all those together with the session videos (!) on their website (free registration required, so worth it). The video team would have the session videos on the site within an hour. This puts them at two or three orders of magnitude faster than other conferences.

You can find the link to my session video, slides and links here. But take time to browse and watch the other sessions. MacSysAdmin has a very impressive list of high quality speakers and it is an honor to be among them.

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.)

On Scripting OS X

News and Opinion

MacAdmins on Twitter

  • MacDeployment YYC: “Dates for 2019 #MacAdmins & Consultants Conferences announced so far: @macaduk March 26–29 (London) @acesconf June 4–6 (Kansas City) #MacDeploy June 10–11 (Calgary) @MacDevOpsYVR June 12–14 (Vancouver) @psumacconf July 9–12 (State College) #MacSysAdmin Oct. 1–4 (Göteborg)”
  • Keir Thomas:
    “Mojave trick. Cmd+plus or cmd+minus (the two keys left of the backspace key) will shrink or enlarge icons on the desktop, or in icon, list and gallery views of Finder.”
  • Erik Gomez: “In just three hours, we enrolled more macOS devices than I had at my entire last job. …and they had thousands of macs”
  • Chris Espinosa: “On this day 25 years ago, Apple introduced AppleScript, a system and application automation system and language. It’s still shipping in Mojave and is one of the oldest code bases in continual use in macOS. Happy birthday, AppleScript!”

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!