OS X File Association Quirks

Deploying to Mac OS? Ask Mac OS specific questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
SirWobbyTheFirst
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 239
Joined: Tue Jun 30, 2009 11:15 pm

OS X File Association Quirks

Post by SirWobbyTheFirst » Wed Nov 23, 2011 3:34 am

Hey everyone, long time no speak.

I'm back with a little question involving an OS X quirk, I've built an application similar to Revolution Player and Stack Runner by STS and added a couple of command line arguments and a set of functions to get information about the host OS and whatnot. My application is designed to perform some initialisation tasks such as actually loading the functions library into the memory and placing it into the message path and thus it has a -Open command line argument to specify that a specific stack be opened.

Now my question is this, in Windows a file association can be setup with the application in mind, you create a registry entry and tell it to execute using (Path To EXE) -Open "%1" and it will open it. Thus does anyone know how to do this in OS X because as it stands OS X tells the application to open the stack in question but without passing -Open and thus the application assumes it hasn't been passed any arguments and defaults to displaying the help dialog at the moment yet the stack opens but in a real world scenario the stack may have been designed to use the functions exported by my application and thus would cause errors.

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: OS X File Association Quirks

Post by Klaus » Wed Nov 23, 2011 11:33 am

Hi Mick,

1. the link to your homepage(Facebook?) on the right does not work!
2. I am not sure if some Mac expert should help you due to your signature! 8)
3. there is a quesion mark missing in the namely signature. :D

OK, these infos (and more) are stored in the "Info.plist" file inside of the application package -> Contents
It is in fact an XML file.Use GOOGLE to get more info about these files.


Best

Klaus

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7239
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: OS X File Association Quirks

Post by jacque » Wed Nov 23, 2011 7:28 pm

Klaus wrote: 2. I am not sure if some Mac expert should help you due to your signature! 8)
:) I started to write a response last night and didn't send it because of the sig. I wondered why he's writing for Mac if it's so bad.

Mick -- more than half the LiveCode developers here are Mac users, so you'll probably get more help if you change your sig. We try to be platform-neutral; LiveCode supports Mac, Windows, Linux, iOS and Android. Each has its advantages.

Here's a summary of what I almost sent last night: Macs have no registry, instead the OS uses plist files which are embedded into the application bundle. The advantage here is that the association is portable and you don't need to do anything special to the OS to support it; the moment your user copies your app to his machine, the file association is in place. You accomplish a file association by assigning a 4-letter creator code to your application, which you can do in the standalone settings. Your creator code must be unique; if you are building only for your own use you can make up just about anything but if you will distribute your app then you need to register your code with Apple to ensure you aren't using an existing one. There are some rules about capitalization, so look those up.

When creating stacks for your app, they must use your creator code's extension. You can assign that in the standalone settings too. Google "OS X creator code" to find out more.

Finally, you shouldn't need to use any command lines at all. LiveCode supports a wide variety of system and file functions (including setting the Windows registry) and you should be able to do anything you need using native LiveCode commands. I'd ditch the shell calls and use what LiveCode provides, it will be faster and avoid unnecessary overhead.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

SirWobbyTheFirst
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 239
Joined: Tue Jun 30, 2009 11:15 pm

Re: OS X File Association Quirks

Post by SirWobbyTheFirst » Wed Nov 23, 2011 7:49 pm

The signature thing is just a wack at the people in England who were believing that whole Rapture the world is gonna end thing. I've had it for a while as for my problem, I decided it might be better to rewrite it as last nights version seems a bit badly explained. When my application starts it loads its main stack like all Revolution applications, the main stack then sets up the global properties it needs such as examining the platform and setting the ShellCommand property to $ComSpec if its running on Windows.

Then when PreOpenCard kicks in, it examines the $# variable to see if it is equal to 1, if it is which means only the $0 variable exists and of course in standalones the $0 variable points to the application name with $1, $2 and so on being the actual arguments passed, thus if $# equals 1 the application assumes the user didn't pass any arguments at which point it pops up a friendly help dialog, on Windows this works perfectly because when you setup a file association there you can pass the -Open argument that the application recognises and then the name of a stack and I can verify it works by building a simple stack which executes the calls exposed by my application and displays their information.

Things change slightly on a Mac, the application will still pop up its help dialog if you just double click the .APP folder and my Info.plist file works correctly identifying the .NTAPP files as belonging to my application, but if you double click those files, OS X doesn't pass the -Open parameter to the application but here's where the quirk kicks in. OS X still manages to tell the application to open the stack specified which it does but the $0 variable still shows as 1 and thus the application assumes it needs to show its help dialog, which it does but if you move the help dialog out of the way you can see the stack it was told to load in the background.

If I get the test stack to then output the GlobalNames it shows only $# which indicates the number of arguments passed and $0 which displays the path to the application like always, but it doesn't show $1 which would seem logical if Finder passed the file name as an argument, so what I'm thinking is that OS X uses an AppleEvent to tell the application what to do and if so is there anyway to intercept it, because in a real world scenario, a developer may want to call one of the functions my application exposes and because this happens early in the initialisation of my application, certain parts of it might not be initialised yet.

I hope to god this makes sense and I'll change the signature, as I said before its been a while since I've been on the forums and that signature has been around since the day "zombies" where supposed to rise from the ground according to that American guy.

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: OS X File Association Quirks

Post by mwieder » Wed Nov 23, 2011 7:57 pm

Hey Mick- welcome back. Yeah - it's been a while.

Note that the way files are associated with executable programs is also OS-version-dependent. It has changed over time with various releases of OSX and may change in the future as well.

If it helps any (I'm sure it doesn't) file associations don't work much better on linux.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7239
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: OS X File Association Quirks

Post by jacque » Wed Nov 23, 2011 8:23 pm

Okay, now I get it. :) But thanks for changing the sig anyway.

Yes, you can trap appleEvents with an "on appleEvent" handler. Check to see if the params contain "aevt" and "odoc" and if so, get the appleEvent data. I haven't done this in a while, but if I remember right the stack name is in there. The dictionary has a pretty good example of how to parse the incoming params.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

SirWobbyTheFirst
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 239
Joined: Tue Jun 30, 2009 11:15 pm

Re: OS X File Association Quirks

Post by SirWobbyTheFirst » Wed Nov 23, 2011 10:56 pm

Hmm, I've been experimenting with the On AppleEvent message and whilst it does what I need it to do, I've came across another little problem. If I put in an On Startup, PreOpenStack, PreOpenCard and AppleEvent message into the card script of the stack the Startup, PreOpenStack and PreOpenCard messages get fired but the AppleEvent doesn't, even if I comment out the PreOpenStack and PreOpenCard messages, it seems any of the default engine messages override the AppleEvent, therefore I can't intercept the odoc event.

I was wondering if this occurs in the IDE as well, because I'd hate to have to develop a separate version of my application designed to make use of the oapp event for initialisation. It seems like a waste considering the startup message is supposed to do the same thing. Plus it defeats the purpose of Cross Platform. :D I'm happy to develop a separate version but I thought I should get advice from you guys before jumping into a rewrite.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7239
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: OS X File Association Quirks

Post by jacque » Mon Nov 28, 2011 7:25 am

A bit late on responding due to the holiday. An appleEvent handler should respond any time, in both the IDE or a standalone, provided it's in the message path. If you've put the handler in a card script but you aren't on that card when the event fires, the handler won't see it. Try putting it into the stack script instead, if your stack has more than one card.

If that's not the case then there's something else wrong. Are you sure it isn't firing at all? Have you tried putting a breakpoint in it or having it put something into the message box so you know whether it's being called?

You shouldn't have to write two versions of your app, the appleEvent should work. The only message the IDE gets that a stack will never see is the "startup" message, because the IDE gets that long before any stacks open. A standalone will get it though.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

SirWobbyTheFirst
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 239
Joined: Tue Jun 30, 2009 11:15 pm

Re: OS X File Association Quirks

Post by SirWobbyTheFirst » Tue Nov 29, 2011 12:07 am

I'm positive Jacque, I created a separate stack, placed a Startup, PreOpenStack, PreOpenCard and AppleEvent handler in its card script, and it seems if Startup, PreOpenStack and PreOpenCard exist, the AppleEvent won't trigger with regards to the oapp and odoc events, if other events occur such as quit, then the AppleEvent works fine. Bare in mind that I'm running Revolution 4.0 so this bug may have been fixed in newer versions.

I'm not too fussed about it anyways, doing the Mac specific version is giving me something to keep me occupied really. :-)

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: OS X File Association Quirks

Post by Klaus » Tue Nov 29, 2011 12:01 pm

Hi Mick,

the link to your FACEBOOK page does not work: FACEBOOK cannot find the requested page!
Could you please fix this or remove the link? Thanks!


Best

Klaus

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7239
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: OS X File Association Quirks

Post by jacque » Tue Nov 29, 2011 8:14 pm

Version 4.0 is pretty old so I can't remember now if there were problems with appleEvents back then. It should work though, I don't recall any specific problems with it. I'm more inclined to think there is something else wrong. It would help if we could see your handler, and if you could describe how you are trying to trigger the apple event. Are you dragging a file in the Finder and dropping it onto your running app?

Also, did you test in a standalone? The IDE may block the events, because it will try to open your stacks itself. I do know that I used the odoc event in the past and it worked fine.

The presence of other system event handlers (preOpenStack, etc.) will have no effect on an appleEvent handler. They are unrelated. In a standalone, are you trying to launch the app when the user drops a stack onto it? Or are you dropping the stack after the standalone is already running?
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

SirWobbyTheFirst
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 239
Joined: Tue Jun 30, 2009 11:15 pm

Re: OS X File Association Quirks

Post by SirWobbyTheFirst » Fri Dec 02, 2011 6:18 pm

Well to be honest, I've gotten started on the Mac specific version and I'm nearly done, just going to start testing now, the original was tested exactly how you describe, compiled it, right clicked a stack file in Finder done the usual Open With stuff and the application opened but wouldn't execute the AppleEvent handler if the startup, preOpenCard or PreOpenStack handler existed. I'm not really fussed about it any more, it just seemed strange at the time.

Anyways, with regards to the AppleEvent message idea in the first place, I'd like to thank you for suggesting it, I had completely forgotten about the message and the Apple Event system in general, I've got somewhat of a hybrid application going on where an AppleEvent handler catches the odoc and oapp messages and uses them to start executing the application instead of a PreOpenCard and whatnot message and it seems to be doing well.

With the Windows version I'm going for old faithful, it does have some perks because I don't have to worry about platform specific code being accidentally executed because I goofed up.

Post Reply

Return to “Mac OS”