Opening an OS X disk image with the launch agent on display

I created an agent launchd

that opened an unregistered disk image (and mounts its offline volume) daily at 2:45 AM to prepare the backup for that volume. The agent plist file is launchd

saved in ~/Library/LaunchAgents/

. Here are the parameters for the plist file:

Label: my.DiskImageOpener
KeepAlive: NO
RunAtLoad: NO
StartCalendar:
    Hour: 2
    Minute: 45
ProgramArguments:
    hdiutil
    attach
    /path/to/MyDiskImage.sparseimage

      

While the computer display is inactive, the agent acts as advertised by opening the disk image and setting its size at the point in time specified by the Launch Agent. On the other hand, if the display sleeps at the time specified in the launch agent, the disk image does not open until the display wakes up from sleep (even if it is a few hours later), after which the disk image opens immediately and mounts its volume. The same phenomenon occurs if I replace the command hdiutil attacj /path/to/MyDiskImage.sparseimage

with open /path/to/MyDiskImage.sparseimage

or put the command in a separate executable shell script that the launcher launches.

How can I get the launcher agent to open the disk image and set its volume when the display is sleeping?

I am using a MacBook Pro laptop running OS X 10.8.2 Mountain Lion. Thank you for helping us resolve this issue.

+3


source to share


1 answer


I think I came across a solution. As long as I keep the computer in a state to never sleep in the power saving preference area, then even if the display is asleep and / or the hard drive is installed whenever possible, then the launcher agent starts successfully by opening the disk image and setting the volume. Inexplicably, if the computer is configured to any setting other than never sleep (even though it might indeed be awake), the Launcher Agent does not work.



0


source







All Articles