Page 1 of 1
How to get parameters if extension is associated?
Posted: Thu Sep 20, 2012 3:47 pm
by Kukulkan
Hi,
I made a package to deploy a PB application on MacOS. I use the Info.plist to assign the application as editor/viewer for the extension rgf. If I now double click such a file in MacOS, my application is launched. Sadly, the clicked file is not provided as commandline parameter. My application does not know about such a file.
I found this:
http://developer.apple.com/library/ios/ ... 010412-SW1
I can imagine that CocoaMessage() function from
http://www.purebasic.fr/english/viewtop ... 19&t=50795 can help, but how????
Any hints for me?
Kukulkan
Re: How to get parameters if extension is associated?
Posted: Thu Sep 20, 2012 4:42 pm
by wilbert
Unfortunately CocoaMessage isn't always the solution and the problem is complicated.
I'll try to explain ...
Normally every application can have a delegate that handles several issues.
Opening documents is one of them. NSApplicationDelegate has a method named application:openFile: for this purpose.
The problem is that an application can only have one application delegate and PureBasic itself already sets one so changing the delegate will cause problems.
Another way would be to use the NSAppleEventManager class to set your own manager for the event that is triggered when a document has to be opened.
This should be possible but would require quite a lot of code.
Third possible way is to use method swizzling meaning you get the implementation of the method application:openFile: (a pointer to a C function) and exchange that with your own function.
From the three options this is the easiest one but as far as I understand Apple isn't happy with this and you risk an app being rejected from the AppStore if you do it this way.
What you could do with CocoaMessage is get the arguments passed to the application but you mention a filename isn't passed as an argument so in that case this wouldn't help.
So there is no quick solution if PB itself has no support for this.
Re: How to get parameters if extension is associated?
Posted: Thu Sep 20, 2012 4:43 pm
by WilliamL
I am also interested in a solution to this problem!
I understand that with Cocoa and 64 bit programs that the process is very different from Carbon (which we had a solution - see 'API List for Mac').
Possibly Fred can comment on this request.
Re: How to get parameters if extension is associated?
Posted: Fri Sep 21, 2012 5:33 pm
by WilliamL