Volume Valet

The Volume Valet applet responds when a volume is mounted on the current system by alerting the user and offering the option to switch to the desktop and reveal the contents of the mounted volume.

The script accesses both the NSWorkspace and NSNotificationCenter classes of the AppKit framework to respond when a disk is connected to the computer.

To setup the applet for use:

To use the applet, double-click its icon. To stop using the applet, bring it to the front, and select “Quit” from the applet’s “File” menu or type Command-Q (⌘Q).

use framework "Foundation" use framework "AppKit" use scripting additions property ignoredVolumeNames : {"Recovery HD", "net", "home"} property notificationCount : 0 global blocked -- REGISTER THIS APPLET TO RECEIVE NOTIFICATION WHEN VOLUME IS MOUNTED -- create an instance of the Shared Workspace set workspace to current application's NSWorkspace's sharedWorkspace() -- identify the Shared Workspace's notification center set noteCenter to workspace's notificationCenter() -- register notification handlers for dealing with volume mounting noteCenter's addObserver:me selector:"volumeWasMounted:" |name|:"NSWorkspaceDidMountNotification" object:(missing value) set blocked to false -- handler called by OS when volume is mounted on volumeWasMounted:notif if blocked is false then set blocked to true set notificationCount to notificationCount + 1 -- get path to mounted volume set mountedVolumePath to (notif's userInfo()'s NSWorkspaceVolumeURLKey's |path|()) -- get last path item set thisVolumeName to (mountedVolumePath's lastPathComponent()) as text if thisVolumeName is not in ignoredVolumeNames then -- get AppleScript reference to volume set thisVolumeReference to (mountedVolumePath as text) as POSIX file as alias -- display alert tell application (POSIX path of (path to frontmost application)) display dialog "The volume “" & thisVolumeName & "” has been mounted on this system." & return & return & "Do you want to view its contents?" & space & "(" & notificationCount & ")" buttons {"No", "Yes"} default button 2 if the button returned of the result is "No" then error number -128 end tell -- show the volume tell application "Finder" open thisVolumeReference tell the front Finder window set current view to list view set bounds to {72, 90, 800, 640} end tell activate activate set visible of every process whose name is not "Finder" to false end tell end if set blocked to false end if end volumeWasMounted:
UNDER CONSTRUCTION

This webpage is in the process of being developed. Any content may change and may not be accurate or complete at this time.

DISCLAIMER