Spacer http://macenterprise.org MacResource.org - Mac OS X enterprise deployment project Spacer
Site Map Contact Us Top Background
 
Search
 
 
Detect User Media on Logout E-mail
Written by A.   
Tuesday, 03 October 2006
This is an applescript for use in lab situations where clients may leave , but forget their CDs,
Flash Drives, etc. This code is meant to be added to longer logout script (this script does
not actually log someone out)..

Change the first line that is not commented out to reflect the number of disks the computer has, and
if there are more than that when the script runs, it will eject them and warn the client. Disk images
and mounted servers are not counted.

--Checks for number of mounted disks and warns the user before logout if number exceeds
--standardNumDisks
--Last updated: 24 May 2006
--Written by David A. Cox, University of Washington

--number of standard local volumes
set standardNumDisks to 1

--warning to client, possibly displayed later
set newLine to (ASCII character 10)
set warningMessage to "It appears you may have a disk mounted. Ejecting all media..." & newLine &
newLine & "Please ensure you have all your items."

--This sets the command to close the try to false. It is set to true if the drive is ejected later.
set checkTray to false --may have to close cd tray

--This bit gets a text dump of all the info about mounted disk images, does some hack
--work to count the number of instances a word shows up in that text. It subtracts 1 from
--this count to clean up after the hack way we are getting the data.
set hdiOutput to do shell script "hdiutil info"
set IDline to "image-path" as string
set ASTID to AppleScript's text item delimiters --preserve
set AppleScript's text item delimiters to IDline
set ItemsofOutput to text items of hdiOutput
set AppleScript's text item delimiters to ASTID --restore

--total # of disks that aren't possible client media. Anymore than this and we
--display a warning set expectedNumDisks to (count ItemsofOutput) - 1 + standardNumDisks

tell application "Finder"

--counts current local volumes
set currentNumLocalDisks to count of (every disk whose local volume is true)

--display warning if more than standard number of disks + number of disk images are found
if currentNumLocalDisks > expectedNumDisks then

--eject all media
try
eject (every disk whose local volume is true)
--eject all CDs/DVDs, disk images, and firewire/USB devices; warning if disk in use
end try

set checkTray to true --possibly opened above, need to close it later

--inform client
set volume 6
beep 2
say "Don't forget your media" using "Trinoids"
set WarningDialog to display dialog warningMessage with icon
2 buttons {"OK"} default button "OK" giving up after 15
set volume 0

end if

--retract tray
if checkTray then
try
do shell script ("drutil tray close")
end try
end if

end tell

Last Updated ( Monday, 30 October 2006 )
 
< Prev   Next >