FinderSync check if extension is selected
Asked Answered
N

3

6

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

Nealson answered 5/10, 2015 at 8:46 Comment(4)
As far as I know, the answers to your questions are no, no, and no. I'd happily be proven wrong though.Eyed
Why would you need to check if its selected? Why not forcibly select it every once in a while? Why is the pluginkit command bothering you?Periodicity
One of the features I have to implement is to have a checkbox in app preferences dialog that the user is able to enable/disable Finder extension, and that option should be in sync with the selection from System Preferences->Extensions. I could make it like you said, but if the user wants to disable my extension from System Preferences, I do not want to override his action. Plus, I can make the two check boxes out of sync pretty easy. For now I just display a button and when clicked, redirect the user to the Extensions prefpane.Nealson
Does anybody have any idea how is the extension persisting the Checkbox value. If i uncheck the extension and remove it and add it again, it remains unchecked, and if i check it before removing and adding it again, it remains checked on adding again.Supple
G
9
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.

Gauntlett answered 13/10, 2015 at 17:18 Comment(0)
L
3

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()
Lattimore answered 14/8, 2018 at 1:23 Comment(0)
U
-2

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
}
Ullund answered 11/9, 2017 at 3:34 Comment(1)
The system can manage multiple instances of a Finder Sync Extension and arbitrarily start / stop these processes. Therefore it’s not a good approach to check for a running application with a given bundle identifier.Pants

© 2022 - 2024 — McMap. All rights reserved.