Reset NSToolbar back to default configuration - objective-c

I programatically create an NSToolbar in my application. I just added a new button to the toolbar and added that button to the default configuration of the toolbar. When I run my application the new button is not shown by default. That's because I already have been using the program and I already have a plist file in which this new button is not setup to be shown.
So my question is how can I get the toolbar to reset its current configuration back to the default configuration so that my button will be shown automatically for people who have been using the application.
I guess I could delete the entries in the plist file to force the program to recreate them and thus use the default configuration... but I was hoping there was was some command I could issue to reset it. I didn't see one in the NSToolbar class.
Thanks for any help.

If you add a new button to your toolbar's default configuration it will not appear for users which have customized the toolbar and have settings stored in the user defaults.
If you want to force the new default toolbar on users which have perviously customized the toolbar, changing the autosave name (by appending a version number, for example) is the way to do so. (Consider whether you want to blow away your user's toolbar customizations though.)

Well I deleted the appropriate key in the plist file and it worked. I'd still rather know a better way so if you have any better ideas let me know.

Related

How do I disable my application from participating in the ⌘+tab cycle on macOS?

I'm trying to write a small utility that attaches itself to the current main/key window. I've managed to make sure that the window cannot become key or main window, but it still shows up in the list of active applications when I use ⌘+tab.
The application should still be in the dock (so you can quit it and do other interactions), but I would rather that it didn't show up in the application list when pressing ⌘+tab.
I thought I had the answer when I discovered NSApplicationPresentationDisableProcessSwitching, but alas, that's system wide(!) which is certainly is not what I want.
Add "Application is an agent (UIElement)" to the Info.plist (raw key: NSUIElement) to remove yourself from the dock. Then create a status bar item (NSStatusItem) to hold your menu.

How to hide the automator application icon when running

I create a automator application and set it to run at logon, and I check the "Hide" box, but it still shows up (the gear icon) in the status bar. How can I hide it?
I check the "Hide" box here:
but the gear icon is still shown (the worse part is that it never stops rotating!)
Is it possible to hide this icon, or let it stop rotating?
control-click on it, and choose Show Package Contents from the pop-up menu. Inside the Contents folder, open up Info.plist, and change LSUIElement from No to Yes (if using Property List Editor) — or change the line after the LSUIElement key line to (if using a text editor). Save Info.plist.
Now when the alarm triggers, the Automator plugin will run in the background, without a Dock icon or a menu bar, and the focus will remain on the application you’re using.
Three things to note:
You might have to move the plug-in out of the iCal folder and back in
for this to work. Tiger caches the LSUIElement info; moving the app
forces Tiger to renew the cache.
You probably do not want to do this with any iCal plugin that has
dialogs or requires user interaction! This works best for maintenance
actions, automated downloads, and that sort of thing.
Third, this will work with any Automator workflow that is saved as an
application, not just with iCal plugins.”
Then Clear your Cache

How to create a background only program that can show a window with text fields

I want to create a program that consists of just a menu in the status bar (no dock icon or menu bar) that, when the user clicks on menu items, opens a window that allows the user to enter text (NSTextField and NSTextView).
I can make the program background only by setting the "Application is background only" property to YES in my Info.plist file, however, when I do this and display a window, firstly the window always appears behind other windows, and secondly I can't type any text into it (text goes to whatever last had focus - usually a source file in Xcode!)
This is definitely not something as simple as the fields are not enabled. Simply changing the "background only" property to NO fixes the issue, but then I get a dock icon and menu bar which I don't want.
Is what I'm trying to do possible or is there something about the background only mode that means my application can never receive text?
If it is possible what do I need to do to fix this?
From the documentation for LSBackgroundOnly:
You can use this key to create faceless background apps. You should also use this key if your app uses higher-level frameworks that connect to the window server, but are not intended to be visible to users.
So when they say “background only”, they mean background only.
The key you want is LSUIElement. Xcode describes this as “Application is agent (UIElement)”.
I personally can't stand Xcode's default behavior of showing me descriptions of some of the keys' meanings. I recommend turning on “Show Raw Keys/Values”; then, Xcode will show you the real keys being used in the dictionary.

How to dynamically add fields to a NSView similar to iCal New Task popup?

I'm trying to implement a NSView which will host a 'choose file' attachment button. If the user chooses to add a file, the user will be given an option to add another one (and from the 'new set of dropdowns' the user will essentially be able to pick the kind of file they're attaching').
The closest match to this functionality is iCal's New Task editor where you select an alarm and then it gives you an option to add another alarm right underneath.
What is the right way of doing this (I'm new to Mac OS X development)? I originally thought I'd create a custom NSView with all the 'file options' and then if the user was to attach a file I'd dynamically add another NSView right below it (in a NSScrollView). However so many apps do something similar that I almost feel as if there's something else out there in the set of controls that I should be using.
Please can someone guide me to the right direction? Is 'NSForm' or NSPredicateEditor used for this sort of stuff? This is what I mean:
Neither NSForm nor NSPredicateEditor would be useful for what you want to do. I think your thoughts about how to do this by adding a custom view below the original view, is the right way to go. You don't necessarily have to do it in a scroll view, you could expand the size of the window like iCal does.

Changing the Trashcan icon in the dock

Is it possible to write a program for Mac OS X that monitors the trashcan and changes the icon dynamically when you fill the can?
Yes, it's possible. Candybar does it. I expect that rather than dynamically changing the icon, they just register a new 'empty' and 'full' icon with the Dock process.
Panic's Candybar lets you customize system icons (including the trash), so it must be possible.
The NSDockTile class allows you to make changes to your application's icon in the dock:
http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/NSDockTile_Class/Reference/Reference.html
The Trash is actually a hidden folder in the user's home folder called .Trash
I guess you could monitor whether or not it's empty by periodically finding the size of the folder. Or you could run ls using NSTask, and find out whether there are any files left in it.