Executing Scripts for Mac management

5 min read

by Mosyle Team


Executing Scripts for Mac management

When managing devices at a company, it’s often the case that IT teams are managing an entire fleet of Mac computers. There are many ways to streamline certain processes for device management that save time and allow admins to have greater control over the whole fleet. One of those ways is running scripts or custom commands.

In this article, we’ll go over what it means to run scripts, requirements for executing scripts and some tips that’ll help you run scripts smoothly. We’ll also share a few scenarios in which scripting can be used and some basic operations to get you more familiar with custom commands.

What is scripting for Mac computers?

Scripting is a type of programming language that allows you to automate certain processes. With scripts, you can complete a number of commands, such as shutting down/restarting a device, installing updates and more. On Mac computers, you can execute scripts using the Terminal app command prompt located in the Utilities folder.

There are thousands of possibilities when it comes to the types of scripts you can run because scripts allow admins to run system level configurations. These commands can help IT teams streamline workflows and elevate Mac management to the next level.

How scripting can help admins manage Mac computers?

As mentioned earlier, you can essentially execute scripts for configuring any settings or system level configurations on specific Mac computers, but there are advantages to scripting for admins that have a fleet of devices. For example, running scripts is also a way to install apps/software on Mac computers. Scripting can make certain necessary processes automated, and when using a mobile device management (MDM) solution, can make applying these commands easier.

Scripting for Apple device management allows Mac admins to use custom commands to manage devices at the system level, which is the deepest level of management. With that being said, make sure to be careful when using scripts as not to cause damage to the Mac computers.

MDM solutions like Mosyle Business give you the ability to send custom commands to your entire fleet of Mac computers in bulk, saving you time and effort.

Requirements for running scripts

There are certain suggestions for scripting that can help you based on the scenario. In general, we recommend that scripts are in the Bash (.sh) or AppleScript (.applescript) format if you’re running scripts using Mosyle Business, the Apple device management for Enterprise. To further help you get started with scripting, below are some scenarios in which scripts can be used to automate processes:

I. Inventory for local users

dscl . list /Users | grep -v '_'

This script is used to check if users have been given the correct permissions and have not been given administrator access. Running this custom command helps IT teams know if users have to be demoted back to standard users.

II. Check signature of package file. If it's not signed, it won't be installed on the DEP workflow.

pkgutil --check-signature %name of the file%.pkg

This script helps ensure that the package file you’ve downloaded is the same one that you want to install. If the package download has a different signature, that can mean that it was swapped or the download has failed.

III. Testing network in the case of downloading files from cloud (CDN)

Testing the network is a way to check if the device can reach the CDN and ensure that the firewall or web filters are not interfering with the download.

1st command: cd Downloads/

2nd command: curl -O %name of the file.%format file %URL of download%

In the case of using the Mosyle CDN, you should /cdn mosyle at the end of the second command.

IV. Other basic scripts for getting started

If you’re just getting started with scripting, you can test these scripts for basic operations on Mac computers:

Verify Updates: sudo softwareupdate -l

Install pending Updates: sudo softwareupdate -ia

Shutdown Mac: sudo shutdown -h now

Restart Mac: sudo shutdown -r now

Restart Mac within one hour: sudo shutdown -r +60

Tips for Running Scripts for managing macOS devices

Sending custom commands to an entire fleet of Mac computers is a substantial task. If not done properly, the devices can be damaged. That’s why we recommend testing your scripts before sending them. Mosyle Business offers a test panel where you can remotely test your scripts on one of your Mac devices. This way, you can make sure everything is running smoothly before sending the custom commands.

Keep in mind that certain scripts must be run at the user level or system level, so it’s best to make sure that the script is being run at the correct permission level.

When running so many different custom commands on your Apple devices, keeping them organized can be difficult. Using an MDM solution gives you the added benefit of keeping your many scripts and responses organized. You can even create criteria-specific device groups in Mosyle Business to send groups to specific Mac computers.

Ready to try out Mosyle Business? Sign up for a free 30-day trial today!