Associate a file and set a file icon

Its been a few years since I last tried this, and can’t remember the precise juju I had to use.

My new app has been given a bundle identifier
com.mycompany.appname

I added a file type
I gave the MacCreator the same creator code as I always use.
I gave the MacType a new type different from any old one
I added file icons for all sizes.
I set the app as editor role for files of this type.

When I save a file, it gets no icon.
When I use Get Info, it suggests opening with one of my older apps: presumably because the Creator code is the same.

What have I missed to get .newextension associated with new product.app ?

Its gotten a LOT more complex since Apple moved off using type & creator.
Basically you need to add a UTI entry

Got one.

The user guide says give the app a bundle ID

com.mycompany.myapp

to set the file type to be creator = ??? type = ???
To set the UTI to be com.mycompany.myapp.myextension

and then to edit the plist file.
… which appears to already contain the things that the user guide tells me to add.

But still nada.

[quote=129794:@Jeff Tullin]Got one.
[/quote]
I mean a UTI entry in the app plist which is a lot more than what the IDE can do for you right now
For instance in the IDE we add, using a post build script, entries for all the document types that look like

CFBundleDocumentTypes


CFBundleTypeName
Real Studio Project
CFBundleTypeIconFile
REALbasicProject.icns
CFBundleTypeOSTypes

RbBF

CFBundleTypeExtensions

rbp

CFBundleTypeRole
Editor

one for each document type we want to associate with the IDE

Thats whats required now instead of just the old IDE type & creator

Ive given App Wrapper a crack at it too. Still doesn’t work.
Surprising there isn’t more chatter about this.

I’m not familiar with what app wrapper does / doesn’t add

I assume since so many people us it it does it correctly

Sometimes you have to move your app from where it is to another location to beth the OS to realize it needs to reread the plist and therefore recache the launch services entries that do the association

and yes, its a LOT more complex that it used to be for the classic mac os style where you set a type & creator and you were done

[quote=129821:@Jeff Tullin]Ive given App Wrapper a crack at it too. Still doesn’t work.
Surprising there isn’t more chatter about this.[/quote]

I do not think App Wrapper can do anything for that.

A simple way to do it is to build your app, then in the bundle get the info.plist file, move it next to your project, and add to it in a text editor the lines Norman displayed, with the information pertaining to your particular app. You can also double click on info.plist and do it in XCode plist editor.

Then use a CopyFile build step to replace the default info.plist by your modified one after the build (the gear in Build Settings/OS X).

AppWrapper works just fine for creating UTIs (it’s little brother Mini however does not handle UTIs)
I’d show you a screenshot, but my trial is up and I have to wait for payday to get a license.

You can add them manual, via a script, using a tool like app wrapper

just not in the ide right yet - its on the “to do list” though since it would let us consolidate a few things in the IDE and make something like this a lot simpler

[quote=129868:@Tim Parnell]AppWrapper works just fine for creating UTIs (it’s little brother Mini however does not handle UTIs)
I’d show you a screenshot, but my trial is up and I have to wait for payday to get a license.[/quote]

That’s right. I found it, in Documents.

Indeed it can be used to append UTIs to the plist when you wrap your application.

I would suggest making sure that you don’t have any ‘old’ versions lying around so that Launch Services picks up the correct copy of the application. When you open the application, it should update the Launch Services database and associate the file to your application.

Hi Sam.
Yes, I found the option.
It offered to build a UTI and looked like it had succeeded.
But my documents remain firmly un-iconned and un-owned.

What I don’t get is how to associate the UTI with a file at the time it gets saved.
(I used to add maccreator and mactype to the folder item at the time of saving.)
I can’t find any similar ‘use this UTI’ option when I create a file: so at the moment I’m saving with a unique extension (that is defined in a filetype although the filetype doesn’t get mentioned when I save the file) and wishing on a star.

Maybe this is the bit thats missing?

[quote=129918:@Jeff Tullin]Hi Sam.
Yes, I found the option.
It offered to build a UTI and looked like it had succeeded.
But my documents remain firmly un-iconned and un-owned.

What I don’t get is how to associate the UTI with a file at the time it gets saved.
[/quote]
There’s the rub - you don’t :stuck_out_tongue:
LaunchServices does that for you based on the information in your apps plist for the UTI
Kind of like how the old Mac desktop DB did it based on type & creator
So you basically create the file & set the extension to the one you put in the UTI and you’re done
Every thing else is handled for you BUT as sam noted the LS db MAY have old cached versions and its sometimes hard to force it to update them

Guess I need to sacrifice a cockerel at a crossroads then.
Appwrapper adds what seems to be a duplicate set of definitions.
And the plist generated doesn’t match the instructions in the Xojo docs about adding UTI information into the info.plist

As far as I can tell, this should be doing the trick

UTExportedTypeDeclarations


UTTypeConformsTo

public.data
public.item

UTTypeIdentifier
com.mycompany.myapp.myappFiles
UTTypeTagSpecification

public.filename-extension

myext


CFBundleTypeIconFile
myappFiles.icns

Make sure all your file extensions match, from the file types in Xojo, your saved files and your UTI.

UTIs just encompass several different ways of determining file types.

  • Mac Type & Creator
  • File Extensions
  • MIME types
  • OS X Pasteboard types

And wraps them up into a single piece of information for you to check. In theory if the UTI is added to your application, any file that matches the above settings should be viewable to your application.

Oh and make sure your application has a Bundle Identifier!

Progress. I hadn’t checked the ‘obvious’, only the technical.
I found I hadn’t added an OpenDocument event handler yet.

Now that I have, OSX has registered that my app can open my files, and double clicking works.
Just the icons to go now. :slight_smile:

Awesome!

[quote=129927:@Jeff Tullin]Progress. I hadn’t checked the ‘obvious’, only the technical.
I found I hadn’t added an OpenDocument event handler yet.

Now that I have, OSX has registered that my app can open my files, and double clicking works.
Just the icons to go now. :)[/quote]
Well done
And now you can see why a UTI editor IS definitely on the TO DO list
This is a pain in the butt to have to do externally

So many things to do - so little time

Anyone put in a feature request for 100 hours days yet ?

Yes. Already six years ago and nothing has been done about it.

See feedback case 666

:stuck_out_tongue:

Huh. Part timers… :wink: