Page 1 of 1

Do stuff when drive is unmounted (disconnected)

PostPosted: Wed Nov 23, 2011 9:33 am
by DouweM
Hi,

Would anyone happen to know of a way to do stuff when a specific drive is unmounted (disconnected)?
I'm able to react to it being mounted (connected), by monitoring the `/Volumes/` folder with rules `Name is [Drive Name]` and `Date Added is after Date Last Matched`, but I want to execute some actions when that same drive is mounted again as well.

Any ideas?

Thanks!
—Douwe

Re: Do stuff when drive is unmounted (disconnected)

PostPosted: Wed Nov 23, 2011 1:10 pm
by Mr_Noodle
There's no way to deal with files that have disappeared at the moment. The best you can do is some script which would match some volume that is always present (like your boot drive) and then scan the folder itself and deal with any missing volumes, or something like that.

If you provide more details on what it is you are trying to do, there may be an alternate way of doing it that I can suggest.

Re: Do stuff when drive is unmounted (disconnected)

PostPosted: Wed Nov 23, 2011 1:27 pm
by DouweM
What I want to do is the following:
  • Intelligently switch between `~/Downloads` and `/Volumes/External HD/Downloads` as Safari's download folder
  • Intelligently switch between `~/Downloads` and `/Volumes/External HD/Downloads` as the source of the Downloads stack in my Dock.
I know how to realize both using shell scripts, but I don't know how to detect the unmount "event".

I take my MBP to school and work a lot, so currently this is something I need to do manually. I would love for it to be done automatically.

Re: Do stuff when drive is unmounted (disconnected)

PostPosted: Sun Nov 27, 2011 7:52 am
by DouweM
Any suggestions?

Re: Do stuff when drive is unmounted (disconnected)

PostPosted: Mon Nov 28, 2011 1:36 pm
by Mr_Noodle
Sorry, can't think of a good way to do this at the moment. Maybe look into something like Sidekick (formerly NetworkLocation) if you need to reconfigure stuff depending on your location.

Re: Do stuff when drive is unmounted (disconnected)

PostPosted: Wed Dec 07, 2011 6:01 pm
by a_freyer
With Hazel 3.0b you can do this with a passed shell script in the rule menu: ls /Volumes/ | grep "External HD"; This will match when the drive is ejected so long as the '/Volumes/' directory is monitored.

With Hazel 2.xx I'd do something like this, although I'm not sure if Hazel triggers rules on file deletion (directory/volume ejection): Rule monitoring /Volumes/ then run a script that checks the status of your downloads directory first. If the directory matches what it should be for the volumes mounted, then do nothing. Else, make the appropriate change.

If you're on SL, you can use an app I wrote called AirPort Location. Its free - http://airportlocation.wordpress.com.

Otherwise, if it were me, I'd write an Alfred script that I'd trigger when I got home.

Re: Do stuff when drive is unmounted (disconnected)

PostPosted: Thu Dec 08, 2011 5:43 pm
by sjk
a_freyer wrote:With Hazel 3.0b you can do this with a passed shell script in the rule menu: ls /Volumes/ | grep "External HD"; This will match when the drive is ejected so long as the '/Volumes/' directory is monitored.

Another way to check for the directory's existence is like this:
Code: Select all
test -d "/Volumes/name"

In Bourne-like shells, test is a built-in command so no external commands are required and this also works:
Code: Select all
[[ -d "/Volumes/name" ]]