Back to Resources
Level
Script
Security
Unregulated or unauthorized USB devices can expose macOS systems to data leaks, malware threats, and policy violations. Manually monitoring for USB connections is time-consuming and prone to oversight, leaving IT Professionals and MSPs vulnerable to unexpected security breaches.
This script uses the built-in system_profiler
command to detect any mounted USB drives on a macOS endpoint. If it finds an active USB device, it prints “ALERT,” which can be captured and reported by Level. This enables immediate visibility into unauthorized or unexpected removable media usage.
You can configure a script-based monitor in Level to trigger on-demand checks whenever USB-related activity is suspected, or set it to run on a schedule via a Level Automation. By pairing it with a remediation action, you can automatically disable or eject suspicious drives to maintain tighter security.
1#!/bin/bash
2
3# This resource is provided as a convenience for Level users. We cannot
4# guarantee it will work in all environments. Please test before deploying
5# to your production environment. We welcome contributions to our community
6# library
7
8# Level Library
9# https://level.io/library/script-macos-monitor-usb-drive
10
11# Look for USB Drives
12USB_DRIVE_PRESENT=$(system_profiler SPUSBDataType | grep "Mount Point")
13
14if [[ ! -z "$USB_DRIVE_PRESENT" ]]; then
15 # If USB drive is present, send console message for Level to alert on
16 echo "ALERT"
17fi
system_profiler
should work. Testing is advised to ensure compatibility.macOS Monitor - USB Drive
This script checks for connected USB drives on a macOS system by scanning for active mount points in the USB device information. If a USB drive is detected, it outputs an "ALERT" message to signal the presence of the device for monitoring purposes.
Bash
100
Local system
Explore more automations, scripts, and policies to further enhance your IT operations.