In xcode on OSX app, I can change the app icon in the dock by using this code:
let image = NSImage.init(named: NSImage.Name(rawValue: "AltAppIcon"))
NSApp.applicationIconImage = image
But when I close the application the dock image reverts back to the original icon. Is there a way I can save the alternate icon so it will show at all times even when the app is closed? Thanks for any help.
You can implement a Dock tile plug-in. Much of the documentation for this has vanished, unfortunately. You can read about loadable bundles generally and plug-ins specifically in the Code Loading Programming Topics.
You would create a new Bundle target in your app project. A Dock tile plug-in's bundle extension must be docktileplugin. You should add a class to that target that adopts and implements the NSDockTilePlugin protocol. Set the NSPrincipalClass key in the bundle's Info.plist to the name of your class.
In the main app target, add the bundle target's product to be copied to the Contents/PlugIns directory in your app's bundle. Also, the app's Info.plist needs to have a key NSDockTilePlugIn whose value is the name of the plugin bundle.
When your plug-in is loaded, the system will call its -setDockTile: method, passing in an instance of NSDockTile for it to use. Your code can use that object to manipulate your app's Dock tile.
Related
I've implemented a drag-and-drop function in my application. The app let's you open .kext files.
I've used -(void)application:openFiles: as well as having set the Document Types:
All works well, and my app can detect when the kext is dropped. However, when a Kext is dropped, all kexts on my Mac change icon to Folder icon! I guess it has something to do with my app messing with the file associations.
Is there any way around this?
Wow, the answer was simple: Tick the Document is distributed as Bundle box in the Document Types area, and the Icon doesn't change.
I've submitted a helper application (using LSUIElement)to the Mac App Store. I was under the false impression that the App Store install process would put a dock icon for helper apps.
How can I create a dock icon that the user could remove, while the status bar app runs independently (like the popular app Caffeine)? Do I need to create a non-LSUIElement app that loads the LSUIElement app, or is there a better way?
Instead of using LSUIElement, use NSApplication's setActivationPolicy: method. By default, the application will have a dock icon, but by changing the activation policy to NSApplicationActivationPolicyAccessory, you get the same effect as LSUIElement while being able to change it programatically (the documentation for NSApplicationActivationPolicyAccessory says it is equivalent to LSUIElement=1).
- (void)applicationDidFinishLaunching:(NSApplication *)app {
if([[NSUserDefaults standardUserDefaults] boolForKey:#"HideDockIcon"])
[NSApp setActivationPolicy:NSApplicationActivationPolicyAccessory];
}
Apparently I was misinformed by my app reviewer (two of them actually). The dock icon is created for you by the install process. Pressing the issue, I was able to get the app through the review process.
I'm developing a preference pane in 10.6 Snow Leopard and Xcode 3.2.3.
As is popular nowadays, I want to add a helper application to this preference pane. Both the application and preference pane should be able to communicate in real time (notification centre, defaults database, etc).
How would I go about doing this? I'm not sure whether to make two different projects, or make one with the pref pane and add an application as a target.
Thanks!
I'd go with the second route; add another target to your existing project. That way you can make the preference pane depend on the helper application, and copy the helper app into the pane's Resources folder as part of the pane's "Copy Resources" phase.
Why is my application bundle sometimes missing its icon and/or have this "cancel" symbol over it?
alt text http://img33.imageshack.us/img33/2690/picture2oql.png
I have looked at the .plist file and the icon path and icon exist and are correct. If I right click the bundle and click Get Info, the icon shows up in the 'preview' section.
This happened after I moved around some code in my qmake file (but made no change semantically). Is this just a bug in Finder? There seems to be no way to refresh the view.
What generally causes Finder to display this cancel symbol and/or not load the bundle's icon?
That's the "You can't run this application" icon.
The finder will display that icon if:
the app is marked as being untrusted (i.e., downloaded like #kiamlaluno said)
the app the wrong architecture (i.e., PPC app on an intel machine without rosetta)
the application bundle is messed up (make an empty folder with an .app extension)
Since you're building this program, I suspect that the Finder noticed the .app bundle before it was finished compiling and thought it was broken. When you move your app to another folder, the Finder refreshed the bundle (which is complete now), and displayed the correct icon.
I have been hitting the wall on this issue for a few days now, and cannot for the life of me figure out what I am doing wrong (or if this is some kind of bug):
I have a custom Mac application (in Java, if it matters). It essentially takes a specific type of document bundle, does some processing on it, and sends the results to a server. I have everything working, except for the one use-case of a user dropping a "file" onto the application's dock icon.
Everything I have read so far seems to indicate that dropping on a Mac Dock icon uses the same Launch Services that the Finder uses. And yet, opening the Applications directory and dropping on the application there works, while dropping on the application icon in the Dock does nothing.
So, some specifics of what I have tried so far:
App handles documents with a *.foo extension, which are Document Bundles (i.e. opt-click gives "Show Package Contents" option)
Document has UTI of org.example.foo, which conforms to the UTIs com.apple.package and public.composite-content (all info copied from owner application Info.plist Exported Type UTIs key)
Info.plist declares this document type in Imported Type UTIs (UTImportedTypeDeclarations key)
Also in Info.plist, the UTI is declared in Document Types (CFBundleDocumentTypes key)
CFBundleTypeExtensions includes "foo"
CFBundleTypeOSTypes set to "****"
Cmd-Opt-drop on the Dock icon (to force the drop) does nothing. Dropping in Finder works exactly as expected. So this appears to be an issue with dropping on the Dock icon specifically.
Any ideas on what to change?
Maz has hit the heart of the issue, I think. The application is set up to run in Mac OS X 10.5 or 10.6, and the Java APIs I am using (com.apple.eawt.*) appear to be deprecated without replacements; which likely explains why it mostly works, but doesn't work in annoying ways.
It seems the actual solution will involve reverse-engineering the JavaApplicationStub executable to work with the newer APIs, and make JNI hooks so that the proper events get passed along to my application.