I have a encrypted dmg disk “Private Drive” I would like to automate an eject on close folder so that it forces the password prompt again.
I am new to scripting so I tried to create one but it fails this is what I tried…
“on closing folder window for this_folder
tell application “Finder”
eject disk “Private Drive”
end tell
end closing folder window for”
I ran this “tell application “Finder” to set the_disks to (get disks whose local volume = true and ejectable = true)”
which brings back the result {disk “Private Drive” of application “Finder”}
Take out the word disk and tell the finder to eject “Name of Drive”
“on closing folder window for this_folder
tell application “Finder”
eject “Private Drive”
end tell
end closing folder window for”
I keep this one in my dock to unmount all network drives before I leave the office.
set theMac to boot volume of (system info) as string
set theDrives to list disks
repeat with i in theDrives
if i is not in theMac then
tell application "Finder"
eject i
end tell
end if
end repeat
Nominally, that’s completely wrong. The Finder ejects disks, not texts. Does omitting the keyword actually work better for you?
An alias to the folder to which the action’s attached is passed to the handler. In the Finder, a ‘folder’ is a subspecies of ‘item’, which has a ‘disk’ property containing the disk on which the item’s located, so:
on closing folder window for this_folder
tell application "Finder"
eject disk of this_folder
end tell
end closing folder window for
As with all folder action scripts, Folder Actions must be enabled, the script must be attached to the relevant folder and must be located in a folder called “Folder Action Scripts” in your user “Scripts” folder.