I constantly forget to eject secure disk images, and it bugs the hell out of me. For the longest time, I’ve wanted a way to make a secure disk image eject automatically after X minutes.
Elasticthreads came to my rescue, and I was able to whip up a very simple app in Automator using AppleScript:
on run {input, parameters}
tell application "Finder"
do shell script "hdiutil attach ~/Documents/Secure.dmg"
delay 1800 --number of seconds
eject disk "Secure"
end tell
return input
end run
So instead of double clicking Secure.dmg to mount it—like I used to—I run this app, which mounts Secure.dmg for me (after giving me the usual password prompt). After 30 minutes, or 1,800 seconds, it ejects Secure.dmg.
For me, 30 minutes is usually ample time to do what I need to do Secure.dmg. And I can always eject it manually and quit the app in the menu bar.
If this is too paranoid and geeky for you, congratulations. Forget about it. Otherwise, let me know if you come up with a more elegant solution.
{ 5 comments… read them below or add one }
Still incredibly unelegant:
tell application “Finder”
set d1 to name of disks
set d2 to {}
repeat with f in (get selection)
if kind of f is “Disk Image” then set end of d2 to f
end repeat
if d2 is {} then return
open d2
delay 30 — password dialogs etc
set d3 to name of disks
delay 1600
repeat with dsk in d3
try
if dsk is not in d1 then eject dsk
end try
end repeat
end tell
one app I have been enamored with is the mac App Undock. It will eject external drives and disk images with a click.
You can attach scripts to it, so I wonder if your script could be connected to Undock so that you have a really nice solution for all of your eject needs.
twitter: @nanaslugdiva
Can you show the steps in how you made this work with Automator? I understand where I should edit the location/name of my dmg in the text you have there, but how do I put this into Automator? I’ve tried pasting it into Automator and it doesn’t do anything when I make it an application. It just launches and nothing happens. It doesn’t ask for my dmg sparseimage password or anything.
Also, while this in delay mode, does that slow down the computer at all or does the system kind of note the time and then come back to eject the dmg as instructed?
Ok, I got it to work with AppleScript Editor instead of Automator.
I removed: on run {input, parameters} from the top and return input end run from the bottom. What were those commands for?
Thank you by the way for putting this info up!