Overview:
Wallpaper setups may be time-consuming, especially when an administrator is required to make the change on several devices. As a result, we at Addigy decided to make the procedure a little easier by offering a variety of alternatives based on your operating system.
This post will go over the numerous custom scripts that may be executed on your device to change the wallpaper. The script will report back all the devices that fall within your defined policy (report back Device Name and Agent ID), interpret the results, and conduct the API Request for the wallpaper change.
The scripts discussed in this article are attached in the footer.
------------------------------------------------------------------------------------------------------
General Requirements:
- iOS and iPadOS Supervised Devices
- Requires iOS 8.0+
- Requires Addigy MDM
- Desired wallpaper encoded as a base64 image
- Base64 Converter - Base64-Image-Converter
- An Addigy API V1 Client ID and Client Secret
- Policy ID of the Policy the command will be sent to
------------------------------------------------------------------------------------------------------
Applying the Wallpaper in Python:
Script Requirements:
-
Python Script
-
MacOS Operating system:
- This will require the Python Interpreter from the Homebrew Library:
- Install Homebrew into your macOS - HomeBrew Installation (if installed, skip this)
Once homebrew is installed, Installpython3
with Homebrew (if installed, skip this):brew install python
- Once installed, Confirm the
python3
version with the following command:python3 --version
- Once you have the interpreter installed, we recommend downloading an IDE (Integrated development environment) to perform the editing process and execution of the script. (Example: Visual Studio Code Download)
- Install Homebrew into your macOS - HomeBrew Installation (if installed, skip this)
- This will require the Python Interpreter from the Homebrew Library:
-
Windows Operating system:
- This will require the Python Interpreter from the Python website:
- Install the Python Interpreter from the Website - Python Download
- Once installed, Confirm the
python
version with the following command:python --version
- Once you have the interpreter installed, we recommend downloading an IDE (Integrated development environment) to perform the editing process and execution of the script. (Example: Visual Studio Code Download)
- This will require the Python Interpreter from the Python website:
-
MacOS Operating system:
Once the script requirement has been met, you can successfully open the Python file in your IDE and configure all the necessary steps like:
-
- Provide the Client ID and Secret
- Policy ID (Where your devices are being enrolled)
- Set Location for Background image (Values: 1 = Lock Screen 2 = Home Screen 3 = Both)
- By default, it will be set to 3 for both the home screen and lock screen!
- Copy the Base64 equivalent code from the base64 Converter into the base_64_image variable.
- Once added, you should be good to go in executing the Python script - How to run Python code in Visual Studio Code!
Python Script:
# Python Libraries
import time
import requests
# Author: Charles Jiron
# iOS Wallpaper Change via Python Script
# API credentials
client_id="PASTE YOUR OWN CLIENT ID"
client_secret="PASTE YOUR OWN CLIENT SECRET"
# Policy ID
policy_id="PASTE YOUR OWN POLICY ID"
# Where to set the background
# Values: 1= Lock Screen 2= Home Screen 3= Both
location=3
# Get the base 64 Image
base_64_image = "PASTE THE BASE 64 EQUIVALENT CODE"
# Get policy devices API URL
devices_url = (
f"https://prod.addigy.com/api/policies/devices?policy_id={policy_id}&client_id={client_id}&client_secret="
f"{client_secret}")
# Fetch devices Info
response = requests.get(devices_url)
devices = response.json()
# Extract Agent IDs and Device Names
agents = [device["agentid"] for device in devices if device["Device Model Name"] in ["iPhone", "iPad"]]
device_name = [device["Device Name"] for device in devices]
# Device Name counter:
i = 0
# Enqueue wallpaper
for agent_id in agents:
# Set wallpaper API URL
wallpaper_url = f"https://prod.addigy.com/api/mdm/settings?agent_id={agent_id}"
# Enqueuing Wallpaper command and outputting both the Agent ID and Device Name!
print(f"\nEnqueuing wallpaper command for Agent: {agent_id} & Device Name: {device_name[i]}")
data = {
"Wallpaper": {
"Image": base_64_image,
"Where": location
}
}
headers = {
"client-id": client_id,
"client-secret": client_secret
}
response_wallpaper = requests.post(wallpaper_url, json=data, headers=headers)
# Check the response
if response_wallpaper.status_code == 200:
print("Message sent successfully!")
time.sleep(4)
print(f"Wallpaper Change:\nDevice Name: {device_name[i]}\nAgent ID: {agent_id}")
i +=1
else:
print(f"Message sending failed. Response: {response.text}")
------------------------------------------------------------------------------------------------------
Applying the Wallpaper in Bash:
Script Requirements:
- Bash:
-
-
MacOS Operating System:
- Bash was the default shell in macOS, so an interpreter is not needed since the macOS should have one integrated with it.
- This will also require a particular library or tool called
jq
for JSON parsing that would have to be installed with Homebrew:- Install Homebrew into your macOS - HomeBrew Installation (if installed, skip this)
- Once Homebrew is installed, Install
jq
tool with Homebrew (if Installed, skip this)
brew install jq
-
After installation, you can verify that
jq
is installed by running:jq --version
-
MacOS Operating System:
-
Once the script requirement has been met and downloaded, you can successfully open the shell file in your IDE or TextEdit and configure all the necessary steps:
-
- Provide the Client ID and Secret
- Policy ID (Where your devices are being enrolled)
- Set Location for Background image (Values: 1 = Lock Screen 2 = Home Screen 3 = Both)
- By default, it will be set to 3 for both the home screen and lock screen!
- Copy the Base64 equivalent code from the base64 Converter into this terminal command to create a text file:
echo "PASTE THE BASE 64 CODE" > base64_image.txt
- Note: This will make it easier for the script to call!
- Once the text file has been created, the script will be able to read it from the script itself with a concatenate command.
-
Once all configurations have been configured, kindly open your terminal or IDE Terminal (How to open terminal in Visual Studio Code) to execute the script. The script can be run by executing the following:
- Convert the script into an executable by executing the following command where the script was downloaded and saved:(chmod +x FILENAME.sh)
- Once the script has been converted to an executable, you can safely execute the script:
sudo sh FILENAME.sh
Bash Script:
#!/bin/bash
# Author: Charles Jiron
# iOS Wallpaper Change: Bash
# API credentials
client_id="PASTE YOUR OWN CLIENT ID"
client_secret="PASTE YOUR OWN CLIENT SECRET"
# Policy ID
policy_id="PASTE YOUR OWN POLICY ID"
# Where to set the background
# Values: 1= Lock Screen 2= Home Screen 3= Both
location=3
# Read the Base64 image from the file into a variable
base_64_image=$(cat base64_image.txt)
# Get policy devices API URL
devices_url="https://prod.addigy.com/api/policies/devices?policy_id=${policy_id}&client_id=${client_id}&client_secret=${client_secret}"
# Fetch devices and parse JSON response
response=$(curl -s "$devices_url" | jq '.')
# Extract agent IDs and device names using jq
agents=($(echo "$response" | jq -r '.[] | select(.["Device Model Name"] | contains("iPhone") or contains("iPad")) | .agentid'))
device_names=($(echo "$response" | jq -r '.[].["Device Name"]'))
# Device Name counter
i=0
# Enqueue wallpaper for each agent
for agent_id in "${agents[@]}"; do
# Device name Output for each Agent ID
device_name="${device_names[i]}"
# set wallpaper API url
wallpaper_url="https://prod.addigy.com/api/mdm/settings?agent_id=$agent_id"
# Enqueing Wallpaper and outputting the Agent ID and Device Name
echo "Enqueuing wallpaper command for agent $agent_id & $device_name"
# Send POST request to change wallpaper using a here document
response=$(curl --request POST "$wallpaper_url" \
--header "client-id: $client_id" \
--header "client-secret: $client_secret" \
--data-raw "{
\"Wallpaper\": {
\"Image\": \"$base_64_image\",
\"Where\": $location
}
}")
# Checking for any curl request failures
if [[ $? -ne 0 ]]; then
echo "Error: curl request failed"
exit 1
fi
# Check the response for errors (if applicable)
if [[ "$response" == *"error"* ]]; then
echo "Error in response: $response"
exit 1
else
echo "Executing......"
sleep 4
echo "\nWallpaper Change Script Executed:"
echo "Device Name: $device_name"
echo "Agent ID: $agent_id\n"
i=$((i+1))
fi
done
------------------------------------------------------------------------------------------------------
Applying the Wallpaper in Powershell:
Script Requirements:
- PowerShell:
-
-
MacOS Operating System:
- Powershell is native to the Windows Operating system, so we would need to install the scripting language with HomeBrew for macOS devices:
- Install Homebrew into your macOS - HomeBrew Installation (if installed, skip this)
- Once Homebrew is installed, Install
PowerShell
tool with Homebrew (if Installed, skip this) - Microsoft HomeBrew PowerShell Downloadbrew install --cask powershell
-
After installation, you can verify that
PowerShell
is installed by running:pwsh
- After the verification, type exit and it will exit you out of the PowerShell interpreter.
- Next, comes the process of Installing the PowerShell Extension in Visual Studio Code.
- Launch the VS Code app.
- The Extensions view opens on the Side Bar. Select the PowerShell extension from Microsoft.
- Click the Install button on the PowerShell extension from Microsoft.
- After the installation, if you see the Install button turn into Reload, Click on Reload.
- After VS Code has reloaded, you're ready for editing.
- Powershell is native to the Windows Operating system, so we would need to install the scripting language with HomeBrew for macOS devices:
-
MacOS Operating System:
-
Once the script requirement has been met, you can successfully open the Python file in your IDE and configure all the necessary steps like:
-
- Provide the Client ID and Secret
- Policy ID (Where your devices are being enrolled)
- Set Location for Background image (Values: 1 = Lock Screen 2 = Home Screen 3 = Both)
- By default, it will be set to 3 for both the home screen and lock screen!
- Copy the Base64 equivalent code from the base64 Converter into the base_64_image variable.
- Once added, you should be good to go in executing the Python script - How to run PowerShell on Visual Studio Code!
PowerShell Script:
# PowerShell------------------------------------------------------------------------------------------------------
# Author: Charles Jiron
# Wallpaper iOS Wallpaper Change
# Header Call
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Cookie", "Cookie_1=value")
# API credentials
$client_id = "PASTE YOUR OWN CLIENT ID"
$client_secret = "PASTE YOUR OWN CLIENT SECRET"
# Policy ID
$policy_id = "PASTE YOUR OWN POLICY ID"
# Where to set the background
# Values: 1 = Lock Screen, 2 = Home Screen, 3 = Both
$location = 3
# Get the base 64 Image
$base_64_image = "PASTE YOUR OWN BASE 64 CODE"
# Get policy devices API URL
$devices_url = "https://prod.addigy.com/api/policies/devices?policy_id=$policy_id&client_id=$client_id&client_secret=$client_secret"
# Fetch devices Info
$response = Invoke-RestMethod -Uri $devices_url -Method Get
$devices = $response
# Extract Agent IDs and Device Names
$agents = $devices | Where-Object { $_."Device Model Name" -in @("iPhone", "iPad") } | ForEach-Object { $_.agentid }
$device_names = $devices | ForEach-Object { $_."Device Name" }
# Device Name counter:
$i = 0
# Enqueue wallpaper
foreach ($agent_id in $agents) {
# Set wallpaper API URL
$wallpaper_url = "https://prod.addigy.com/api/mdm/settings?agent_id=$agent_id"
# Enqueuing wallpaper command for Agent ID and Device Name
Write-Host "`nEnqueuing wallpaper command for Agent: $agent_id & Device Name: $($device_names[$i])"
$data = @{
Wallpaper = @{
Image = $base_64_image
Where = $location
}
}
$headers = @{
"client-id" = $client_id
"client-secret" = $client_secret
}
# Send request to change wallpaper
Invoke-RestMethod -Uri $wallpaper_url -Method Post -Headers $headers -Body ($data | ConvertTo-Json)
Start-Sleep -Seconds 4
Write-Host "Wallpaper Change:`nDevice Name: $($device_names[$i])`nAgent ID: $agent_id"
$i++
}
Additional Information
- The script must be used carefully as it will set the wallpaper on all iOS Devices within your specified policy.
- The script will contain your API keys, so do not share them publicly.