Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.5: Eject drives and run iSync before sleep via script System 10.5
This is a little AppleScript that I wrote to check and ask if the machine should unmount peripheral disks, and optionally perform an iSync, before sleeping. I was motivated to write this after about the fifteenth time I woke my laptop up after taking it home from work only to be greeted with a warning that I did not properly disconnect my Time Machine Disk.

Additionally, since I use iSync to sync my date book and address book with my Nokia cell phone, I thought it would be a good idea to have it auto-sync before I put the machine to sleep. If you are capable with AppleScript, you can go in and make modifications for your system (e.g. turn off iSync, or the options to unmount). One caveat: if your home disk is not the same as the startup disk (unlikely on a laptop), the script will ask if you would like to unmount that disk before sleeping.

I packed the script as an application bundle (with a 10.5-sized icon) for optional placement directly into the dock -- download it from macosxhints.com [464KB download]. Here's the source:
-- A few commands of interest before sleeping
-- AVN   Mon Apr 21 16:04:40 EDT 2008
-- Run iSync to get latest information on phone 

-- Unmount the backup disk if it is currently mounted.  
-- This should really be done with all external disks
tell application "Finder"
  display dialog "Preparing to sleep.  This will attempt to eject the BackupDisk, and run iSync before sleeping. " with title "mySleep?"
  set SDstring to name of startup disk as string -- get startup disk name  
  set AttachedDisks to name of disks -- get list of attached disks
  set DiskCount to number of disks -- skip repeat if only 1 disk
  if DiskCount is not equal to 1 then
    repeat with CurrentDisk in AttachedDisks -- run on all disks
      set CDstring to CurrentDisk as string -- create stringname for comparison
      if CDstring is not equal to SDstring then --if not the startupdisk
        try
          display dialog ({"Unmount ", CDstring, "?"} as string) with title "mySleep: eject disk?"
          eject disk CurrentDisk
        end try
      else
        display alert ({CDstring, " is being skipped"} as string) giving up after 2
      end if
    end repeat
  end if
  
  set dosync to display dialog "Please disconnect power and all unmounted peripherals before continuing." buttons {"Cancel", "Sleep now", "Sync then Sleep"} default button "Sync then Sleep" cancel button "Cancel" with title "mySleep: disconnect peripherals"
  if button returned of dosync is "Sync then Sleep" then
    tell application "iSync"
      activate
      tell application "System Events" to set visible of process "iSync" to false
      synchronize
      repeat
        if not syncing then exit repeat
      end repeat
      quit
    end tell
  end if
  
  tell application "Finder"
    display dialog "Good night" default button "Ok" giving up after 2 with title "mySleep"
    sleep
  end tell
end tell
[robg adds: I haven't tested this one, but I did download the disk image and confirm that it's just the script rolled up in an application bundle.]
    •    
  • Currently 3.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (6 votes cast)
 
[11,131 views]  

10.5: Eject drives and run iSync before sleep via script | 3 comments | Create New Account
Click here to return to the '10.5: Eject drives and run iSync before sleep via script' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
newer version
Authored by: avn on Apr 25, '08 08:34:17AM
If interested, there is a slightly modified version that gives the option for sleep now in case you become addicted to clicking that button on the dash for every sleep instance.

mySleep.dmg

[ Reply to This | # ]
10.5: Eject drives and run iSync before sleep via script
Authored by: vocaro on Apr 25, '08 11:12:16AM
A similar script for ejecting drives, with finer-grained control over such things as optical discs, can be found on my blog.

[ Reply to This | # ]
Way to sync .Mac dotMac?
Authored by: TF on Apr 27, '08 11:45:34AM

Starting iSync is nice, but that doesn't sync to .Mac. Is there way to start a dotMac sync before going to sleep/shutdown?

TF



[ Reply to This | # ]