Forums > MaxMSP

Can MaxMSP open a rtf in TextEdit or html file in browser?

October 19, 2009 | 3:19 pm

Dear users,

we can open a url in max.
Max can also launch a favorite browser in order to open a url.
However, how about a file?
Can Max launch an external program (TextEdit) in order to open a rtf file?

best,
prko


October 19, 2009 | 9:01 pm

You can use [shell] to run terminal commands on a mac. Try something like the patch below. It won’t work when there are spaces in the file path, but it will if there are spaces in the filename itself, I imagine that it’s fixable though.

lh

– Pasted Max Patch, click to expand. –

October 19, 2009 | 9:39 pm

is it compatible with max 5?
It doesn’t work.


October 19, 2009 | 9:50 pm

Have you downloaded the [shell] object? It is an external, not part of the regular distribution. If you already have it what is the patch doing? Anything? Try formatting the message manually, it should look something like: "cd ~/; open -a "

lh


October 20, 2009 | 12:12 am

Alternatively try this patch which uses applescript and the [shell] or [aka.shell] object. I’m a bit more familiar with escaping characters for applescript so this one should work just fine.

lh

– Pasted Max Patch, click to expand. –

October 20, 2009 | 9:19 am

Thanks, there is still one error.
I have corrected it.
Now it works well.
See my correction.
I still don’t understand regexp.
I have just experienced your last patch.
Thanks a lot!

– Pasted Max Patch, click to expand. –

October 20, 2009 | 9:35 am

I have another problem.
After launching the TextEdit, the application TextEdit is sent back of the MAX5.
Can we have the TextEdit in front of MAX?


October 20, 2009 | 10:06 am

Which bit exactly did you change from my example? It should bring the TextEdit window to the front automatically, the "activate" command should take care of that. Do you have anything in max keeping windows in the foreground? Like "front" to [thispatcher] for example?

lh


October 20, 2009 | 10:24 am

HM,it is strange.
I added in MAX the message "sendtoback" into thispatcher.

What I altered in your patch is the following:
you connected the second outlet of the second regexp into the sprintf.
It truncate the volume name (partition name) of the harddisk.
I connected the third outlet of the second regexp into the sprintf.
It does not truncate the volume name.
I have not perfectly understood the usage of the symbols in regexp.
But, with this change the patch works now perfectly.

best with lots of thanks,
prko


October 20, 2009 | 3:11 pm

I have a further question.
Can I also use the default association of the rtf file?
That means, Max use the system information about the association of a file type to a specific program.
Thus, if a system has Acrobat, then a pdf file will be launched with Acrobat.
If a system has just Preview, the a pdf file will be launched with Preview.

best,
prko


October 20, 2009 | 10:08 pm

You can do that with the shell script I posted before. Remove the "-a TextEdit" bit which tells the terminal which application to use and it will use whichever is the default for the file you specify. If you want to use applescript then I generally find all the information I need using google, perhaps try the "do shell script" command from there.

lh


October 20, 2009 | 10:32 pm

In your first code, there is an error in sprintf.
There are two inlets for two "%s"s.
However, you connected only one inlet.

Thus, the second code is funtional.

sprintf osascript -e ‘tell application \"TextEdit\"‘ -e ‘activate’ -e ‘open \"%s\"‘ -e ‘end tell’

What I should change?

Thanks a lot!

best,
prko


October 20, 2009 | 10:57 pm

If you send a list to many max objects it will interpret it as the first item being sent to the first inlet, the second item to the second inlet and so forth. As there are two backreferences (sets of parentheses) in the [regexp] it will output a list of two items and [sprintf] will interpret these as being sent one to each inlet. Just removing the "-a TextEdit" bit should work with the default application. The patch below works for me.

lh

– Pasted Max Patch, click to expand. –

October 20, 2009 | 11:22 pm

Now I know the problem (but still without solution)!

Your code is only functional, if we open a document inside of the home folder.
However, I want to open a file in another hard disc.
Thus, your patch does not work for me.
I have not found, how to refer another partition in another hard disc.
(IO have four hard disks)

Do you (or does anybody) know the method?


October 22, 2009 | 8:52 pm
prko wrote on Wed, 21 October 2009 01:22
Now I know the problem (but still without solution)!

Your code is only functional, if we open a document inside of the home folder.
However, I want to open a file in another hard disc.
I have not found, how to refer another partition in another hard disc. (I have four hard disks)

Do you (or does anybody) know the method?

Yes, send this message: (ls /Volumes)->[shell].

PG


October 24, 2009 | 12:54 am

sorry!
I have tried longer than two days.
I could not find the possibility.
However, I know what I should do.
But, how?

I should e.g. divided the following strings:
"WorkspaceX:/MyDocuments/Compositions/Patches/interactive additive synth/[Version_V]/_sonic_prism_.scd"

This strings should be

WorkspaceX:/MyDocuments/Compositions/Patches/interactive additive synth/[Version_V] _sonic_prism_.scd

I don’t kno what I should write in regexp


October 24, 2009 | 2:22 am

Dear thereishopeforus and PhiDjee,

here the correct patch!
However, there is still a problem.
The path and filename should not have a space.

– Pasted Max Patch, click to expand. –

October 24, 2009 | 8:40 pm
prko wrote on Sat, 24 October 2009 04:22
The path and filename should not have a space.

So replace the space char(s) with %20

philippe


October 24, 2009 | 10:38 pm

Yes, I did.
However, it also does not work.
See the code revised after your comment.

– Pasted Max Patch, click to expand. –

October 24, 2009 | 10:45 pm

The %percent% sign is used to recall back-references in [regexp] substitutions, you will need to escape by using two: %%20.

lh


October 24, 2009 | 11:25 pm

Is the following patch correct?
It does still not work.

– Pasted Max Patch, click to expand. –

October 24, 2009 | 11:32 pm

Try enclosing your entire filepath in "quotes" this will force it to be interpreted as a string and not a list. The patch below works for me.

lh

– Pasted Max Patch, click to expand. –

October 24, 2009 | 11:48 pm

Thank you very much!
It is perfect!

sincerely yours,
prko


Viewing 23 posts - 1 through 23 (of 23 total)