8

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?

EDIT:

  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.

Himanshu P
  • 3,432

1 Answers1

1

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)

http://www.mactech.com/articles/mactech/Vol.20/20.07/FolderWatching/index.html

http://webcache.googleusercontent.com/search?q=cache:IjvM1V_MxroJ:macscripter.net/viewtopic.php%3Fid%3D39468+&cd=4&hl=en&ct=clnk&client=safari

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

otherwise

keep checking
jackJoe
  • 658
  • why the downvote? – jackJoe Feb 27 '13 at 09: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 P Feb 27 '13 at 09:31
  • (I dunno who downvoted. I don't know enough yet to upvote or downvote your answer) – Himanshu P Feb 27 '13 at 09:32
  • @HimanshuPokhariya I updated with some links that I found, to help you get started. – jackJoe Feb 27 '13 at 09:47
  • 2
    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? – nohillside Feb 27 '13 at 10:05
  • @jackJoe: The flow/algorithm seems posted seems to make sense, but for non-programmers/non-applescript-programmers an actual script would be really helpful. (not wanting to sound impatient since you have already mentioned you plan to do that later in the day... so take your time) – Himanshu P Feb 27 '13 at 12:27
  • @jackJoe: Another thing: you posted links referencing "folder watching", which implies watching out for changes on the volume. However, for the purposes of this question, I believe we should consider a volume non-idle even if only read-only access to it is happening. – Himanshu P Feb 27 '13 at 16:47
  • @HimanshuPokhariya I posted pointers to get you started, and from the tests I made, checking for disk IO is very procesor hungry, and it will make your system slow unless you check if a certain app in that disk is idle. BTW, why do you want to eject an image after idle? – jackJoe Feb 27 '13 at 18:56
  • As I mention in the question (edited the question to add this a few hours back), this would be useful for a password protected image containing sensitive data. – Himanshu P Feb 27 '13 at 19:45