Skip to content

Instantly share code, notes, and snippets.

@mveinot
Last active August 29, 2015 14:23
Show Gist options
  • Save mveinot/c194d9cbc366144ed62d to your computer and use it in GitHub Desktop.
Save mveinot/c194d9cbc366144ed62d to your computer and use it in GitHub Desktop.
Look for a specified USB device
#!/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