> ## Documentation Index
> Fetch the complete documentation index at: https://docs.getprimo.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Script library

> Add, edit, download, and delete shell, Python, and PowerShell scripts you can run on macOS, Linux, and Windows devices.

The **Script library** is where you manage the scripts you can run on your fleet. Add a `.sh`, `.py`, or `.ps1` script once, then run it on any compatible device.

## Supported script types

| Extension | Platforms    | Notes                                                                                     |
| --------- | ------------ | ----------------------------------------------------------------------------------------- |
| `.sh`     | macOS, Linux | Must run under `/bin/sh`, `/bin/bash`, or `/bin/zsh`.                                     |
| `.py`     | macOS, Linux | Must start with a shebang that includes `python` (for example, `#!/usr/bin/env python3`). |
| `.ps1`    | Windows      | Runs in PowerShell.                                                                       |

Each script is limited to **1 MiB** of content.

## Open the Script library

<Steps>
  <Step title="Open Device Management">
    From the dashboard, open **Device Management**.
  </Step>

  <Step title="Go to the Scripts tab">
    Select the **Scripts** tab.
  </Step>

  <Step title="Select the Script library sub-tab">
    You see one row per script with its name, type, and available actions.
  </Step>
</Steps>

## Add a script

<Steps>
  <Step title="Open the form">
    Select **Add a script**.
  </Step>

  <Step title="Provide the script">
    Choose one of two ways:

    * **Drag and drop** a `.sh`, `.py`, or `.ps1` file into the upload area. The form fills in the name, platform, and contents for you.
    * **Fill in the fields manually**: pick a platform, enter a name ending in the matching extension, and paste the script into the editor.
  </Step>

  <Step title="Save the script">
    Select **Save**.
  </Step>
</Steps>

<Tip>
  The **Platform** selector owns the extension. Switching platforms rewrites the extension in the name, and typing a name with a matching trailing extension updates the platform. You can edit either field freely — they stay in sync only when the other field is unambiguous.
</Tip>

### Validation rules

Before saving, Primo checks that:

* The name ends in a supported extension (`.sh`, `.py`, or `.ps1`).

* The contents are 1 MiB or smaller.

* A `.py` script starts with a `python` shebang, for example:

  ```python theme={null}
  #!/usr/bin/env python3
  print("Hello from Primo")
  ```

* A `.sh` script uses a supported interpreter if it declares a shebang, for example `#!/bin/bash` or `#!/usr/bin/env bash`.

If a rule fails, **Save** stays disabled and the offending field shows the reason.

## Edit a script

<Steps>
  <Step title="Open the edit form">
    On the script's row, open the actions menu and select **Edit**.
  </Step>

  <Step title="Update the contents">
    Edit the script in the editor.
  </Step>

  <Step title="Save your changes">
    Select **Save**.
  </Step>
</Steps>

You can only edit the **contents**. The **name** and **platform** stay locked, because renaming would change the script's type. To rename a script or change its type, delete it and create a new one.

<Note>
  **Save** stays disabled until you change the contents.
</Note>

## Download a script

On the script's row, open the actions menu and select **Download**. The file downloads with the script's original name and extension.

## Delete a script

<Steps>
  <Step title="Open the delete dialog">
    On the script's row, open the actions menu and select **Delete**.
  </Step>

  <Step title="Confirm">
    Confirm in the dialog.
  </Step>
</Steps>

Past runs of the script remain in each device's script history — Primo keeps the name and contents used at run time. Any run that hadn't completed yet moves to **cancelled**.

## Permissions

| Action                              | Required permission |
| ----------------------------------- | ------------------- |
| View the library, download a script | `MDM_READ`          |
| Add, edit, or delete a script       | `MDM_WRITE`         |

If you're missing a permission, the action stays visible but disabled and a tooltip explains why. In a **demo workspace**, only the confirm buttons in the modals are disabled — you can still open a script to read it.
