I have been working for months on a «idle» handler that would supervise my computer inactivity. When every requirements would be met, it would put my computer to sleep until it is awaken by Power Manager to do a specific job. After the handler would put it back to sleep again.
While I thought everything was OK, I got this problem. One of the important reason for this handler is to do unattended nighlty backups and to go to sleep afterwards. My handler does perfectly the job (except for the backup part obviously …) when no drive is connected. I tried to eject the drive, by script, before putting it to sleep. If the drive is connected but not mounted, the drive interrupts the sleep process and reawakens my Imac. If the drive is connected and mounted, it also awakens and tells me that the drive was disconnected inappropriately.
I do all of that without a script. I have my Energy saver set up to sleep the machine in an hour, sleep the disks (2) whenever possible, and sleep the screen in a few minutes. I have set the Energy Saver Panel to wake the machine at 3:09 AM, and have set the schedule in SuperDuper to back up one minute later at 3:10. The maintenance script(s) run when the machine wakens so SuperDuper doesn’t start until 3:24 AM. The machine goes back to sleep on its own. I don’t know if the screen lights up – I’m not there.
As you can check every status (switched off, unmounted, mounted) of a disk drive with AppleScript,
I guess you just need the appropriate code for a reliable disk handling.
But there is no common answer, because the different type of disks behave also different
I need something more than the “EnergySaver” options. AppleScript does it all … save my problem with the disk drive. I can share all my handler, but this is the part of the script that handles the sleep part:
repeat with i in diskList
if (list disks) contains i then
tell application "Finder" to tell disk i to set isEjectable to ejectable
if isEjectable then
try
tell application "Finder"
eject disk i
repeat while exists (disk i)
delay 0.5
end repeat
end tell
on error e
reportError(e)
end try
else
try
do shell script "/usr/sbin/diskutil unmount /Volumes/" & i
on error e
reportError(e)
end try
end if
end if
end repeat
delay 30
if (activeUserName is equal to currentUserName) then
do shell script "/System/Library/CoreServices/Menu\\ Extras/User.menu/Contents/Resources/CGSession -suspend"
delay 3
end if
tell application "System Events"
sleep
delay 5
end tell
What is the information I need to provide to get “the appropriate code for a reliable disk handling” ?