Registering a file type or extension

Archives Forums/MacOS X Discussion/Registering a file type or extension

remz(Posted 2006) [#1]
Does someone know how an application can tell Mac OS that it supports a certain file type?
I'm writing a picture browser in Bmax, and I would like to have the possibility to double-click a JPG in the Finder that'll launch my app.
However, my app doesn't appear in the 'Open with' finder popup, and if I choose 'Other...', my app is not shown in the 'recommended application' list.

So:
How do you make Finder know that your application supports a file type?


remz(Posted 2006) [#2]
Eureka! I found something, thanks to another post:
Inside the app (show package content), you can edit
Info.plist
There it is possible to inform Finder that your app can support some file types. Great!

But alas, this file gets stomped everytime you compile.
Would there be a way in BMax to insert those Info.plist entries so that they would be kept?

Anyway for now I can copy / paste my plist after I compile, so the main issue is 90% solved.

I can post the detail of what to edit in info.plist if anyone cares.

Rem


SebHoll(Posted 2006) [#3]
Hi,

Does someone know how an application can tell Mac OS that it supports a certain file type?

I was wondering this just the other day, but hadn't got round to asking the community yet. ;-)

I can post the detail of what to edit in info.plist if anyone cares.

If you wouldn't mind, that would be really useful.

Would there be a way in BMax to insert those Info.plist entries so that they would be kept?

I hope so!!!



Thanks


Seb


ozak(Posted 2006) [#4]
What exactly do you need to specify in the plist?


remz(Posted 2006) [#5]
I'll describe it, here you go:

Add CFBundleExecutable, type String, and enter the name of your app. This allows your app to be renamed and still work.

Add CFBundleIdentifier, type String, and enter something unique related to your app. I suggest something like com.brl.YourAppName. This allows associating a file extension correctly with Finder.

Add CFBundleDocumentTypes. type Array.

Inside it:
Add a child (named 0), type Dictionnary. This will be your first associated file type.

Inside this child:
Add CFBundleTypeName, type String, and enter the name describing this file extension that will be shown to the user in Finder in column Kind.

Add CFBundleTypeRole, type String, and enter Viewer or Editor depending on what your application do with the file. (i.e.: if your app can save a document with this extension, use Editor.)

Add CFBundleTypeExtensions, type Array

Inside this array,
Add a child (named 0), type String, and enter the extension (i.e.: jpg). If you want several extensions associated with this same file type, you can add more, like jpg, jpeg, jpe, j2000, etc.

Done! Repeat these steps if your app supports several different file types.

Tips:
- Remember that each time Blitzmax compiles your app, your plist entries will be overwritten. My tip is to edit a separate plist, and keep a Terminal Window open that you can use to copy your plist inside your app after each compile.
- Be warned that modifying a plist does not update Finder. You must manually 'touch' your app using touch from a Terminal Window.
- File extension are not case-sensitive, even though Apple own Preview.app describes JPG and jpg. Maybe older Mac OS X were case sensitive?


Diordna(Posted 2006) [#6]
You cannot have it automatically insert the plist into your app because it is a platform-specific thing. You're going to be stuck with copying it into the bundle every time.


Garrett(Posted 2006) [#7]
The easiest way of setting up an info.plist file is to get an app that already
uses the same extensions as you want to use. Right click on that app and
select "Show Package Contents". Then navigate into the "Contents" directory.
Then open the "Info.plist" file there and examine it for the file associations.

Instead of doing this manually for own app everytime you compile, you could
easily write your own app that will drop an info.plist file into your newly created
apps after you've compiled them from BlitzMax.

The .app programs in OS X are just a directory that contain all the files needed
for the program. Using functions in the 'File System' module in BlitzMax will
allow you to do any file actions as you would normally in any other directory on
OS X.

For that fact, you can change your apps icon doing this also. A few months
back I made a little app that changes the menubar images of a little program
called "DiskSpy" and "DiskSpy Solid". It uses images in the "Resources"
directory of it's package on the menubar of OS X. The program is a monitor
for disk activity, and the "Solid" does that and internet activity. But the
author did not make any program that allowed you to change the themes
that are included with the program, and constantly having to use Finder to
open the .app to change themes is a pain.

And while you're at it, you might as well include the ability to change the .icns
file of your newly created BlitzMax app along with the plist file. Kill two birds
with one stone.

Being a bit new to BlitzMax (Less than 24 hours) though, I do not know if you
can include your own tools in the IDE for accessing, or if it's possible to have
your own tools executed before or after a compile has taken place. If it does,
then you've got it made.

-Garrett