Page 1 of 1

MacOS: Get Filename from "document interaction controller"

Posted: Fri Sep 21, 2012 6:41 am
by Kukulkan
Hi Fred and Team,

If a PB application handles a mime-type or file extension on MacOS, it gets startet after double clicking such a document. Sadly, the filename is not submitted as a commandline parameter. It is done using a document interaction controller. It is described here:
http://developer.apple.com/library/ios/ ... Types.html

Can you please check these UIApplicationLaunchOptionsURLKey values on executable start in MacOS and pass them as commandline parameters?

With this function the filename(s) from this interface will be usable with the ProgramParameter() function.

Thank you!

Kukulkan

Re: MacOS: Get Filename from "document interaction controlle

Posted: Fri Sep 21, 2012 6:56 am
by wilbert
You are mixing things up Kukulkan.
This is for the mobile operating system iOS only.
If you look at the title of the link you posted, you will see it mentions iOS.

Re: MacOS: Get Filename from "document interaction controlle

Posted: Fri Sep 21, 2012 7:28 am
by Kukulkan
Oh damn, you are right! :oops:

Anyway, we need a way to get the submitted filename. It is definitely NOT submitted as commandline parameter.

Any ideas around this issue? Or is this a PB bug only?

Kukulkan

Re: MacOS: Get Filename from "document interaction controlle

Posted: Fri Sep 21, 2012 7:36 am
by wilbert
You are right about the commandline parameter.

As for a workaround, I prefer to wait for a response from the PB team first.
All possible workarounds are not easy to accomplish. Maybe there's some simple solution I overlooked.

Re: MacOS: Get Filename from "document interaction controlle

Posted: Fri Sep 21, 2012 7:52 am
by Kukulkan
I found this page:
https://developer.apple.com/library/mac ... rence.html

The arguments parameter should return this values...

Kukulkan

Re: MacOS: Get Filename from "document interaction controlle

Posted: Fri Sep 21, 2012 7:56 am
by wilbert
I already had looked into that but it just mentions the application name itself, no documents the application has to open unfortunately.

Re: MacOS: Get Filename from "document interaction controlle

Posted: Fri Sep 21, 2012 11:26 am
by Fred
Actually it was needed for IDE as well, so we did a quick hack. You can use it as well for now, it will probably change for something more integrated later (like using ProgramParameter() instead). As i'm away from home and don't have OS X, i can't test the following code but you get the idea:

Code: Select all

ImportC ""
  PB_Gadget_SetOpenFinderFiles(Callback)
EndImport

IsGadget(0) ; Ensures the gadget lib is linked as this command is in it

ProcedureC OpenFinderFilesCallback(*Utf8Files)
  Files$ = PeekS(*Utf8Files, #PB_Utf8) ; Each file is separated by a 'tab'
  Debug Files$ ; Use StringField() to iterate easily
EndProcedure

PB_Gadget_SetOpenFinderFiles(@OpenFinderFilesCallback()) ; should be put very early in the code, before any event loop

Re: MacOS: Get Filename from "document interaction controlle

Posted: Fri Sep 21, 2012 11:58 am
by wilbert
That's a much easier approach as other possible workarounds :D

The code form Fred is almost working except for the PeekS command

Code: Select all

ImportC ""
  PB_Gadget_SetOpenFinderFiles(Callback)
EndImport

IsGadget(0) ; Ensures the gadget lib is linked as this command is in it

ProcedureC OpenFinderFilesCallback(*Utf8Files)
  Files$ = PeekS(*Utf8Files, -1, #PB_UTF8) ; Each file is separated by a 'tab'
  MessageRequester("", Files$) ; Use StringField() to iterate easily
EndProcedure

PB_Gadget_SetOpenFinderFiles(@OpenFinderFilesCallback()) ; should be put very early in the code, before any event loop

Re: MacOS: Get Filename from "document interaction controlle

Posted: Mon Oct 15, 2012 8:54 am
by Kukulkan
Hello,

this works fine if the app was called with a filename. But how to detect if it was called without a filename?

My application works both as viewer (filename in parameter) or editor (no filename).

If I like to view a file it works good with this hack. But if, with opened viewer, someone likes to run the editor (start app in "Applications"), it only activates my current viewer. The callback here is not called in this case (there is no filename given).

Any idea? Is there a callback like PB_Gadget_SetOpenFinderFiles() for this case, too?

Kukulkan

Re: MacOS: Get Filename from "document interaction controlle

Posted: Fri Dec 16, 2016 6:21 am
by coder14
Fred wrote:Actually it was needed for IDE as well, so we did a quick hack. You can use it as well for now, it will probably change for something more integrated later (like using ProgramParameter() instead). As i'm away from home and don't have OS X, i can't test the following code but you get the idea:

Code: Select all

ImportC ""
  PB_Gadget_SetOpenFinderFiles(Callback)
EndImport

IsGadget(0) ; Ensures the gadget lib is linked as this command is in it

ProcedureC OpenFinderFilesCallback(*Utf8Files)
  Files$ = PeekS(*Utf8Files, #PB_Utf8) ; Each file is separated by a 'tab'
  Debug Files$ ; Use StringField() to iterate easily
EndProcedure

PB_Gadget_SetOpenFinderFiles(@OpenFinderFilesCallback()) ; should be put very early in the code, before any event loop
Hi Fred! You said a quick hack - is it still safe to use it?

For my own education is PB_Gadget_SetOpenFinderFiles hooking AEOpenDocuments from OS-X?

Thank you!