Launching apps behind the lock screen

applescriptkeychainpasswordrootsleep-wake

I need to run an application behind the lock screen, e.g., just as Time Machine or Sophos antivirus (and others) can run when the screen is locked.

Specifically, I would like to schedule an application to launch when the computer is asleep and unattended (but not powered off). The plan is to schedule wake via Energy Saver or pmset, and use iCal/Automator to schedule the app launch. The problem I'm encountering is the lock screen (ie System Pref > Security > Require Password). When the lock screen is enabled the application will not launch unattended – a user must enter the password. By way of debugging I have confirmed that disabling lock screen allows the app to launch, but this is not a solution due to the security issues.

Bottom line: Is there a way to schedule an applescript or shell script (perhaps with root privileges) to grant the lock screen access to the password? I'm thinking KeyChain should be able to do this, but I can't figure out how. Or perhaps there are other solutions?

Other details:
– I'm running 10.7 and 10.9.

Best Answer

Power Manager

If you are happy to use a third party application, Power Manager can do exactly what you want.

There are lots of recipes to help create your schedule. For your situation:

By default, Power Manager will power on a sleeping Mac to perform scheduled events. The recipe above for launching an application will automatically wake a sleeping Mac. You can adjust the event to power on a shut down Mac, if desired.

Power Manager will launch your application behind the lock screen. This is possible because Power Manager has a helper agent running within each user session. The main scheduler works with the agent to make sure the application is launched in the right user session.

DssW Power Manager on OS X

Disclosure: I work for DssW, who make Power Manager; so feel free to ask technical questions.

Fast User Switch

If you are concerned about security, consider having the user be switched back to the login window with Fast User Switching.

While Fast User Switched, your Mac can wake to schedule, run the AppleScript, and complete its task while not risking unguarded access to the Mac.