Monday, August 27, 2012

Running an unsigned app with Gatekeeper set to 'only apps from the Mac App Store and identified developers'

So with Gatekeeper set to 'Mac App store and identified developers', how do you actually run an app that isn't signed? If you double-click you'll see something like this:

As explained previously you can delete the HFS+ attribute or run it from the commandline, but for regular users that doesn't work too well. The solution is Ctrl-Click and 'Open'.

Tuesday, August 21, 2012

OS X: get a list of running launchd jobs

Here's a nice easy way to get a list of running launchd jobs using PyObjC to talk to the ServiceManagement API:

from ServiceManagement import SMCopyAllJobDictionaries

print SMCopyAllJobDictionaries('kSMDomainSystemLaunchd')
So how does this compare to launchctl? On a first look its great, it provides way more information about each launchd job.
        Label = "";
        LastExitStatus = 0;
        LimitLoadToSessionType = Aqua;
        MachServices =         {
            "" = 0;
        OnDemand = 1;
        Program = "/Applications/Utilities/System Information";
        TimeOut = 30;
But wait, I'm getting different results:
$ sudo launchctl list | grep airport
- 0
- 0
$ sudo python | grep airport
So what is launchctl doing different? Why am I missing airportd and other services? I spent some time reading the source, but that didn't help. I finally realised this was a execution context issue.
$ sudo /usr/libexec/StartupItemContext python | grep airport
        Label = "";
            "" = 0;
        Program = "/usr/libexec/airportd";
        Label = "";
            "" = 0;
            "" = 0;
The launchd jobs are running in the System context (there are a bunch of others, see table 1 here), and can't see jobs running in other contexts. This also means that if we use StartupItemContext as above to run in the System context, we're going to miss jobs that have set LimitLoadToSessionType to something else, as with the systemprofiler job, which only runs in the Aqua (GUI) context.
$ sudo /usr/libexec/StartupItemContext python | grep systemprofiler
$ sudo python | grep systemprofiler
        Label = "";
            "" = 0;

Wednesday, August 15, 2012

git: undo changes, revert uncommitted changes

I mostly love git, but I can never remember the syntax for undoing and reverting things, which is partly because I don't use it that often, and partly because the syntax is un-intuitive. I'll update this post as I hit the various scenarios.
Merge broken by conflicts
Often I'll pull in changes from the stable repo, forgetting I've made some uncommitted local changes, which results in a conflict. To drop all of your local uncommitted changes:
git reset --hard HEAD