Simple LiveBlog Demo Video →

August 25th, 2012 • 4 notes

This is a demo video of something I’ve been working on today. It’s a live blog (posts appear in real time), built with PHP + Pusher on the backend, and Cocoa for the native posting client. Still going to tweak it a little, but it’s pretty darn easy to set up on any server. Hopefully going to release the code + a tutorial so people can set up their own live blogs.

Cocoa Snippet: Check if process is running

May 26th, 2012

While working on a little Cocoa application, I needed to check if another process was open or not. NSWorkspaceworks great for GUI applications with a dock icon, but I needed to check if a background process was running. Instead of trying to wrangle with really abstract APIs to get this information, I opted to use NSTask to send a “top” command and parse the results for the process I was looking for. This method takes a string argument (the process you’re looking for) and returns true or false.

  -(BOOL)processIsRunning:(NSString *)aProcess{
    NSTask* task = [[NSTask alloc] init];
    [task setLaunchPath: @"/usr/bin/top"];
    NSArray* arguments = [NSArray arrayWithObjects: @"-s", @"1",@"-l",@"3600",@"-stats",@"pid,cpu,time,command", nil];

    [task setArguments: arguments];
    NSPipe* pipe = [NSPipe pipe];
    [task setStandardOutput: pipe];

    [task setStandardInput:[NSPipe pipe]];
    [task launch];
    NSData* processData = [[[task standardOutput]fileHandleForReading]availableData];
    NSString* processes = [[NSString alloc]initWithData:processData encoding:NSUTF8StringEncoding];
    if ([processes rangeOfString:aProcess].location != NSNotFound) {
        return TRUE;
    else {
        return FALSE;
October 25th, 2010
Cats are immutable singleton objects.

— Josh Nozzi