FinderSync issues with sidebar icon, toolbar icon and context menu - objective-c

I am developing a mac app that must provide support for FinderSync application extension. Everything works fine, except some sidebar and toolbar icon issues.
Is there a way to programatically add the toolbar and sidebar icons without user intervention?
As from documentation, I didn't find anything to help me do that. They refer to these icons, by mentioning that the user must manually drag the folder manually to sidebar, or manually customize the toolbar, but not API to achieving this at runtime.
However there are apps that add themselves back if someone removes them from the toolbar.
Is there other way to display an icon for my folder, except iconset? I noticed that there are other apps out there which do have an icon in the sidebar, but they do not seem to have an icon set in bundle resources and the CFBundleIconFile is set to an icns resource.
Is there a way to disable a menu item in menuForMenuKind: ? In a normal NSMenu situation, the menu item should have no action or target, but this is not the case. Even if I do so, menu item is still enabled.
Thanks a lot for your help!

Welcome to the world of pain.
I've been developing Finder Sync extension as well, so here are answers to your questions:
Now I'm searching for the way to add programmatically Toolbar button, I saw some phrases that this can be done.
To add item to sidebar, you should use some LSSharedFileList code:
Add Item to Finder Sidebar
Via the same API you can check if your item is present in the sidebar, and do not add the duplicate.
Now (since Mac OS X 10.11) sidebar icon can be changed only via iconset. Previously it was possible to change it via Finder code injection, which is not allowed in 10.11.
Just use [menuItem setEnabled:NO]. Also please note that not all menu stuff is available in 10.10 - for instance, checkboxes are not shown and separator item is shown as space. Also, sender parameter in your handlers is always empty NSMenuItem object.

Related

Custom Menu for Mac Catalyst App in Obj-C

Can anyone help with an example on how to configure the menu for a catalyst app in Objective-C. The main intend is to get rid of most of the menu items.
Select your Main.storyboard for your project. Near the upper right hand corner, there is a + button to add objects from library, click that button and search for Main Menu then add it to your Main.storyboard. From there you should be able to select items and delete the unwanted ones. I believe you won't be able to remove the Application menu.

Adding a toolbar button to Finder.app programmatically (macOS)

I am looking for a way to add several toolbar buttons to Finder, which, when clicked, perform certain actions.
My research shows that injecting code into Finder process is impossible on latest versions of macOS due to SIP, yet this would be the most seamless way for the user.
There is a possibility to add a toolbar item by creating a Finder Sync extension. However there are 2 problems:
There can be only one toolbar button per extension (I need several buttons)
The toolbar button will have a dropdown arrow (see an image below). I do not need to show a menu, however, and therefore this arrow makes the button misleading. It must be a simple plain button that matches the current system theme and performs an action upon click.
So this is what I don't need (because of the drop down arrow):
Update:
One of the ways to add a button, is drag and drop an .app bundle, holding Command key.
This approach has the following problems:
This button wouldn't match the other toolbar buttons look&feel, as the icon for such button is taken from the .app bundle (so it wouldn't switch based on macOS light/dark theme, for example)
It is impossible to add several toolbar buttons like that (as there needs to be one .app per 1 button). However, I need multiple buttons.
I am wondering if FinderSync allows creating "normal" (non menu) buttons
Is there a way to add a regular button to Finder's toolbar?
Please check out my Finder buttons:
https://github.com/lexrus/LTFinderButtons
Basically, I made every task a button app.
I'm trying Finder Sync Extension to do the same thing. All issues you found are true. Furthermore, there's problem #3:
You can not submit an app with Finder Sync Extension to the App Store.

Use LSUIElement (aka no Dock icon) but retain the "File, Edit, View" menubar?

I want my app to have:
Menubar extra icon (by the clock)
App Menubar ("File, Edit, View, Etc")
I do not want my app to have:
Dock Icon
Is this possible? I am deploying for 10.6 and 10.7 via the Mac App Store if that matters.
Setting LSUIElement in the info.plist file removes the dock icon, but it also removes the menubar.
NSApplication's setActivationPolicy might be what you are after.
[NSApp setActivationPolicy:NSApplicationActivationPolicyAccessory];
Please note the discussion:
Currently, NSApplicationActivationPolicyNone and
NSApplicationActivationPolicyAccessory may be changed to
NSApplicationActivationPolicyRegular, but other modifications are not
supported.Needs links to running application
As per NSApplicationActivationPolicyAccessory's documentation you may need to programmatically ensure that the menu bar appears.
You could create two "separate" applications. One that has a dock icon and menu items,the other one has just the icon by the clock.
When you click on the icon by the clock it launches the dock application. When you close the dock application the 'background' application stays running.
If that model will work for you then that's the way to go. But I would weigh that effort against what File-Edit-View will do for you.

How to get the Spotlight-like text input effect in menu bar?

I want to have an icon in the menubar in my Mac app - and the icon should spawn a menu upon clicking. While having more entries in the menu, I would like to have a top row as a universal text entry field - like it is in Spotlight:
http://dl.dropbox.com/u/3943878/_mine/Screen%20shot%202011-07-16%20at%2012.29.18.png
Is it possible to add such a field to NSMenu? Or should I do it as a panel-type window?
If you're using xcode 4 , make a custom view in interface builder and add a textfield or anything you want to it. In IB also drag and drop a "Menu" from the objects library with as many items as you want in it. Then simply ctrl+click the menu item you want to make into the text field (In your case it would be the top one) and drag to the custom view and select "view". Now when you open the menu, instead of showing a menu item in that space, it shows whatever was in your custom view.
EDIT: As for your comment here's what you should do. Make your menu an outlet by opening the assistant editor view and ctrl+click from your menu to the header file that you want to use. now, simply make a method that will run whenever the menu will open, conveniently apple already made this, it's called menuWillOpen.
- (void)menuWillOpen: nameOfYourMenu{
[self performSelector:#selector(methodExecutedWhenMenuIsClicked) withObject:nil afterDelay:0.0 inModes:[NSArray arrayWithObject:NSRunLoopCommonModes]];
the delay at 0 will make it happen immediately, it must be done in the common modes run loop so that the menu will be updated even while it's open. Now just make the methodExecutedWhenMenuIsClicked and set it so the text field responds.
- (void)methodExecutedWhenMenuIsClicked{
[[yourTextfiled window] makeFirstResponder:yourTextField];
You can put any view in a menu using -[NSMenuItem setView:]. See the long comment in NSMenuItem.h and the section Views in Menus in Application Menu and Pop-up List Programming Topics.
You're probably going to struggle quite a bit. I just tried doing the same thing, and reading the Views in Menus in Application Menu and Pop-up List Programming Topics document referenced by Ahruman, I found this:
A view in a menu item can receive all mouse events as normal, but keyboard events are not supported. During “non-sticky” menu tracking (that is, manipulating menus with the mouse button held down), a view in a menu item receives mouseDragged: events.
I think we're SOL. Apparently Spotlight pops up a borderless window instead.

NSTextView not responding in an app without dock icon

I have a menulet app with an NSTextView in it. I don't want the app to appear in the dock, so I wrote
<key>LSUIElement</key>
<true/>
in the Info.plist file.
But if this option is enabled, somehow an NSTextView in the menu stops responding at all.
How can I make it respond again? Maybe there are any other ways to hide the dock icon?
Thank you!
IMPORTANT UPDATE: This bug has been spotted only on Mac OS 10.6 and higher
The documentation states that keyboard events are not supported in views that are attached to a menu item (see Application Menu and Pop-up List Programming Topics).
That said, I had no problem creating a minimal sample app without Dock icon and a text view embedded in a status item's menu, so your problem is likely somewhere else. You can download my sample app here.