My app is able to extract .deb files but only if you specify where with buttons in the app. But I want to be able to just click on a .deb file and have my app open up, run the actions I already have, then quit when it's done. Right now I'm using NSWorspace to tell my app it can open .deb files but I don't know how to have it run my actions from that. Is using NSWorkspace even the right thing to do? I also need to be able to get the Filepath of the file being opened in string format and I can't seem to fighure this out?
I did some testing and this might be of interest to others, too. Solution is lined out by a little example.
Create a new Cocoa project in Xcode, go to the xib and add a label to the window. We will use it for a proof of concept. Next, some stuff to your app delegate. Interface:
#import <Cocoa/Cocoa.h>
@interface fileClickerAppDelegate : NSObject <NSApplicationDelegate> {
NSWindow *window;
NSTextField *fileName;
}
@property (assign) IBOutlet NSWindow *window;
@property (assign) IBOutlet NSTextField *fileName;
@end
The implementation is pretty straight forward:
#import "fileClickerAppDelegate.h"
@implementation fileClickerAppDelegate
@synthesize window;
@synthesize fileName;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
}
- (void)application:(NSApplication *)theApplication openFiles:(NSArray *)filenames {
[fileName setStringValue:[NSString stringWithFormat:@"Wow, even multiple files like %d :-)", [filenames count]]];
}
@end
There is one method to keep an eye on:
application:openFiles.
Guess what it does? It receives a list of files passed from either having clicked on an item on the desktop or in the finder, or having dragged files onto the icon. It will be passed an array with the filenames, along with the paths, UNIX style.
My tests did not require to set "Document types" in the plist of the app, or doing fancy registration stuff with the finder. Of course, this could add...
That should fix your problem and you can do whatever you want with your .deb files (I assume debian packages?).
Good luck!
Living
P.S.: Just do not forget to hook up the NSTextField to the GUI control ;-) Otherwise, it will work but nothing is displayed....