How to launch an external application

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
MasterchiefJB
Posts: 76
Joined: Sat Nov 07, 2009 7:43 pm

How to launch an external application

Post by MasterchiefJB » Thu Jan 21, 2010 9:02 pm

Hi again,

this time I want to launch an external application through a button.
The documentation says:
13.1.2 Launching other applications
Use the launch command to launch other applications, documents or URLs. To launch
an application, supply the full path to the application. The following example opens a text
document with TextEdit on OS X:

launch "/Users/someuser/Desktop/text document.rtf" with \
"/Applications/TextEdit.app"
Well my external is in the defaultfolder and now I want to know how I can get the path to my defaultfolder or how I can create the launch command using my defaultfolder to search for the external executable.
I already tried to combine it like "defaultfolder\external.exe"
but this doesn´t work.

So I would like to know how I can get the path to my defaultfolder or how I can create the launch command using my defaultfolder to search for the external executable?
Any help will be appreciated,
Masterchief

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1239
Joined: Sat Apr 08, 2006 1:10 pm
Contact:

Re: How to launch an external application

Post by BvG » Thu Jan 21, 2010 11:39 pm

The defaultfolder is like a variable, it's not a string and can't be used like that.

Try something similar to this:

Code: Select all

on mouseUp
  answer the defaultfolder
end mouseUp
Now you need to conconate the string that the defaultfolder produces, and the name of your executable. Note that rev uses the forward slash, not the backwards one that you used in your attempt:

Code: Select all

on mouseUp
  launch (the defaultfolder & "/external.exe")
end mouseUp
If the path doesn't work, you will want to check the path for accuracy:

Code: Select all

on mouseUp
  --launch (the defaultfolder & "/external.exe") --disabled because it doesn't work properly, i wonder why?
  answer (the defaultfolder & "/external.exe")
  --now I know!
end mouseUp
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: How to launch an external application

Post by Klaus » Fri Jan 22, 2010 2:20 pm

Hi Chief,

maybe this will also help you:
When your app starts, "the defaultfolder" will be the folder where you app resides:
.../HardDisk/Folder/Your_app.app

So right after you doubleclicked "Your_app.app" "the defaultfolder" will be: .../HardDisk/Folder

That may change when using you app however, so a good idea would be to store this folder path right at the start in a custom property or global variable:
Example Mainstackscript (Standalone)
on preopenstack
...
global the_default_folder
put the directory into the_default_folder
...
end preopenstack

Then you can later use it whenever you need to:
...
global the_default_folder
launch (the_default_folder & "/you_other_app.app")
## OR EXE on windows
...


Best

Klaus

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: How to launch an external application

Post by Dixie » Fri Jan 22, 2010 2:48 pm

masterChief...

to find out the path to the folder where your rev stack/standalone currently resides...

Code: Select all

global myAppPath

on preOpenStack
   set itemDel to "/"
   put item 1 to -2 of (the fileName of this stack) into myAppPath
   set the defaultfolder to myAppPath
   
   put myAppPath  -- will put it in the 'message box'
end preOpenStack
be well

Dixie

MasterchiefJB
Posts: 76
Joined: Sat Nov 07, 2009 7:43 pm

Re: How to launch an external application

Post by MasterchiefJB » Fri Jan 22, 2010 3:45 pm

Thank you very much Dixie and Klaus! This helped me to get my little stack running;)
Both solutions are working great^^.

Best Regards,
Masterchief

Fasasoftware
Posts: 203
Joined: Mon Oct 31, 2011 9:36 pm
Contact:

Re: How to launch an external application

Post by Fasasoftware » Sat Aug 18, 2012 4:07 pm

This Works fine too...for mac os x

Code: Select all


on mousedown

launch ("./your_app.app")

end mousedown


Best regards,
Lestroso

Post Reply