Description
Jamf Now does not have a built in mechanism for deploying scripts or Terminal commands to devices. This article provides two solutions for building packages using Composer in order to deploy a script from Jamf Now.
Important notes:
The workflow below requires being able to sign a package. Building and signing a package to be deployed to Macs will require an Apple Developer Account.
Jamf Now cannot remotely remove a script that has been deployed. Always test scripts before deploying to a group of Macs to confirm the script works as desired.
Building Packages using Composer
We can create a package containing the script using Composer following one of the methods below.
Option 1: Deploying the script as a postinstall script
Drag an app, package or any item to the left column in Composer to Create a placeholder package source we'll modify to create our script.
This example is using Safari, but it doesn't matter what this item is as we'll delete it then use the package source to build off of. Something from Applications is good or an existing package can be duplicated.
Right click all the items in the source and delete them.
Right click the package name and rename it to something more appropriate for what the script will do.
Notice below, the package source is now empty and has been renamed Chrome_Install as that's what the script will do.
Select the arrow next to the package name to expand it, then right click the Scripts option to choose the script type. The example below was postinstall under Add Shell Script.
Place the commands you would like to run under the script variables, ensuring not to remove any items that were already there.
Save your changes to the package script using File > Save.
Click Build as PKG and follow Building and Signing Mac Packages to ensure the package is signed. it's signed following our requirements.
Upload the package to Jamf Now following the steps below:
Click Apps and click + Add an App in the upper-left corner.
Click Upload Your App.
Drag and drop the package or click Browse to upload the package.
To add the app to a blueprint:
Click Blueprints.
Click Apps under the Blueprint name in the middle column.
Check the boxes for how you want the package to install - Automatically and/or display in Self Service.
Option 2: Deploying a ".sh" file and deploying the script
If the script is more complex than a few lines or you already have a .sh file to deploy, we can package the file with Composer to install onto the machine and use a postinstall script to run the script file.
Place the .sh file into the directory you would like the script to be in on the managed Macs.
This can really be anywhere, but /private/tmp/ works well because if this is a hidden directory and plus items in the /tmp/ directory get deleted at the next reboot.
Drag the script file from Finder into the Sources section of Composer's sidebar to capture its location.
Expand the package contents, right click Scripts and add a postinstall script.
Add a command to the postinstall script to run the script file after it's deployed, using the format below:
sh /path/to/script/filename.sh
Adjust the path to match your script name and location. In this example the file is in /private/tmp/ so the command would be
sh /private/tmp/installChrome.sh
Save your changes to the package script using File > Save.
Click Build as PKG and follow Building and Signing Mac Packages to ensure the package is signed. it's signed following our requirements.
Upload the package to Jamf Now following the steps below:
Click Apps and click + Add an App in the upper-left corner.
Click Upload Your App.
Drag and drop the package or click Browse to upload the package.
To add the app to a blueprint:
Click Blueprints.
Click Apps under the Blueprint name in the middle column.
Check the boxes for how you want the package to install - Automatically and/or display in Self Service.