Page 1 of 1

launch png or txt file with defaultapp

Posted: Sun May 04, 2014 11:14 am
by jmburnod
Hi All,
I use this script to open a .png or .txt file on OSX
Is there an equivalent on windows ?

Code: Select all

on doLaunchOneFile pPathEx
   if char -4 to -1 of pPathEx = ".png" then
      launch pPathEx with "/Applications/Preview.app"
   end if
   if char -4 to -1 of pPathEx = ".rtf" then
      launch pPathEx with "/Applications/TextEdit.app"
   end if
end doLaunchOneFile
Thanks
Jean-Marc

Re: launch png or txt file with defaultapp

Posted: Sun May 04, 2014 11:47 am
by Klaus
Hi Jean-Marc,

just use:

Code: Select all

...
launch document pPathEx
if the result <> empty then

  ## Probably "no association" or something...
  ## Check the dictionary for other possible RESULTs
  answer "Error:" && the result
  exit to top
end if
...
and let the underlying OS take care of the correct associated application for that file (-type)!
:D

This will work crossplatform for Mac and Win (maybe Linux, no idea...)!


Best

Klaus

Re: launch png or txt file with defaultapp

Posted: Sun May 04, 2014 12:06 pm
by jmburnod
Hi Klaus,
This will work crossplatform for Mac and Win (maybe Linux, no idea...)!
I love it
I will test it for IOS
Thanks a lot
Best
Jean-Marc

Re: launch png or txt file with defaultapp

Posted: Sun May 04, 2014 12:37 pm
by Klaus
Hi Jean-Marc,

"launch document..." is not suported on mobile, but "launch url...", which is a slight variation of "launch document..."
does in fact work on mobile according to the dictionary.


Best

Klaus

Re: launch png or txt file with defaultapp

Posted: Sun May 11, 2014 3:48 pm
by jmburnod
Hi Klaus,
Thanks one more

Code: Select all

launch url("file:" & tMyPath)
I tested it on OSx and windows. It works fine
On IOS I get a "error:no association" result
That is not an emergency for IOS.

This script is used to open a document after exporting a txt or png file
It is freezed in this time because I need something like diskspace() for IOS before
All the best
Jean-Marc

Re: launch png or txt file with defaultapp

Posted: Sun May 11, 2014 5:15 pm
by Klaus
I'm afraid there is nothing you can do about this!

The docs about "launch url...":
-----------------------------------------------------------------
When launch url is called, LiveCode checks to see if an application is available to handle the URL.
If no such application exists, the command returns "no association" in the result.
..................................................................