Xojo launch/run another app (Mac)

2.7k views Asked by At

I want my program to launch another desktop application.

Tried shell execute (open appname) but it does not work.

Is there another way ?

Thank you in advance.

3

There are 3 answers

0
Abhi Beckert On

I'm not familiar with Xojo, however "launching" an application on OS X is complicated. There are many things you need to consider, especially if it's already running.

I recommend you look into two possible options, either use Xojo's ability to launch call native C code to run one of the three -[NSWorkspace launchApplication...] methods: https://developer.apple.com/library/mac/documentation/cocoa/reference/applicationkit/classes/NSWorkspace_Class/Reference/Reference.html#//apple_ref/doc/uid/20000391-SW23

Alternatively, use Apple's open command line tool:

/usr/bin/open -a "App Name"
/usr/bin/open -a "/Applications/App Name.app"
0
ianmjones On
dim s as new Shell
s.Execute("open -a ""Finder""")

' Check error code and do something about it...
if s.ErrorCode <> 0 then
  MsgBox("Error code: " + Str(s.ErrorCode) + EndOfLine + "Output: " + s.Result)
end if

Change "Finder" to whichever application you need, or build a string and pass that to s.Execute(). Be sure to include escaped quotes, especially if the application has spaces in its name.

2
BKeeney Software On

Another possibility is use the standard Xojo FolderItem and use the Launch method.

Dim f as folderitem = specialfolder.applications.child("AppName")
if f <> nil and f.exists then
  f.launch
end

Reference Documentation: http://docs.xojo.com/index.php/SpecialFolder http://docs.xojo.com/index.php/FolderItem.Launch