I'm new to Terminal, so feel free to state the obvious.

SleepWatcher runs scripts right before and after your Mac goes to sleep. I've got a script to unmount an external disk before sleep, then remount it after. (That way, when I'm rushing to get to work in the morning, I can just close the lid, pull out all the cables and not get a "You didn't eject it, jerk!" complaint.)

The scripts run fine and it unmounts right before sleep. But, it won't remount after wake.


diskutil mount 8851F3A7-60A7-39A7-9DA8-41BE1499DE6C 

I can run this script manually in Terminal. It'll work then. SleepWatcher can execute the script (I can get it to display a dialog box), just not the command to mount.

What am I missing?

Update: I've chmod-ed the scripts as +x. Can diskutil be run as +x?

  • I didn't get /usr/sbin/diskutil mountDisk to work in the normal crontab (either directly or in a script), but it did work when run from the root's crontab or a per-user launchd job. – Lri Jul 31 '12 at 13:34

It's quite possible the device isn't available when SleepWatcher runs it's script. You can try running diskutil list > /PATH/TO/SOME/FILE in the script to see what diskutil sees at the time the script is actually run. You may need to introduce a delay (eg. sleep 5) on the script while you wait for the drive to become available to actually mount.

| improve this answer | |
  • Just tried that (18 seconds), and still no dice. How can I log what the script is doing? – Matthew Robertson Aug 12 '09 at 7:54
  • Getting the script to run diskutil list results in log files that are empty. It doesn't even list the internal disks. (Running the command manually produces a proper log file.) Huh. – Matthew Robertson Aug 12 '09 at 8:15
  • If you run diskutil >> /PATH/TO/SOME/FILE just to get output and see that diskutil will even run or if it's some other issue. – Chealion Aug 12 '09 at 16:34
  • @Chealion, If it's run with SleepWatcher, I just get blank files. If I run them manually, I get proper outputs. So, for some reason, diskutil won't run automated. Is there any other way I can mount an external disk with Terminal (or AppleScript)? – Matthew Robertson Aug 13 '09 at 7:14
  • 1
    Odd question, are you using just diskutil or the full path usr/sbin/diskutil? If you're not using the full path try that in the script. – Chealion Aug 13 '09 at 14:42

Try /usr/sbin/diskutil in the script. Depending on how the application executes the script, this could make all the difference.

| improve this answer | |

Try mounting the disk itself, rather then a single volume (even if it's the only volume on the disk).

For your .wakeup script, replace

 diskutil mount 8851F3A7-60A7-39A7-9DA8-41BE1499DE6C


 diskutil mountDisk disk1s3

... replacing 'disk1s3' with the proper device identifier for your own external disk, of course. I don't think I need to tell someone who is capable of specifying a volume by its UUID where to find that information. For everyone else, here's how:

 diskutil list
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.