I'd like to run a script (removing non-OSX .* files) on a USB drive whenever that drive is ejected - is there a way to trigger a script automatically when a drive is ejected from the Finder?

To clarify: I'm looking for a way of triggering a given script before the umount command runs, i.e. immediately before the drive is ejected. I'm aiming to delete .* files and run dot_clean before a FAT drive ejects, getting rid of OSX-only invisible files that confuse Windows systems.

  • 1
    How would you run a script on a USB drive after you have ejected it?
    – duci9y
    Commented Sep 17, 2012 at 15:26
  • It would run BEFORE the drive ejects ... when the Finder starts the process of unmounting it. Presumably there is a way of running a script before umount runs.
    – Simbamangu
    Commented Sep 17, 2012 at 18:15
  • I don't believe there is anything that allows you to do that. Also, you would perhaps like to edit your question to include that the script should be run run before the drive ejects.
    – duci9y
    Commented Sep 17, 2012 at 18:23
  • There is a hack to let you do something like this - renaming umount and creating a new umount script that removes dotfiles and then calling the old umount. Will give this a try anyway.
    – Simbamangu
    Commented Sep 20, 2012 at 12:34
  • That’s great! Add that as an answer and accept it so that future visitors with the same problem know that there is a solution.
    – duci9y
    Commented Sep 20, 2012 at 12:56

1 Answer 1


There is some 3rd party software (UnDock) which allows you to run scripts when drives are ejected.

  • It doesn't seem to support that. You can only tell it to run scripts when disks are ejected manually with it.
    – Lri
    Commented Sep 18, 2012 at 12:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .