Last active
August 29, 2015 14:23
-
-
Save mveinot/c194d9cbc366144ed62d to your computer and use it in GitHub Desktop.
Look for a specified USB device
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Specify the product ID of your device | |
DEVICE="0x2838" | |
# the command to list USB devices | |
USB_DEVICE_CMD="system_profiler SPUSBDataType" | |
# get the list and filter for the device we're looking for | |
DEVICE_PRESENT=`$USB_DEVICE_CMD | grep $DEVICE | cut -f2 -d':'` | |
if [ "$DEVICE_PRESENT" == " $DEVICE" ]; then | |
# Do things in this section if the device is found | |
echo "Device found" | |
else | |
# Do the things in this section when it's missing | |
echo "Device removed!" | |
say "Alert! Device has been removed" | |
#afplay /path/to/some/sound.mp3 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment