I did something similar once upon a time, where whenever a drive named a certain way was mounted, a script immediately fired off to sync the contents of a set of folders to the drive.
To do something similar here, the script would need to look like this:
#!/bin/bash
if [ -d /Volumes/XYZ ];
then
echo “Ejecting XYZ!”;
umount /Volumes/XYZ
exit;
fi
Save it somewhere, your ~/bin/ directory if you have one, or maybe ~/Library/Scripts/, just remember where.
The second piece of the puzzle is the LaunchAgent that will actually handle the event whenever a drive is mounted:
<?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.superuser.226504.example</string>
<key>ProgramArguments</key>
<array>
<string>/Path/To/Script/unmount-modem.sh</string>
</array>
<key>QueueDirectories</key>
<array/>
<key>StartOnMount</key>
<true/>
<key>WatchPaths</key>
<array/>
</dict>
</plist>
That needs to be saved as a .plist (named similar to the string used in place of “com.superuser.226504.example”) and saved to ~/Library/LaunchAgents. You can either load it from the terminal via launchctl load ~/Library/LaunchAgents/pathtoplist or log out / log back in and it should get loaded if everything is configured properly.