PDA

View Full Version : Applescript before / on unmount


sussdorff
05-05-2007, 07:07 AM
Is it technically possible, if I use the eject button to eject an external harddisk, that an apple script is executed so I can run a command to stop the daemon accessing the external harddisk?

Here is why:

I have a larger postgres database which I did not want to clubber my harddisk on the MBP, so I put the whole database on the external harddisk. So far so good.

Sadly, if I remove the harddisk using the eject button, I forget to shutdown postgres as well. And the pg database daemon acts very unhappy that his file system was taken away while it was still running.

So my idea is to trigger a script whenever I eject this harddisk, to first shut down the daemon (and maybe stop any running parallels sessions, as they run of the external disk as well) and then run the "unmount".

Hoping this is the right place to ask, if I should ask in the developers forum, please accept my apologies and maybe an admin can move it over there?

giskard22
05-05-2007, 12:50 PM
I'm a little surprised that you're able to do an eject at all. If a volume has open files on it, the OS should refuse to unmount it.

How are you "ejecting" the HD? Dragging its icon to the Trash in the Finder?

tw
05-05-2007, 01:55 PM
I'm a little surprised that you're able to do an eject at all. If a volume has open files on it, the OS should refuse to unmount it.


giskard: postgres isn't an open file in that way (through the finder). it's more of a web-accessed thing, so the Finder doesn't even know it's active, and won't take any steps to protect it.

sussdorf: I think there's a way to run scripts at unmount, but I'm suspicious of it, so I have a couple of alternate suggestions.

1) create a script that shuts down postgres first and then unmounts the drive, and then never unmount the drive manually, always use the script.

2) create an applescript stay-open application, put it on the hard drive, and run it - that way when you try to unmount the hard drive, the Finder will see the open application, and give you the normal "you can not unmount this drive error", and maybe even trigger the script to shutdown postgres and quit.

sussdorff
05-05-2007, 02:06 PM
tw: Thanks, I assume that will be safer (with the script and not unmount manually)

giskard22: In principle you are right, sadly not in this particular case. I took your advise though and put the *binaries* of postgres also on the remote disk. And voila. it works, I cannot unmount the harddisk.