在Mac OS X中启动GUI过程,无需停靠栏图标 [英] Start a GUI process in Mac OS X without dock icon

查看:1011
本文介绍了在Mac OS X中启动GUI过程,无需停靠栏图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个通常使用标准图形界面运行的应用程序。但是,对于某些长时间运行的任务,它会产生以脚本模式运行的同一应用程序的其他进程,其中我从父进程控制它。一切都很好,除了对每个子进程,我得到另一个停靠图标,弹出一两秒,然后消失。

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 that run in a "script mode," where I am controlling it from the parent process. Everything works great, except that for each child process I get another dock icon that pops in for a second or two and then disappears.

有一种方法来运行应用程序有时,但应用程序图标不显示在Dock上?我不能编辑info.plist或任何东西,因为通常我想要的dock图标。该选项必须能够通过更改进程上的属性或通过命令行参数进行设置。我完全控制源的应用程序。它是用C ++(Qt)编写的,但是针对本地Cocoa库的解决方案很好。

Is there a way to run an application sometimes without the application icon showing up on the dock? I can't edit the info.plist or anything because normally I want the dock icon. The option must be able to be set by changing a property on the process or via a command line parameter. I have full control over the source to the application. It is written in C++ (Qt), but solutions that target the native Cocoa library are fine.

如果我把这个代码放到一个单独的应用程序中,所以我宁愿保持它的方式。我不能在后台线程中运行长时间运行的任务,因为他们正在做必须在GUI线程中完成的事情。 (在Qt,你不能可靠地使用字体,像素图或渲染SVG内容到背景线程上的QGraphicsScene。)

If I put this code into a separate application it would cause major duplication, so I'd rather keep it the way it is. I cannot run the long-running tasks in background threads because they are doing things that must be done in a GUI thread. (In Qt, you cannot reliably use fonts, pixmaps, or render SVG content onto a QGraphicsScene on background threads.)

任何解决方案?

推荐答案

根据这里,您可以: / p>

Motivated from here, you can do:

[NSApp setActivationPolicy: NSApplicationActivationPolicyAccessory];

[NSApp setActivationPolicy: NSApplicationActivationPolicyProhibited];

这应该隐藏dock图标。请参见这里 NSApplicationActivationPolicy

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

在Python中,隐藏停靠栏图标的代码是:

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

# http://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)

另见相关的问题的如何隐藏的Dock图标

如果你想避免停靠栏图标都在开始就弹出,你可以这样做:

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"

这篇关于在Mac OS X中启动GUI过程,无需停靠栏图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆