Path to a double-clicked document

Trevor DeVore lists at
Wed Jul 2 21:53:29 EDT 2008

On Jul 2, 2008, at 9:28 PM, Bill Vlahos wrote:

> How do I get the path to a file that was double-clicked in the OS  
> (Mac, Windows, and Linux) that opens my standalone?
> The association of the standalone to files with a particular  
> extension is set on the Mac and Windows gives the user the ability  
> to set up the association if I didn't set it in the registry.
> I want the document files for my application to live in a particular  
> folder and not be anywhere on the drive. When the user double clicks  
> the file on the file system or as an email attachment, I want to  
> catch it and offer the user the ability to copy the file from where  
> it is to where I want it to be.
> I assume getting the path will be the same for all the platforms and  
> I can write the copy/move routine.

Hey Bill,


Here is some appleEvent code you should put in the message path. Since  
you use the splash stack design I would put it in a library stack so  
that it catches the message regardless of which stack is frontmost.  
Note that you may need to check that your application has finished  
loading in the appleEvent. If double-clicking on the file causes the  
OS to launch your application then the appleEvent might be received  
before all of your application stacks have opened.

on appleEvent pClass, pID, pSender
     if pClass is "aevt" and pID is "odoc" then
         request appleEvent data
         put it into theFiles ## files OS is requesting your  
application opens.

         if theFiles is not "not found" then
             if theFiles is not empty then

                 pass appleEvent
             end if
             pass appleEvent
         end if
         pass appleEvent
     end if
end appleEvent


If your application is not running yet then the file paths will be  
passed in the command line arguments - $1, $2, etc. Revolution 2.9  
added $# which tells you how many command line arguments were passed  
to the application so the following code will create a return  
delimited list of argument passed to your application at launch. It is  
up to you to verify the params are paths to one of your files.

repeat with i = 1 to $#
    put value("$" & i) into theValue
    put theValue & cr after theFiles
end repeat

If your application is already running then you need to handle the  
'relaunch' command in the stack you use to create the executable.  
Again, you should check that your application has finished loading  
before doing anything as the relaunch command could be sent before  
your application has completely loaded (you are using splash stack  

on relaunch
     repeat with theCounter = 1 to the paramcount
         put param(theCounter) & cr after theFiles
     end repeat
end relaunch


No idea, sorry.


Trevor DeVore
Blue Mango Learning Systems
Developer Resources:

More information about the use-livecode mailing list