Jump to content

Handling files "open with" from finder


7 posts in this topic

Recommended Posts

Does anyone know how to handle files with finder "open with" in our program? Say someone wants to open .png pictures with our program. What gets called first? Do we use pasteboards to handle this?

 

Thanks in advance.

 

its handled by filetype and creator, edited in finderflags, creatorchanger is an app for it.

unlike windows they arent visible

Link to comment
Share on other sites

Does anyone know how to handle files with finder "open with" in our program? Say someone wants to open .png pictures with our program. What gets called first? Do we use pasteboards to handle this?

 

Thanks in advance.

 

What language? For objective-C look at NSApp:

- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename;
- (void)application:(NSApplication *)sender openFiles:(NSArray *)filenames;

Link to comment
Share on other sites

Dear westwaerts:

How do I edit the finderflags? Is it like one of those document based cocoa project where there's a file which you can edit to specify the filetypes your app would handle?

 

Dear PascalW:

It'll be obj-c. I think your solution is what I'm looking for. Thanks!

Link to comment
Share on other sites

Hi PascalW, your solution works! and it's pretty nice considering it won't launch another instance of my app if one is already running. My problem right now is registering the recommended file type. Right now I would get a message saying "It is not known if this application can open PNG files" and my app can only be chosen if I choose All Applications in the enable combo box. Anyone knows a solution?

 

And my guess that it would allow dropping files into my app icon on the dock once I register the file type handling to finder?

Link to comment
Share on other sites

My problem right now is registering the recommended file type.... Anyone knows a solution?

 

And my guess that it would allow dropping files into my app icon on the dock once I register the file type handling to finder?

 

Yes you should register your app as being a editor/viewer for a filetype.

 

Put something like this in your info.plist:

 

<key>CFBundleDocumentTypes</key>
<array>
	<dict>
		<key>CFBundleTypeExtensions</key>
		<array>
			<string>png</string>
		</array>
		<key>CFBundleTypeIconFile</key>
		<string>png</string>
		<key>CFBundleTypeName</key>
		<string>png</string>
		<key>CFBundleTypeOSTypes</key>
		<array>
			<string>png</string>
		</array>
		<key>CFBundleTypeRole</key>
		<string>Viewer</string>
		<key>LSTypeIsPackage</key>
		<false/>
		<key>NSPersistentStoreTypeKey</key>
		<string>XML</string>
	</dict>
</array>

 

You could also specify this in Xcode, somewhere in project or active target settings.

 

And yes, if you register your app like this, the registrerd filetypes can also be dropped on the dock icon.

Link to comment
Share on other sites

 Share

×
×
  • Create New...