Launch a program from console

Quick question:

Once upon a time you could launch a program with something like

var f as folderitem
f = SpecialFolder.Documents.Child(“TheProgramFolder”).Child(“MySpecialProgram”).Launch.

This option does not seem to be available anymore.

When I do a search in the documentation, for Launch, it doesn’t seem to be there either.

How do you launch a program now?

Regards

I believe .Launch was API-1. So try API-2 .Open

Edited to add: Oops, just noticed this disclaimer

This method is not supported for console and mobile projects.

But just below that notice is an example of how to open an app from a Console app using Shell on macOS. I’m sure there is a similar way on Windows if needed.

It won’t work on Mac OS because console apps don’t have a connection to the window server (provides GUI), which is what FolderItem.Launch requires.

Try this, if you’re on the Mac: in your console app, create a Shell and execute “/usr/bin/open /path/to/executable”. That should launch any GUI or console app.

Hi Eric.

I’ll try that and let you know.

Regards

Hi Scott.

This method is not supported for console and mobile projects.

You have now idea how bad I felt when I found this in the documents before opening this thread. :smiley: Glad to know I am the only one who misses things!

Where do you change from API-1 to API-2? I looked under build settings, where i thought it was but there is nothing there.

But just below that notice is an example of how to open an app from a Console app using Shell on macOS. I’m sure there is a similar way on Windows if needed.

I didn’t see any attachments. Another error on my part?

Regards

It’s not a setting change. It’s what objects and syntax you use. Check out the discussion in this thread for more information.

Go to this link .Open and scroll down about half a screen.

Hi there.

Ok, I “kind of” have my program running, but it brings up some questions.

This works for me:

sh.Execute ("open -a /Applications/myMovieScreenSaver.app”)

However if I to this:

sh.Execute ("/usr/bin/open -a /Users/michaelcebasek/Documents/xojo programs/myMovieScreenSaver/Builds - myMovieScreenSaver9/macOS Universal/myMovieScreenSaver.app”)

It doesn’t work.

Looking through the man open, I know -a is for application start, but shouldn’t this work in a “general” (not restricted, and on my computer I am an administrator) folder like Dcouments?

Regards

Just a hunch - is the app in that location codesigned and notarised yet?

I think the args themselves may have to be quoted, thus:

s = new shell
s.execute ("/usr/bin/gzip """ +  logfile + ".tmp""")

Tim is right, there are two spaces in the passed path:
Builds - myMovieScreenSaver9

Thanks for the responses everyone.

I did forget to mention (since I was doing this at 0330 Eastern Time) That I took a copy of the app and put it directly into my Documents folder, using the shell execute

sh.execute (“open -a /Documents/myMovieScreenSaver.app”)

and it never launched.

Will try your suggestions and advise.

Regards

You need the full path to your documents folder.

"open -a /Users/yourusername/Documents/myMovieScreenSaver.app"

You should use the full path, but instead try using FolderItem.shellPath which will return a path with “funny” characters escaped so you don’t need to do quoting:

e.g. instead of this:

/Users/michaelcebasek/Documents/xojo programs/myMovieScreenSaver/Builds - myMovieScreenSaver9/macOS Universal/myMovieScreenSaver.app

ShellPath would return this:

/Users/michaelcebasek/Documents/xojo\ programs/myMovieScreenSaver/Builds\ -\ myMovieScreenSaver9/macOS\ Universal/myMovieScreenSaver.app