Lock all folders via Terminal

Started by lnealan, April 10, 2010, 03:13:19 AM

Previous topic - Next topic

lnealan

Espionage doesn't seem to have an applescript dictionary and I'd like to be able to automate "lock all folders". Is there a way to invoke this behavior via the terminal?

greg

#1
We are looking in to adding support for manipulating folders via the command line for a future version, but there are several possible workarounds in the meantime.

The easiest way would be to simply write a script to unmount the unlocked folders using the 'hdiutil' command. For example, I'll use the df command to get a list of mounted volumes:

$ df
Filesystem    512-blocks      Used Available Capacity  Mounted on
/dev/disk0s2   345767936 256640080  88615856    75%    /
devfs                234       234         0   100%    /dev
/dev/disk0s3    44282200  25677656  18604544    58%    /Volumes/Windows
map -hosts             0         0         0   100%    /net
map auto_home          0         0         0   100%    /home
/dev/disk1s2    43642816   9532104  34110712    22%    /Volumes/EspionageMounts/gslepak/3117152101/Programming
/dev/disk2s2     4194240    101776   4092464     3%    /Volumes/EspionageMounts/gslepak/229098097/Mail Downloads
/dev/disk3s2    37969856   6442360  31527496    17%    /Volumes/EspionageMounts/gslepak/229098097/Mail
/dev/disk4s2     4194240     34320   4159920     1%    /Volumes/EspionageMounts/gslepak/2907244101/The Hit List

The last entries are the locations of the mountpoints for unlocked Espionage'd folders. Note that only one of them is safe to lock, Programming, the others are application data.

Do not eject/unmount/lock folders that represent application data. That will confuse any running applications that are accessing that data. The right way to lock an application's data folder is to have Espionage lock it after the application quits. Make sure that the "Lock On Quit" option is enabled for that folder (click Edit Application Associations in Espionage), and then quit the application either using the kill command or safely using AppleScript ('tell application ___ to quit'). If all of the applications that are associated with that folder are no longer running, Espionage will lock it automatically.

If the folder isn't associated with any running applications (like the Programming folder in this example), simply use the hdiutil command to unmount it:

hdiutil detach "/Volumes/EspionageMounts/gslepak/3117152101/Programming"
The quotes around the path are necessary in case there's a space in the filepath. The detach command also takes a -force option to forcibly detach the volume in the event something is preventing it from unmounting (like an application that is reading a file off of it). Use that option with caution. For more information see the man page for hdiutil.

You might also be interested in this thread as it demonstrates how to use AppleScript to automate some of Espionage's behavior.
Follow @espionageapp@twitter.com or @espionage@mstdn.io for news and updates!

lnealan

#2
Thanks for your reply and pointer! I did realize that for now hdiutil is the only way to go. Since I'm trying to trigger a backup I first run an applescript that quits all the running applications that I have associated with any Espionage folders. Then I run this:

# Lock all folders
mount | grep EspionageMounts | cut -d' ' -f 3- | cut -d'(' -f 1 | xargs -I {} diskutil unmount {} &>/dev/null

greg

#3
Ah neat. I assume you're using some third-party tool for the backup? (Just as an FYI, though you probably already know, Espionage's built-in backups will properly backup the folders regardless of whether they're locked or unlocked.)

One other tip I'd give is to make sure to wait a little bit after all the applications have quit before running that command. Espionage will wait 3 seconds after it detects that an application is no longer running before locking the folder, this is so that application auto-updaters (which quickly quit and relaunch an application) work properly.
Follow @espionageapp@twitter.com or @espionage@mstdn.io for news and updates!

TomEck

#4
Interesting discussion but a bit over my head or better coding experiences. Is there a simple apple script or terminal code that would allow me to unlock or lock a specific folder or all folders? I would like to use Launchbar to unlock and lock folders. Perhaps it would be possible to tell the Espionage helper via a apple script to lock/unlock a folder? Or could I even assign a keyboard shortcut?

Thanks,
Thomas

greg

#5
Quote from: "TomEck"I would like to use Launchbar to unlock and lock folders.

You should be able to simply use LaunchBar to open the folder, this will bring up the password prompt and voila. Then, if LaunchBar can manipulate invisible volumes, you can lock the folder by ejecting it (it's just an invisible volume when unlocked).
Follow @espionageapp@twitter.com or @espionage@mstdn.io for news and updates!

TomEck

#6
Of course I can open the folder and bring up the password prompt but that means I have to open a Finder window. What I want to do is to access the folders inside LB and that only works when the folder is unlocked. LB is whitelisted for the reason that I don't want a password prompt any time LB want to index the folder or the folder is part of a search result in LB (for the same reason I don't use Application Association). That means I can look through LB into a locked folder but I see only the three folders "This folder contains encrypted data...". Is there a way to unlock a folder other than to open the folder via LB through the Finder?

LB shows me locked and unlocked folders (most of the time; the mentioned problem with symbolic links still exists...) but a unlocked folder seems not properly recognized as a volume even it is listed under volumes. I am not able to eject such a volume.

greg

#7
Thanks Thomas, we see what you're seeing as well, for some reason LaunchBar can't eject Espionage's volumes (I'm not sure why, this is a question you'll want to ask its developers). We'll look to see what we can do to improve Espionage's compatibility with LaunchBar. In the future you'll probably be able to use Espionage's "Lock Folder" service to lock unlocked folders from LB. Unlocking a folder from LB might take longer though.
Follow @espionageapp@twitter.com or @espionage@mstdn.io for news and updates!

TomEck

#8
Thanks for the response, Greg. I am glad that you will take a closer look. I have posted a similar information in the LB forum. Thanks again!