void waitForProccessToDie(pid_t pid)
{
    ProcessSerialNumber processSerialNumber;
    
    while (GetProcessForPID(pid, &processSerialNumber) != procNotFound)
    {
        sleep(1);
    }
}

int main(int argc, char *argv[])
{
	waitForProccessToDie((pid_t)atoi(argv[2]));

	NSString *exePath = [NSString stringWithCString:argv[1]
                                           encoding:NSUTF8StringEncoding];
    
    [NSWorkspace.sharedWorkspace
        openFile:[exePath stringByExpandingTildeInPath]];

	return 0;
}
