Mac Filetype troubles...

I’m working on a Mac desktop app using latest Xojo 2017r2 on Mac with latest Mac OS. I’m working on a new version of an existing app (MyApp). I have v1, v2 and v3 of this app. In my latest (v3) version of the app, I have an option that allows a user to convert any of his or her older v1 or v2 documents to v3 status, and I have a FileTypes resource setup in my project with all the presumably correct info detailing the v1, v2 and v3 documents. If the user chooses to convert an old document to a new format, I pop up an Open dialog asking him to navigate to the document, passing the Open dialog the correct FileType, etc etc.

If I run the program on MY Mac (within Xojo or as a fully built app), I CANNOT convert v1 docs to v3…I can’t see them. I pop up a dialog box asking the user to navigate to a v1 doc, but when he does, that doc is dimmed out and NOT able to be chosen (even though it IS the correct document type). The convert v2 to v3 (written in the same exact manner) DOES work on my Mac.

Now, here’s the curiosity…

If I send a fully built test app to a friend of mine also with a Mac with same OS along with a copy of some v1 documents, he has absolutely no trouble finding and converting the documents as requested. (They’re seen in the Open dialog.)

So, my conclusion, is that my Mac is messed up in some way. I’ve tried rebooting (no help), I’ve tried rebuilding permissions using Disk Utility and more…still no help. The Convert option in MyApp’s OPEN dialog box does NOT show v1 docs on my Mac as being selectable, but does on my friend’s Mac. (and this used to work on my mac too, of course)

I’m wondering if somehow how my mac handles file associations is messed up, or I somehow mangled the database that supports such associations or something like that. And, if I could just reset that info somehow, I’d be back up and running (though left with a mystery as to what corrupted or messed things up for me in the first place!) Anyway, is there a way to safely reset file associations on a Mac? Is there a utility for such a thing? Or am I simply on the wrong track and there’s another approach I’m missing (very likely)? Thanks for any thoughts…

Gotta love launch services

this is often a symptom of a messed up launch services db

let me find the references to debug this

EDIT : ok the terminal command you want is
mdls [file]

this will tell you what app the OS THINKS should open the given file
and if its not the one you think it SHOULD be then you may need to use lsregister to register the one you think it should be (and you may need to purge the launch services db of specific entries) unfortunately lsregister has no man page but there is lots of references to it on the internet

what can happen is you have several apps registered to handle a file and one (or more) is not active

for instance I often have many versions that I’ve used over time and they end up with some active and some not like the following

[code] type id: 207580
uti: com.xojo.project.legacytextproject
description: Legacy REAlbasic plain text project
flags: exported active trusted
icon: Contents/Resources/PlainTextProject.icns
conforms to: public.plain-text, com.xojo.project
tags: .rbvcp, ‘RBVC’
--------------------------------------------------------
type id: 211324
uti: com.xojo.project.legacytextproject
description: Legacy REAlbasic plain text project
flags: exported inactive trusted
icon: Contents/Resources/PlainTextProject.icns
conforms to: public.plain-text, com.xojo.project
tags: .rbvcp, ‘RBVC’

[/code]

EDIT the other command that is handy is
/usr/bin/mdimport -d1 [path to file here]

and this will tell you what UTI the meta data has identified this document as conforming to

Norman, it’s been said many times (no doubt, at least by me!) but you da man!!! Thank you Norman. I believe my problem is largely fixed. To tell you the truth, most of what you said went over my head, but you certainly pointed me in the right direction. When you mentioned Launch Services as being the likely culprit, I remembered I had a free utility called Onyx, and of the maintenance tasks it includes is the ability to rebuild lots of things…including the LaunchServices database. I ran it, and voila!!! I can now run MyApp and choose the required document types in my OPEN dialog. I still don’t know what I did to somehow wreck that database, but at least I’m back up and running. Thanks again. You were right on the money.

One of the causes is incorrectly specified UTIs. For instance if you were to add a filetype with the UTI “public.jpeg” and make it exportable, yet have no role specified in the file types selection dialog; the file type becomes broken.

I’ve reported it to Apple after I found that I had done it by accident; suggesting that they prevent this from corrupting launch services as was told not to do it again.

The rule of the thumb is that you should mark a UTI as exportable if those files are specific to your application.

Thanks Sam, and Norman too. I’m still debugging things here. With Norman’s push, I was able to rebuild LaunchServices, and at least at first, get things working again. But, then I found other related failures crop up. So, I’m still debugging, I think I have something inconsistent in my own code that is messing up my file types. But, at least now, I have a method to repair, debug and re-test.

In debugging, I’m examining my FileTypes set, and I noticed that the UTI popup help text mentioned a UTI should include only the characters A-Z, a-z, 0-9, a period or an underscore. For years, in past and current versions of my apps, I’ve been using a dash ("-") since my company name happens to include a dash, e.g. “com.first-second.MyApp”. It seems to work just fine, and if I look in my Library’s Preference’s folder, I see all my plists (for instance) with the dash in the name seeming to be no problem at all. I also notice that at least in my own Preferences folder,mine seems to be the only app that included a company name with a dash in it. Anyone know the ramifications of this oversight on my part? (there seems to be none, to me, but that surely doesn 't mean there aren’t any!)

in plist files etc its not nearly as important as file names can accommodate the dash

the naming conventions for UTI’s though are ones we just pass on from Apple

I dont believe they have to match - but I’m also not 100% sure of this

Thanks Norman. Now that I found out about it, I’ll fix it on new apps, live with it on old apps.

I’m still having trouble with my OPEN dialogs being able to see some but not all of the files I need to open. My current area of confusion is again in the FileTypes within Xojo. As mentioned in the start of this thread, I’m developing on a Mac for Mac using latest Xojo and latest MacOS.

I’m developing v3 of MyApp. Each version of MyApp is really a brand new application and it creates its own document in its own format. In each new version of my app (really it’s a new application each time), say v3, I like to offer the user the opportunity to convert his older v1 or v2 documents into v3 format. Thus I have to be able to OPEN up those files in order to convert them.

So, please correct me if I am wrong, I think I thus need to include 3 entries in my FileTypes resource. One for the current v3 document that I must open, read and create, and one for the v1 and one for the v2 documents which I need to open and read. At the moment, each of these filetypes has its own name, UTI, description, etc.

1 - I’m a little confused about whether the UTI type of each filetype should be chosen to be IMPORTED or EXPORTED.

I’m assuming, (is this right?) that the v1 and v2 filetypes should be marked as IMPORTED since v3 of MyApp does NOT specify, create or define the format of these files, it just should be able to open them and read them (to convert them). The v3 filetype entry I’ve marked as EXPORTED, since MyApp DOES create and define this file. Does this make sense?

2 - Also, come to think of it, in a sense what I am really doing is just trying to open a file (v1 or v2) that was created with another application (OK, it happens to be an earlier version of the program I’m working on, but it’s still ANOTHER program.) And, if so, in my FileType entry for the v1 and v2 files (which I’d like to open but not create), I’m wondering if I even need to specify their icons (which the FileTypes Editor seems to imply you should), or the UTI’s, and more. Maybe I just need the OSTYPE and EXTENSION. After all, if I wanted to open up, say, an EXCEL spreadsheet file (which I have nothing whatever to do with its creation), I sure wouldn’t think I would have to be responsible to recreate their icon, or know the UTI they specified, etc. So, if I just want to be able to OPEN up a file with a certain extension that my program (v3) did NOT create, what do I need to specify for its filetype entry?

Thanks for any help!

a file format defined by some other app, like Adobe defined PDF, should be IMPORTED
old versions of your app are typically considered “some other app” - so they would be imported
and your new v3 format should be EXPORTED because THIS version of the app defines it

but you might try to avoid creating a new uti every time
for instance in the text and xml formats for xojo projects we have an entry that says “i’m this version”
so while the version of the contents might change we dont need to new uti every time

yes - but also see my additional remarks about this

[quote=345922:@Ken Winograd]2 - Also, come to think of it, in a sense what I am really doing is just trying to open a file (v1 or v2) that was created with another application (OK, it happens to be an earlier version of the program I’m working on, but it’s still ANOTHER program.) And, if so, in my FileType entry for the v1 and v2 files (which I’d like to open but not create), I’m wondering if I even need to specify their icons (which the FileTypes Editor seems to imply you should), or the UTI’s, and more. Maybe I just need the OSTYPE and EXTENSION. After all, if I wanted to open up, say, an EXCEL spreadsheet file (which I have nothing whatever to do with its creation), I sure wouldn’t think I would have to be responsible to recreate their icon, or know the UTI they specified, etc. So, if I just want to be able to OPEN up a file with a certain extension that my program (v3) did NOT create, what do I need to specify for its filetype entry?
[/quote]
unless you want the new app to redefine the icons you can leave imported icons blank

and what you really need is the extension & uti - the ostype is pretty much ignored now
you’ll want the name & description fields filled in as well

there’s a long list of “well know uti’s” on apples site so its not too hard to know what they might be

Thank you Norman. You’ve cleared up a lot, and I’ve learned a lot. Thanks for taking the time to help. BTW, I found TWO problems. As you know, I’m working on TWO versions of the same program (say, v2 and v3)…v2 is published, v3 is being worked on. Every time I tried to do a fix on one and then used the other, things (file associations) got screwed up. Thanks to you (and the utility Onyx), I could rebuild LaunchServices and get things back to normal, try some fixes and see if they worked. Ultimately, if you’re curious, I found a typo in a UTI…so I had two programs both initially having UTI (that were EXPORTED, when only one should have been) and they had different UTIs (one with a typo) as well…so what would work the first time (no matter which program was tried), failed if I ran the other program. Not sure if I’ve explained it properly, but I’m back up and running, bug fixed, and programs improved. Thanks again.