Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to automatically unmount a specific volume (mounted from a .dmg/.sparseimage) if it has not been accessed for a specified period?


  1. This would be especially useful for password protected images which contain sensitive data.

  2. Since I got no complete answer to this, I have asked a similar but simpler question here.

share|improve this question

The OS doens't allow that out of the box (neither for dmg nor real partitions).

What I would do is create a script that would listen to that mounted image and after x time idle, unmount it.

Applescript is a fairly simple way to get that working (or via an automator flow).

Some pointers:

(the tricky part is getting the disk image idle)

Checking for folder/file changes using Automator?

How to run Applescript on Disk mount

Automatically launch a program or action when an external drive or disk is connected

I'll make an example later today, but the flow will be like this:

open script

drag mounted image disk to it

monitor this disk access (every x time, to save processor)

if last time accessed > idlelimit then     
    eject disk
    quit script


keep checking
share|improve this answer
why the downvote? – jackJoe Feb 27 '13 at 9:29
Thanks, that sounds like it will do the trick. I have never used Applescript. Can you provide a code snippet or pointers on how to get started? – Himanshu Pokhariya Feb 27 '13 at 9:31
(I dunno who downvoted. I don't know enough yet to upvote or downvote your answer) – Himanshu Pokhariya Feb 27 '13 at 9:32
@HimanshuPokhariya I updated with some links that I found, to help you get started. – jackJoe Feb 27 '13 at 9:47
Thanks for doing the research on this, there is a lot of good stuff in your answer already. To make it really great and useful for a broader audience, would you be able to provide a sample script showing how to implement this in real life? – patrix Feb 27 '13 at 10:05

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.