Open a document

Is it possible to, from Xojo, open a document using a specific program.

For example, could I in code open a .txt with TextWrangler rather than Text Edit on a Mac?

You could use AppleScript (or Apple Events) on the Mac side. I don’t know about the other platforms.

[quote=86507:@Bob Gordon]Is it possible to, from Xojo, open a document using a specific program.

For example, could I in code open a .txt with TextWrangler rather than Text Edit on a Mac?[/quote]

Use a shell to send a command line such as :

open -a TextWrangler /Users/Mitch/Myfile.txt

See http://osxdaily.com/2007/02/01/how-to-launch-gui-applications-from-the-terminal/ for more.

Wow. The Forum should provides fast service.

I will look into the shell command.

Would such a feature be useful? For example, currently the folder item launch method is:

folderItem.launch(optional parameters)

A new method might look like:

folderItem.launchWith(applicationFolderItem, optional parameters)

-Bob

have you ‘tried’ LAUNCH?
but instead of pointing “F” at the document, point it at the APPLICATION, and the optional parameters specify the file for that app to open???

You have it backwards.
applicationFolderitem.launch(folderitem.nativepath)

The file you want to open is the optional parameter.

This may work on other platforms, but it doesn’t seem to work on a Mac.

Kem’s right.

The docs are clear about this. It won’t work on a Mac.

On the Mac side, this AppleScript will work and can be called as LaunchAppWithDoc( appBundIeID, doc.NativePath ):

on run {appid, docpath}
	set f to POSIX file docpath
	tell application id appid to open f
end run

You could modify it to use the app name instead, but id is safer.

The shell approach works:

Documentation is here: https://developer.apple.com/library/mac/documentation/Darwin/Reference/Manpages/man1/open.1.html

An example:

cmd   = "open -a /Applications/TextWrangler.app '" + f1.NativePath + "'"
shell = new Shell()
shell.Execute(cmd)

Now, of course, as I understand it, this means I can release this to the Mac App Store, but that’s another conversation.

If you use MBS Plugin, it’s the LaunchServicesOpenXMBS function on Mac.

I think you’re asking for trouble with shell-based solution but, if nothing else, use ShellPath without quotes, not NativePath with quotes.

Christian,

Hello.

I have the MBS Plugins. Will the use of the plugin prevent distribution in the app store?

His plugins are just wrapped around valid system calls, so no, it won’t prevent distribution.

Told you :wink:

Told you :wink:

On a similar topic - is it possible to do an “Open With” like Finder’s contextual menu i.e. a dropdown that shows all the apps that can open a particular folderItem. I can’t see that in Launch Services.

Wasn’t what Dave said earlier ? (years earlier):

It was an old thread but still relevant. No I think that just opens the default application for that file. What I’d like is the ability to chose from a list of all applications that can open that file. Just like right clicking a file in the finder.

I understand the first time, but I do not read the LR for FolderItem.Launch: the optional parameters are available only on Linux and Windows.

Sorry.