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:
if [ -d /Volumes/XYZ ];
echo “Ejecting XYZ!”;
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">
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.