Skip to main content
Inspiring
May 18, 2011
Question

Use NativeProcess to start an air app from and air app

  • May 18, 2011
  • 1 reply
  • 1114 views

If I want to start an air app installed on my machine from another air app installed on my machine, is this possible. My idea is to use NativeProcess. Anybody know of any samples of this. I have seen samples using an exe, but none for air apps by themselves. Any ideas? Thanks!

This topic has been closed for replies.

1 reply

Participating Frequently
May 19, 2011

Hi,

first snippet for you, it's for OS X and it will start "TourDeFlex" (if installed of course )

var arguments:Vector.<String> = new Vector.<String>();

arguments.push("-a");

arguments.push("TourDeFlex");

var info:NativeProcessStartupInfo = new NativeProcessStartupInfo();

info.executable = new File("/usr/bin/open");

info.arguments = arguments;

var nativeProcess:NativeProcess = new NativeProcess();

nativeProcess.start(info);

arguments = null;

info = null;

nativeProcess = null;

http://osxfaq.com/man/1/open.ws

regards,

Peter

Kenneth Kawamoto
Community Expert
Community Expert
May 19, 2011

You don't need to call a script, you can just launch an app direct:

private function launchApp(app:String):void {
            var file:File = new File(app);
            var info:NativeProcessStartupInfo = new NativeProcessStartupInfo();
            info.executable = file;
            var process:NativeProcess = new NativeProcess();
            process.start(info);
}

One important thing to remember when launching a MacOS app is that the "app" is actually disguised folder and you cannot launch a folder

So using the function above, if you want to launch an AIR app (or any app for that matter) called "Test" ("Test.app") this will cause an error:

launchApp("/Applications/Test.app");

You have to target the meat itself in the package:

launchApp("/Applications/Test.app/Contents/MacOS/Test");
Participating Frequently
May 19, 2011

Hi,

I think no one needs to target nested content. Open simulates Finder and uses the same os x services I think, so one could also:

var arguments:Vector.<String> = new Vector.<String>();

arguments.push("/Applications/TourDeFlex.app");

var info:NativeProcessStartupInfo = new NativeProcessStartupInfo();

info.executable = new File("/usr/bin/open");

info.arguments = arguments;

var nativeProcess:NativeProcess = new NativeProcess();

nativeProcess.start(info);

now we are not using application CFBundleExecutable (-a) key (TourDeFlex). Otherwise we heading into possible error as there is no NSBundle.executable path or similar api (NSWorkspace) to read where exactly native executable is within bundle and/or lauch it, so we have to hardcode it, correct?

regards,

Peter Blazejewicz