Start a GUI process in Mac OS X without dock icon

后端 未结 2 1067
遥遥无期
遥遥无期 2020-12-06 14:37

I have an application that normally runs with a standard graphical interface. However, for certain long-running tasks, it spawns additional processes of the same application

相关标签:
2条回答
  • 2020-12-06 14:56

    Motivated from here, you can do:

    [NSApp setActivationPolicy: NSApplicationActivationPolicyAccessory];
    

    or

    [NSApp setActivationPolicy: NSApplicationActivationPolicyProhibited];
    

    This should hide the dock icon. See here for some documentation about NSApplicationActivationPolicy.

    In Python, the code to hide the dock icon is:

    # https://stackoverflow.com/a/9220857/133374
    import AppKit
    # https://developer.apple.com/library/mac/#documentation/AppKit/Reference/NSRunningApplication_Class/Reference/Reference.html
    NSApplicationActivationPolicyRegular = 0
    NSApplicationActivationPolicyAccessory = 1
    NSApplicationActivationPolicyProhibited = 2
    AppKit.NSApp.setActivationPolicy_(NSApplicationActivationPolicyProhibited)
    

    See also the related question "How to hide the Dock icon".


    If you want to avoid that the dock icon pops up at all right at the beginning, you can do that:

    import AppKit
    info = AppKit.NSBundle.mainBundle().infoDictionary()
    info["LSBackgroundOnly"] = "1"
    
    0 讨论(0)
  • 2020-12-06 15:05
    import AppKit
    info = AppKit.NSBundle.mainBundle().infoDictionary()
    info["LSBackgroundOnly"] = "1"
    

    This code works for my Non-GUI background python script.

    0 讨论(0)
提交回复
热议问题