launch png or txt file with defaultapp

Deploying to Windows? Utilizing VB Script execution? This is the place to ask Windows-specific questions.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

launch png or txt file with defaultapp

Post by jmburnod » Sun May 04, 2014 11:14 am

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
https://alternatic.ch

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

Re: launch png or txt file with defaultapp

Post by Klaus » Sun May 04, 2014 11:47 am

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

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: launch png or txt file with defaultapp

Post by jmburnod » Sun May 04, 2014 12:06 pm

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
https://alternatic.ch

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

Re: launch png or txt file with defaultapp

Post by Klaus » Sun May 04, 2014 12:37 pm

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

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: launch png or txt file with defaultapp

Post by jmburnod » Sun May 11, 2014 3:48 pm

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
https://alternatic.ch

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

Re: launch png or txt file with defaultapp

Post by Klaus » Sun May 11, 2014 5:15 pm

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.
..................................................................

Post Reply

Return to “Windows”