How to determine pressed modifier keys when a Cocoa app is started?

Put this in applicationDidFinishLaunching:

NSUInteger modifiers = ([NSEvent modifierFlags] & NSDeviceIndependentModifierFlagsMask);

if (modifiers == NSAlternateKeyMask)   { 
    // do your stuff here 
}

Beginning with macOS 10.12, this should be:

NSUInteger modifiers = ([NSEvent modifierFlags] & NSEventModifierFlagDeviceIndependentFlagsMask);

if (modifiers == NSEventModifierFlagOption)   { 
    // do your stuff here 
}

Swift 5 variant:

func applicationDidFinishLaunch(_ aNotification: Notification?) {

    if NSEvent.modifierFlags.intersection(.deviceIndependentFlagsMask) == .option {
        // Your code
    }

}