Apple has some restrictions in place to prevent access to LaunchAgents running in a user session context.
But you may want to load or refresh a LaunchAgent as part of your install without requiring the user to log out and back in.
I prefer not to require logouts and reboots in my installation packages. Where possible, I use munki’s unattended option so software installs silently and the user is not prompted.
After some experimentation, I came up with this hacky method of getting a LaunchAgent to load from a package being installed as root. If you have a cleaner way to accomplish this, please let me know. Update: Please see Per Olofsson’s comment for a much better method until I update this gist.
Once in a while you run into a package or program that will only work properly with a user logged in. This can ruin your day if you need to automated the deployment.
I found this method of automatically logging in a user (which is quite awesome).
Using that perl script along with a wrapper script can enable you to automate these can other cases where your only option is to have a user logged in.
I started writing a script to handle this, but it turned out I didn’t need it. The script is unfinished, but it may give you a head start if you are considering something similar.
It depends on a modified version of the perl script that accepts a username and password. Just swap out the user and password lines with these that accept arguments.
my $user = $ARGV;
my $pass = $ARGV;
and I comment out the line to automatically restarts the loginwindow.