To create an auto-run macOS service that monitors the connection of your Stream Deck MK.2 and runs the Stream Deck app when the device is connected, you can use a launchd
user agent. Here's how to set it up:
- Create a new script
monitor_stream_deck.sh
in your home directory:
nano ~/monitor_stream_deck.sh
- Paste the following script into the file:
#!/bin/bash
# Replace this with the correct path to the Stream Deck app
STREAMDECK_APP_PATH="/Applications/Elgato Stream Deck.app"
DEVICE_NAME="Stream Deck MK.2"
while true; do
DEVICE_FOUND=$(system_profiler SPUSBDataType -xml | xmllint --xpath "//string[text()='$DEVICE_NAME']" - 2>/dev/null)
if [ -n "$DEVICE_FOUND" ]; then
open -a "$STREAMDECK_APP_PATH"
while [ -n "$DEVICE_FOUND" ]; do
sleep 5
DEVICE_FOUND=$(system_profiler SPUSBDataType -xml | xmllint --xpath "//string[text()='$DEVICE_NAME']" - 2>/dev/null)
done
osascript -e 'quit app "Stream Deck"' >/dev/null 2>&1
fi
sleep 5
done
- Make the script executable:
chmod +x ~/monitor_stream_deck.sh
- Create a new
launchd
user agent plist file:
nano ~/Library/LaunchAgents/com.user.monitor_stream_deck.plist
- Paste the following plist configuration into the file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.user.monitor_stream_deck</string>
<key>ProgramArguments</key>
<array>
<string>/bin/bash</string>
<string>/Users/your_username/monitor_stream_deck.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<false/>
</dict>
</plist>
Replace your_username
with your actual username.
- Load the user agent:
launchctl load ~/Library/LaunchAgents/com.user.monitor_stream_deck.plist
The script will now run automatically when you log in to your macOS user account. It will keep checking for the Stream Deck MK.2 connection every 5 seconds. Once connected, it will launch the Stream Deck app and stop checking.
To unload the user agent, use the following command:
launchctl unload ~/Library/LaunchAgents/com.user.monitor_stream_deck.plist