Terminal: On wake, mount external disk automatically

3

1

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.

#!/bin/sh

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?

Matthew Robertson

Posted 2009-08-12T07:02:31.687

Reputation: 85

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 – 2012-07-31T13:34:44.057

Answers

1

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.

Chealion

Posted 2009-08-12T07:02:31.687

Reputation: 22 932

Just tried that (18 seconds), and still no dice. How can I log what the script is doing? – Matthew Robertson – 2009-08-12T07:54:43.157

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 – 2009-08-12T08:15:04.053

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 – 2009-08-12T16:34:12.603

@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 – 2009-08-13T07:14:44.957

1Odd 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 – 2009-08-13T14:42:50.260

0

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

Benjamin Dobson

Posted 2009-08-12T07:02:31.687

Reputation: 1 021

0

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

with:

 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

Ambrose

Posted 2009-08-12T07:02:31.687

Reputation: 246