A little while ago I shared a snip of code I put in VoodooPad development builds, which beeps at me when I launch a second copy. I run into this problem because I use VoodooPad all day long, and - well, since I'm VoodooPad's creator, sometimes I'll accidently get multiple copies running which I don't want.
Anyway.
I've got a better version now (and I don't know why I didn't do this the first time either); use AppleScript to quit the old version and then continue on the app's merry way. I put this in my main.m file, before NSApplicationMain():
NSWorkspace *workspace = [NSWorkspace sharedWorkspace]; NSArray *launchedApplications = [workspace launchedApplications]; for (NSDictionary *junk in launchedApplications) { if ([@"com.flyingmeat.VoodooPad_Pro" isEqualToString:[junk objectForKey:@"NSApplicationBundleIdentifier"]]) { NSLog(@"It's already running you moron"); system("/usr/bin/osascript -e 'tell app "VoodooPad Pro" to quit'"); sleep(1.5f); // let the quit actually happen. } }
#endif
Yes yes yes, using system() is bad. I know. It's only ever run on my desktop though.