OS X在后台打开URL方案

时间:2022-03-10 02:42:56

I'm currently writing an OS X application that implements a custom URL scheme. By design, my app will relatively frequently (about every 2-4 minutes) be opening URLs from an external source. However, this needs to be done in the background (i.e. no GUI or switching of active applications). This is a status bar app (Application is agent (UIElement) set to YES), and has Application UI Presentation Mode set to All Suppressed. While these do prevent any UI elements from being shown upon opening a relevant URL, whatever application window that is active at the time loses focus. Obviously, losing focus on whatever window you're working in every few minutes is a no-go, so how can I prevent this behavior when opening custom URLs?

我目前正在编写一个OS X应用程序,它实现一个自定义URL方案。按照设计,我的应用程序将相对频繁地(大约每2-4分钟一次)打开来自外部源的url。但是,这需要在后台完成(即没有GUI或活动应用程序的切换)。这是一个状态栏应用程序(应用程序是代理(UIElement),设置为YES,并将应用程序UI表示模式设置为所有压制。虽然它们确实阻止了打开相关URL时显示的任何UI元素,但此时激活的任何应用程序窗口都将失去焦点。显然,每隔几分钟就把注意力转移到正在工作的任何窗口是不可能的,那么我如何在打开自定义url时防止这种行为呢?

1 个解决方案

#1


1  

I found my answer. If anyone else ever runs into this problem:

我发现我的答案。如果有人遇到这个问题:

I removed the Application UI Presentation Mode and Application is agent (UIElement) keys from the plist. I set Application is background only to YES. That did the trick. Now the current window no longer loses focus when opening the URL.

我从plist中删除了应用程序UI表示模式和应用程序是代理(UIElement)键。我设置的应用程序只是背景,是的。起了作用。现在,当打开URL时,当前窗口不再失去焦点。

#1


1  

I found my answer. If anyone else ever runs into this problem:

我发现我的答案。如果有人遇到这个问题:

I removed the Application UI Presentation Mode and Application is agent (UIElement) keys from the plist. I set Application is background only to YES. That did the trick. Now the current window no longer loses focus when opening the URL.

我从plist中删除了应用程序UI表示模式和应用程序是代理(UIElement)键。我设置的应用程序只是背景,是的。起了作用。现在,当打开URL时,当前窗口不再失去焦点。