Skip to main content

Deploying a Script to a Mac using Jamf Now

Updated over 2 weeks ago

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

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

      This photo shows an example of where to drag your app within Composer.

  2. Right click all the items in the source and delete them.

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

      This photo shows how you should now see your package source.

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

    This photo shows an example of what you may see when you git the arrow next to your package name.

  5. Place the commands you would like to run under the script variables, ensuring not to remove any items that were already there.

    This photo shows an example of what you may place your commands.

  6. Save your changes to the package script using File > Save.

  7. Click Build as PKG and follow Building and Signing Mac Packages to ensure the package is signed. it's signed following our requirements.

  8. Upload the package to Jamf Now following the steps below:

    1. Click Apps and click + Add an App in the upper-left corner.

    2. Click Upload Your App.

    3. Drag and drop the package or click Browse to upload the package.

  9. To add the app to a blueprint:

    1. Click Blueprints.

    2. Click Apps under the Blueprint name in the middle column.

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

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

      This photo shows where to correctly place your .sh file into the directory.

  2. Drag the script file from Finder into the Sources section of Composer's sidebar to capture its location.

    This photo shows where you should correctly drag your script file into Composers sidebar.

  3. Expand the package contents, right click Scripts and add a postinstall script.

    This photo shows where you are able to add a postinstall script.

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

    This photo shows the example command put into the path to match the script name and location.

  5. Save your changes to the package script using File > Save.

  6. Click Build as PKG and follow Building and Signing Mac Packages to ensure the package is signed. it's signed following our requirements.

  7. Upload the package to Jamf Now following the steps below:

    1. Click Apps and click + Add an App in the upper-left corner.

    2. Click Upload Your App.

    3. Drag and drop the package or click Browse to upload the package.

  8. To add the app to a blueprint:

    1. Click Blueprints.

    2. Click Apps under the Blueprint name in the middle column.

    3. Check the boxes for how you want the package to install - Automatically and/or display in Self Service.

Did this answer your question?