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

Oct 19, 2009 at 3:19pm

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

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

#45955
Oct 19, 2009 at 9:01pm

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. –
#165572
Oct 19, 2009 at 9:39pm

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

#165573
Oct 19, 2009 at 9:50pm

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

#165574
Oct 20, 2009 at 12:12am

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. –
#165575
Oct 20, 2009 at 9:19am

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. –
#165576
Oct 20, 2009 at 9:35am

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?

#165577
Oct 20, 2009 at 10:06am

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

#165578
Oct 20, 2009 at 10:24am

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

#165579
Oct 20, 2009 at 3:11pm

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

#165580
Oct 20, 2009 at 10:08pm

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

#165581
Oct 20, 2009 at 10:32pm

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

#165582
Oct 20, 2009 at 10:57pm

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. –
#165583
Oct 20, 2009 at 11:22pm

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?

#165584
Oct 22, 2009 at 8:52pm
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

#165585
Oct 24, 2009 at 12:54am

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

#165586
Oct 24, 2009 at 2:22am

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. –
#165587
Oct 24, 2009 at 8:40pm
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

#165588
Oct 24, 2009 at 10:38pm

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

– Pasted Max Patch, click to expand. –
#165589
Oct 24, 2009 at 10:45pm

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

lh

#165590
Oct 24, 2009 at 11:25pm

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

– Pasted Max Patch, click to expand. –
#165591
Oct 24, 2009 at 11:32pm

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. –
#165592
Oct 24, 2009 at 11:48pm

Thank you very much!
It is perfect!

sincerely yours,
prko

#165593

You must be logged in to reply to this topic.