FinderSync check if extension is selected

匆匆过客 提交于 2019-12-09 11:47:36

问题


I am developing a FinderSync extension and I have some issues in checking if the selection is selecting, or selecting/deselecting the extension.

Is there a way to programmatically check if a FinderSync extension is selected in System Preferences->Extensions?

Are there any API's to get notified when this selection changes?

Is there any API to select/deselect an extension, beside using the following?

system("pluginkit -e use -i com.mycompany.finderExt")

Note that I have already visited these pages:

How to enable FinderSync Extension in the System Preference in Cocoa - Objective C

OSX Finder Sync Extension


回答1:


pluginkit -m -A -i com.mycompany.finderExt

If the extension is enabled, the call will return

"+ com.mycompany.finderExt(1)"

If the extension is not enabled, the call will return

"- com.mycompany.finderExt(1)"

Notice the plus and minus signs, just parse the return to determine if the extension is enabled.




回答2:


macOS 10.14 Mojave adds two useful new methods for Extension management:

The application hosting a Finder Sync Extension can determine whether the user has enabled the extension, and can show the UI for managing extensions. When the application becomes active again, it can check whether the user has enabled the extension.

@available(OSX 10.14, *)
open class var isExtensionEnabled: Bool { get }

@available(OSX 10.14, *)
open class func showExtensionManagementInterface()



回答3:


FinderSync extension is an "application", exactly. but its bundle is named as .appex. when you enable it in System Preferences, macOS will load it automatically (you can check by Activity app or ps -ef command)

So, you can easily check it by some code like:

runningApps = [[NSRunningApplication runningApplicationsWithBundleIdentifier:@"your.bundle.id"] retain];
if runningApps.count != 0{
  //your extension was enabled
}
else{
 //your extension was not enabled
}


来源:https://stackoverflow.com/questions/32944475/findersync-check-if-extension-is-selected

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!