How to run scripts on Mac?
A script is a programming language used to automate the execution of certain routine or time-consuming tasks. It is a single file that contains a set of commands or instructions to streamline various processes for Mac management. With scripts, the admin can automate processes to perform specific operations, which otherwise has to be executed one-by-one on Apple’s Terminal.
Hexnode UEM allows IT admins to execute custom scripts on Mac devices remotely. The admin can run any scripts to perform system-level configurations on Mac devices without any user interaction. You can shut down/restart devices, install/uninstall apps, push updates, set up app configurations, and so forth. You can enhance Mac management to the next level by configuring extra settings that may not be natively available in MDM’s features stack.
Create and Run a Mac Script
Here, we will show you how to write a sample bash script that allows you to restart your device.
- Open Text Edit from Applications.
- Click New Document and write your script in the text area as below:123#!/bin/sh/sbin/shutdown -r now
- Now, click Format > Make Plain Text to convert the file into a plain text.
- Save the file by clicking on File > Save. Make sure to uncheck the option If no extension is provided, use ‘.txt’ while saving the file. Also, note the file name and location of the file.
- Next, navigate to the folder where you have saved the file. Right-click on the file and click Get Info. Unlock the bottom padlock present on the opened info window.
- Open Terminal and type the following:1cd (location of the script)
For example, if you have saved the file in Documents, type as follows:1cd Documents </li>
- Next, convert the file into an executable file. Type in1chmod 700 (filename)
If the file name is SampleScript, type as follows:1chmod 700 SampleScript
- Next, type in ./(filename) to restart your device. In this case, type as follows:1./SampleScript
Your device will restart once the script is executed.
Run Scripts on Mac using Hexnode UEM
To execute a custom script on Mac,
- From your Hexnode portal, navigate to Manage > Devices.
- Click on the Mac device you need to deploy scripts.
- Click Actions > Execute Custom Script.
- Specify the below parameters to execute the script on that device:
- Click the Execute button to confirm your action.
- Now, navigate to the Action History sub-tab to view the execution status of the script. You can see the output details by clicking on the Show Output button corresponding to the execution status of that script.
The script, if coded correctly, will be executed successfully to automate the specified operations on the device.