Run script when volume is mounted

Hi! Is it possible to run a script automatically when a volume is mounted? I have a USB modem that I want to connect when it is mounted. Thanks,

gecko

Hi,

unlike a flash drive or a hard disk a modem is not a volume,
therefore you can’t detect its appearance by watching the file system.

Maybe parsing IOReg periodically could help but this quite expensive

Ok… so theoretically if I wanted to run a script when a flash drive was plugged in how would I do that?

Take a look at this article

Worked like a charm. I got my launch agent plist to point at this script which connects the modem when it is plugged in.

property modem_state : 2
set trigger_file to "Internet Movil:Internet Movil.app"
tell application "Finder"
	if file trigger_file exists then
		if modem_state = 2 then
			tell application "System Events"
				tell network preferences
					connect service "HUAWEIMobile-Modem"
				end tell
			end tell
			set modem_state to 0
		end if
	else
		if modem_state = 0 then
			set modem_state to 2
		end if
	end if
end tell

Thanks Stefan, that was exactly what I was looking for.

gecko