Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Quick Applescript to Mount Disk Image' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Quick Applescript to Mount Disk Image
Authored by: puffyn on Apr 18, '03 01:45:17AM
This is far from ideal/finished, but I wanted to automate the process a little more. I'm using the system to secure my Notes library, so anyone using this with Mail could just replace "Notes" with "Mail" in the appropriate places.

Basically the idea is to have a script which mounts the disk image and launches the program and then sticks around so that when the application is quit, the secure disk image is unmounted.

Save the following script as an application, and check the "Stay Open" box and the "Never Show Startup" box. You should call your application "CryptoNotes" or change the 6th line from the bottom to whatever you call it.

On run, the program runs the parent comments' script. It then pauses for a while before going into it's idle state, in which it checks whether the application in question is still open every 5 seconds (this is a very processor-friendly call, but you could increase this time interval if you really want to).

Then, when you quit Notes, CryptoNotes ejects the secure disk image, and quits itself (sometimes the second action occurs 5 seconds after the first). Your files are not left lying around unencrypted.

This works okay for me, but could be improved. The biggest kludge is the delay 10 in the on run section. This is to prevent the script from unmounting the disk image before Notes can open for the first time, but clearly if something caused Notes to take more than 10 seconds to open, this would fail.

on run
set diskpath to "Users:puffyn:Documents:SecureDisk.dmg"
set diskname to "SecureDisk"
tell application "Finder"
if the disk diskname exists then
return
else
do shell script ("hdiutil mount " & ¬
POSIX path of (diskpath as string) & "")
end if
end tell
tell application "Notes"
launch
end tell
delay 10
end run
on idle
set diskname to "SecureDisk"
tell application "Finder"
if not (exists the disk diskname) then
return
else
set x to the name of every process
if "Notes" is not in x then
eject diskname
tell application "CryptoNotes" to quit
end if
end if
end tell
return 5
end idle


[ Reply to This | # ]

Quick Applescript to Mount Disk Image
Authored by: jmb on Apr 18, '03 08:23:00AM

You could set up a cron job to check if Notes i running and, if not, have it eject the image if present. I could imagine that this might create rare problems if, for instance, the cron job runs between disk mount and app launch, but doing it this way would make it independent of an AppleScript that might crash and not be running when needed.



[ Reply to This | # ]