Swif allows you to run flexible MDM command scripts across multiple devices by using Extension Attribute Placeholders. Instead of hardcoding values or creating separate scripts for every device, you can use placeholders that Swif automatically resolves at execution time using each device's unique metadata.
Overview
When you execute a script, Swif looks for placeholders (e.g., {{SUDO_PASSWORD}}) and replaces them with the actual values stored in that device's extension attributes.
This is particularly useful for:
Deploying unique configuration files (like WireGuard or VPN configs).
Passing device-specific passwords or tokens.
Customizing scripts based on hardware specs or ownership.
Prerequisites
Extension Attributes: You must have extension attributes defined and populated for your target devices.
MDM Access: Permissions to create and run MDM command templates.
How to Set Up Placeholders
Step 1: Define Your Placeholders
In your shell script, use the double-curly brace syntax {{ATTRIBUTE_NAME}} to represent the value you want to inject.
Example Script:
# A script to set a unique asset tag on the device
echo "Setting asset tag to {{ASSET_TAG}}"
/usr/local/bin/my-tool --set-tag {{ASSET_TAG}}
Step 2: Populate Device Attributes
Ensure the devices you are targeting have the corresponding attribute set. For example, if your script uses {{ASSET_TAG}}, Device A might have ASSET_TAG: "SWIF-001" and Device B might have ASSET_TAG: "SWIF-002".
Step 3: Execute the Command
When you run the command via the Swif dashboard or API, the backend automatically fetches the deviceContexts for each target device.
Device A will execute:
echo "Setting asset tag to SWIF-001"Device B will execute:
echo "Setting asset tag to SWIF-002"Devices without the attribute will retain the literal placeholder string
{{ASSET_TAG}}to prevent accidental execution with empty values.
Advanced Usage: WireGuard Example
A common use case is deploying WireGuard configurations where each device requires a unique PrivateKey.
Command Template Script:
cat <<EOF > /etc/wireguard/wg0.conf
[Interface]
PrivateKey = {{WG_PRIVATE_KEY}}
Address = 10.0.0.2/32
DNS = 1.1.1.1
EOF
By setting the WG_PRIVATE_KEY extension attribute for each device, you can deploy this single template to your entire fleet securely.
Verification
To verify that your placeholders are resolving correctly:
Run a simple test script:
echo "{{YOUR_ATTRIBUTE}}"Check the Command Logs in the Swif dashboard.
The output should show the resolved value (e.g.,
Hello World) rather than the placeholder brackets.
Tips
Case Sensitivity: Ensure the placeholder name in your script matches the extension attribute key exactly.
Default Behavior: If a device does not have the specified attribute, the placeholder will not be replaced. Always verify your device metadata before running critical scripts.