Goal
Learn what a script is and how it can be used. Upload a basic script to Jamf Pro and deploy it to a Mac.
Video
Key points
-
Scripts can be used to automate tasks and extend the functionality of Jamf Pro.
-
A script is a collection of commands in a single file designed to be run in a specific order.
-
The
opencommand opens files, directories, or URLs. For example:-
open https://jamf.comwill open the Jamf website in the default browser. -
open -a Chess.appwill open the Chess application.- If no application or browser is specified using the
-aflag, the system default will be used.
- If no application or browser is specified using the
-
-
The
sleepcommand suspends command execution for a period of time.-
For example,
sleep 5will pause script execution for five seconds.
-
-
Jamf binary commands can be called in scripts in the same manner as they are used in Terminal.
-
For example,
jamf displayMessage -messagewill use the jamf binary to display a message on the computer.
-
-
Scripts are run on macOS using a command-line interpreter, or shell, that is used to read and execute the commands contained within a script.
-
Every script needs to specify a command-line interpreter in the first line. The script must start with a shebang (
#!) immediately followed by the path to a specific shell.-
For example,
#!/bin/bashtells macOS to use the Bash shell to run this script.
-
-
Scripts deployed from Jamf Pro are automatically run as the root user.
-
Comments can be added to a script using a pound sign (
#).-
It is good practice to add comments throughout your script that explain what subsequent code does.
-
Review
To view answers, click arrow next to each question.
Practice
-
Create and save a new script.
-
Navigate to .
-
Click New.
-
Enter a display name of your choosing.
-
On the Script tab, paste the following:
#!/bin/sh #Open the Chess app open -a Chess.app #Wait three seconds sleep 3 #Display a message to the user jamf displayMessage -message 'Let's play Chess!' -
Click Save.
-
-
Create a new policy to make the script available in Self Service.
-
Navigate to .
-
Click New.
-
Enter a display name of your choosing.
-
In the Execution Frequency pop-up menu, select "Ongoing".
-
Select the Scripts payload and add the script created in Task 1.
-
Scope the policy to a test computer.
-
On the Self Service tab, select the Make the policy available in Self Service checkbox.
-
Save the policy to make it available in Self Service.
-
Open Self Service on the test computer and run the policy.
-
Resources
Jamf Pro Documentation
Jamf
Terminal User Guide
Apple
W3Schools.io