![]() |
How to create an automounting DMG?
Hi,
For the last few months I have been carrying around my work files on a flash disk. Well the inevitable happened and I lost the drive. After the fact, the stupidity of carrying around some personal data without some type of encryption dawned on me. Here is the functionality I desire. A cross platform flash drive with most files accessible across platforms. A smaller number of file kept in encrypted form that really only needs to be accessible on the Mac. My solution is to create an encrypted DMG and carry it on my flash disk which is formatted in FAT32 format for cross platform access. My question is how can I get this encrypted dmg to automatically mount when I insert my flash drive in a USB port on a Mac? Thanks. |
Hi, I am still looking for suggestions. Here is my scenario:
I have 4 GB flash drive (formatted FAT32 I think). On it I created an encrypted read/write DMG. I am looking for the DMG to mount as soon I plug the flash drive into the USB port. Any help would be appreciated. Thanks,. |
Wouldn't having the encrypted image auto-mount defeat the purpose of encrypting it in the first place? I find it on the bus, plug it in, everything opens automatically - no fuss, no password?
|
Good question. I don't think it would work that way. When you launch the DMG, you are asked to enter the password. Perhaps it might be more accurate for me to say I am looking for an auto-launch method. Then on machines I trust, I can save the encryption password in my keychain and it would mount automatically. On other machines I would still have to provide the password before completing the launch. Likewise if you found it, you would still need to enter the encryption password.
|
Windows machines use the autorun.inf file to sort of do what you want, however you might find it disabled as it's been a substantial security risk in the past. I don't think the Mac has a similar automatic function - same reason. If you eject the drive with the window open and the .dmg file visible it should reappear the same way, meaning you just have to double-click it.
|
Yes the autorun functionality is similar to my desired functionality. Unfortunately since it is DMG that I open and mount, I can not eject the flash drive with out first ejecting the mounted DMG. If I do try to eject the flash drive, the OS says the drive is in use and can not be ejected.
|
script to launch DMG file
Hi,
I posted this question in another forum and was not successful in finding a solution so I thought maybe I should try here. Desired functionality: Insert USB flash drive into USB port and launch an encrypted DMG file so that it mounts (on machines where the password is saved in the keychain) and is ready to use along with the flash drive. I have never created an applescript before, so I would be greatful for as much detail as possible about what i should do. Thanks. |
Quote:
If you want your thread transferred to a different section of the forums, ask a moderator to do this. I have merged your new thread into the existing one. I'll now move it to the Developer forums since that is what it seems that you want. |
Thank you. Sorry for the breach of etiquette.
|
There's an article by Craig Smith in the archives of MacScripter.net to run as script when a flash drive is mounted using launchd. Your script would mount the dmg file for you.
|
Thanks for the link. It does indeed give me the framework to do what I need to do if I can figure out how to write the script to launch the DMG file.
|
tell application "Finder" to open (hfs path to the file here)
|
Thanks. This will be my first script so I truly appreciate the help. I will post my solution so that others who come upon this will have it too.
|
I am sorry to impose but I could use a little help debugging why the script that NovaScotian directed me to did not work.
Here is what I have been able to do so far. 1. Created folder called LaunchAgents in /drmoque/Library/ 2. Created folder called Scripts in /drmoque/ 3. Created plist file in LaunchAgents called WatchVolumePath.plist This is what is in the file: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>WatchingVolumePath</string> <key>LowPriorityIO</key> <true/> <key>Program</key> <string>/usr/bin/osascript</string> <key>ProgramArguments</key> <array> <string>osascript</string> <string>/Users/drmoque/Scripts/AutoFlash.scpt</string> </array> <key>RunAtLoad</key> <true/> <key>ServiceDescription</key> <string>This is the launchd script to launch private.dmg</string> <key>StandardOutPath</key> <string>/Users/drmoque/scripts/AutoFlashLog.txt</string> <key>WatchPaths</key> <array> <string>/Volumes</string> </array> </dict> </plist> 4. Created a script called AutoFlash.scpt located in /drmoque/Scripts/ The contents of the script are: property flashState : 2 set triggerFile to "CRUZER:private.dmg" tell application "Finder" if file triggerFile exists then --The file is found, therefore, the flash drive is present if flashState = 2 then open "CRUZER:private.dmg" set flashState to 0 --After the script has been run, change the flashState property end if else --This is ONLY accessed when the file no longer exists, therefore, the flash drive is NOT present if flashState = 0 then --Since the drive is no longer present, the value of flashState must be re-set to 2 in order to prepare for the next hookup set flashState to 2 end if end if end tell 5. Loaded WatchVolumePath.plist (even logged out and logged in) 6. Plugged in USB drive and the desired result does not occur. When I run the script in script editor it does indeed launch the desired DMG file. The problem seems to that the script is not being run which seems to point to the launchd script (WatchVolumePath.plist). If anyone has any ideas as to what I may have done wrong, please let me know. |
I'd recommend using Lingon (google for it) to install launchd agents instead of trying to do it manually.
|
Thank you. I did use Lingon.
|
Next thing that I'd look at is whether the problem might be with your AppleScript or perhaps just with running an AppleScript (any AppleScript) via launchd (see this Apple article about the different contexts: http://developer.apple.com/technotes/tn2005/tn2083.html)
I'd start off with a simple Bash shell script - e.g.: Code:
#!/bin/bash |
The Applescript works when I run from within the ScriptEditor. So I went to the next stage of testing launchd working wiht a script. I created a test.sh based on Hayne's bash script above. I modified the plist file above and changed the program arguments to:
<key>ProgramArguments</key> <array> <string>/bin/bash</string> <string>/Users/drmoque/Scripts/test.sh</string> </array> The test script seems to work properly. Tested it with several insertions of the USB drive. I guess I will try the Applescript again. |
Well I have partial success. If I restart my machine with the flash drive in the USB port, then the Applescript mounts the DMG file. However any subsequent removals and insertions of the flash drive, do not cause the script mount the DMG.
Is there way in the applescript to get a time stamp? I would like to track the change in the state variable of the script. Since I am concurrently running th bash script for changes in the /Volumes, I should be able to match changes in state to see if the state variable is changing as designed. |
I hate to ask this question, but did you ever look into just buying a secure jump drive that is already encrypted? Half of the jump drive is open and the other half is secured with a password. I don't know of any of them off the top of my head, but I do know I have seen and read reviews about them.
I googled this one here: i http://www.everythingusb.com/lexar_j...re_ii_1gb.html It does seem though that a lot of the AES encrypted ones do not support native access on Linux or OS X, but that Lexar one I linked above does. |
Quote:
You should forget about doing the mounting until you can reliably get the AppleScript to get invoked. Note also that it is possible to invoke AppleScript from a Bash script. See the examples in my Unix FAQ (top of the Unix beginner section of these forums) Quote:
|
Actually I have a Sandisk Titanium which did have the U3 software. When I was looking into it, most of the ones with encryption only worked on Windows not Mac OS. Plus I preferred the sturdiness of the titanium over the encryption feature (it also occurred to me to encrypt after I had purchased my flash drive.)
Using a DMG works fine for my needs. I admit to being lazy but if I can get the DMG to mount, my next step is going to be to mount the image and then launch my mail and IM software which both need the DMG to be mounted to work correctly (this is by my choosing). I actually have an applescript that will do all three steps. The only thing I have not been able to do is automatically recognize the insertion of the flash drive. If I compile the script as an application and put it in my dock, then I can actually achieve a substantial savings in startup steps to get me going. So at this point it has moved more into the realm of learning how to do this specific set of tasks rather than lacking a workable solution. The plist file and script do seem to work on occasion. I just can get them to consistently work together correctly. I know at least 3 times today that the scripts worked as intended. Unfortunately, at least as many times they did not. |
Hayne, thank you again for the help.
|
Hayne, if I may impose oncer more upon you. Since i had success with the basic shell script, I thought I might have better luck if I do all the things I want in a shell script rather than an apple script
So this is the AppleScript I want to convert to shell script: try do shell script "hdiutil mount '/Volumes/CRUZER/private.dmg'" set launchApps to "true" on error set launchApps to "false" end try if launchApps is not "false" then tell application "Microsoft Entourage" to activate tell application "Portable Adium" to activate end if Would the following work as it's replacement? #!/bin/bash if hdiutil mount '/Volumes/CRUZER/private.dmg' insert commands to launch apps else exit 1 If the basic framework is correct, is there an equivalent command to tell application to activate for bash? I tried looking at several bash related websites and some google searches and could not find it. But in truth, i have no idea what it might be called so that makes it harder to search. |
I just recently wrote a shell script that date stamps a HTML page for bloggers and web developers to quickly make blank date stamped HTML pages. I used this code to date stamp things, you would have to output the shell script into an application though.
Code:
#!/bin/bashCode:
sh /path/to/script | open -f -t (will open it in the OSes default text editor) |
Thanks, but I can get a time date stamp easily in a shell script using the suggestion by Hayne above. What I was looking for was a way through an applescript since that is where my problem seems to lie. However, right now that is on the backburner if I can find a way to launch a Mac application directly from the shell script.
|
To merely launch an application from the command-line (or from a shell script), you can use the 'open' command - read 'man open'.
You want to use the "-a" option to tell it to run an app (as opposed to opening a document) =- something like: open -a "Microsoft Entourage" |
Excellent. thanks so much.
|
drmoque,
At first, I thought you wanted the dmg to mount on any machine automatically, which I don't believe can be done. But now that you're going down the scripting, you are certainly going to limit this behavior to specific machines--the one's that are running the scripts and launchagents. So since you're going that route, why not forget about all of the scripting and just use Do Something When? |
chabig,
When I started this journey, I was looking to do something to the DMG that would indeed launch on any machine. When that seemed improbable I backed down to something I could do on machines that I use frequently and had a user account. In fact the desire to launch my mail and IM programs after mounting the encrypted DMG were part of what I would call the evolution of my needs and desires. I believe Do Something Now will probably do exactly what i need if I can mount the DMG file using the hdutil command. I am certainly going to download it and try it out to see if it can. Thank you for the suggestion, I had no idea of its existence. |
To all who have responded to this post, Thank you.
Do Something Now seems to have done the trick. It is not my ideal solution since it only works on machines where DSN is installed but for me it will be close enough. At least on machines I can control and trust, it does exactly what I needed to do. |
| All times are GMT -5. The time now is 05:51 AM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.