MAX and Applescript

Jun 14, 2007 at 1:11am

MAX and Applescript

Hello,
been trying to write a patch using the shell object to send out applescript commands ( mostly GUI scripting ). Im a bit familiar with applescript but it seems some of the syntax is a bit different when using the shell object in max, as ill send out some applescript commands from applescripts i have previously written and work, but when sent via the shell object they dont seem to work. im wondering if anyone knows of some resurces for applescript syntax from max’s shell external, i looked around for a bit, but didnt really find anything of use.

thanks,
Mike

#32454
Jun 14, 2007 at 4:53am

Quote: !Include wrote on Thu, 14 June 2007 03:11
—————————————————-
> been trying to write a patch using the shell object to send out
> applescript commands ( mostly GUI scripting ). Im a bit familiar
> with applescript but it seems some of the syntax is a bit
> different when using the shell object in max
—————————————————-

Hi Mike,

Take a look at this recent topic called “Au~ scripting” and search for ‘osascript’ inside: < http://tinyurl.com/24xxzq>

About the interface elements, I suggest to study the scripting possibilities of [thispatcher] object.

Bye,
Philippe

#106748
Jun 14, 2007 at 7:30am

if you don’t mind moving away from the shell object, you may want to look into tap.tools. it does cost money, but perhaps, tap.applescript may do what you’re looking for without an unfamiliar syntax.

http://www.electrotap.com/taptoolsmax/

m

#106749
Jun 16, 2007 at 11:02am

Quote: Philippe Gruchet wrote on Wed, 13 June 2007 22:53
—————————————————-
> Quote: !Include wrote on Thu, 14 June 2007 03:11
> —————————————————-
> > been trying to write a patch using the shell object to send out
> > applescript commands ( mostly GUI scripting ). Im a bit familiar
> > with applescript but it seems some of the syntax is a bit
> > different when using the shell object in max
> —————————————————-
>
> Hi Mike,
>
> Take a look at this recent topic called “Au~ scripting” and search for ‘osascript’ inside: < http://tinyurl.com/24xxzq>
>
> About the interface elements, I suggest to study the scripting possibilities of [thispatcher] object.
>
> Bye,
> Philippe
>
—————————————————-

Thanks for your response. So basically the shell object will process anything with proper osascript syntax? Wierd for some reason i cant get any osascript sent key combinations to work. im basically tryin to pass a keycombo ( cmnd + c ) to the shell object with no luck. I can tell system processes to activate Live the application to receive the key command- that works fine. Ive tried a bunch of different things to get the key combo to work, but nothing yet. I have universal access enabled in system prefs. here is what i have if you dont mind taking a look:

osascript -e ‘tell application “”System Events”" to tell process “Live” to keystroke “c” using {command down}’

ive also tried using the menu as i found in your Au~ script ( your au script works for me in max by the way:

‘tell application |System Events| to tell process |Live| to click menu item 4 of menu 3 of menu bar 1′
but replacing it with the proper menu numbers. Still no luck.

I tried various combinations of both of the above with no luck. Id be greatful for any help on this matter.

Thanks,
mike

#106750
Jun 16, 2007 at 11:59am

#106751
Jun 16, 2007 at 5:56pm

>> Quote: !Include wrote on Thu, 14 June 2007 03:11
>> —————————————————-
>>> been trying to write a patch using the shell object to send out
>>> applescript commands ( mostly GUI scripting ). Im a bit familiar
>>> with applescript but it seems some of the syntax is a bit
>>> different when using the shell object in max
>> —————————————————-
>>> Quote: Philippe Gruchet wrote on Wed, 13 June 2007 22:53
>>
>> Take a look at this recent topic called “Au~ scripting” and search
>> for ‘osascript’ inside: < http://tinyurl.com/24xxzq>
>> About the interface elements, I suggest to study the scripting
>> possibilities of [thispatcher] object.
> —————————————————-

> So basically the shell object will process anything with proper
> osascript syntax?

Basically, yes.

> Weird for some reason i cant get any osascript sent key
> combinations to work. im basically tryin to pass a keycombo ( cmnd
> + c ) to the shell object with no luck. I can tell system processes
> to activate Live the application to receive the key command- that
> works fine. Ive tried a bunch of different things to get the key
> combo to work, but nothing yet. I have universal access enabled in
> system prefs. here is what i have if you dont mind taking a look:
>
> osascript -e ‘tell application “”System Events”" to tell process
> “Live” to keystroke “c” using {command down}’

I suggest to escape all double-quote characters by using the syntax
you’ll find in my examples.

Tell first to activate the targeted application. A simple example
that displays the Finder’s Clipboard from Max.
I’m using there [prepend osascript -e] when I need several lines of
scripts.

#P window setfont “Sans Serif” 9.;
#P window linecount 1;
#P newex 20 194 102 196617 prepend osascript -e;
#B color 5;
#P message 20 105 166 196617 ‘tell application |Finder| to activate’;
#P newex 35 71 45 196617 del 1000;
#P button 20 25 25 9;
#P window linecount 3;
#P message 35 136 162 196617 ‘tell application |System Events| to
tell process |Finder| to click menu item 8 of menu 4 of menu bar 1′;
#P window linecount 1;
#P newex 20 268 19 196617 34;
#P newex 20 249 45 196617 sel 124;
#P newex 20 318 44 196617 itoa;
#P newex 20 299 45 196617 thresh;
#P newex 20 230 45 196617 spell;
#P newex 20 337 45 196617 shell;
#P connect 8 0 6 0;
#P connect 7 0 9 0;
#P connect 7 0 8 0;
#P connect 3 0 0 0;
#P connect 2 0 3 0;
#P connect 4 1 2 0;
#P connect 5 0 2 0;
#P connect 4 0 5 0;
#P connect 1 0 4 0;
#P connect 10 0 1 0;
#P connect 9 0 10 0;
#P connect 6 0 10 0;
#P window clipboard copycount 11;

> ive also tried using the menu as i found in your Au~ script ( your
> au script works for me in max by the way:
>
> ‘tell application |System Events| to tell process |Live| to click
> menu item 4 of menu 3 of menu bar 1′
> but replacing it with the proper menu numbers. Still no luck.

Try this one:

#P window setfont “Sans Serif” 9.;
#P window linecount 1;
#P message 27 110 222 196617 osascript -e ‘tell application |Live| to
activate’;
#P newex 42 78 45 196617 del 1000;
#P button 27 32 25 9;
#P window linecount 3;
#P message 42 143 207 196617 osascript -e ‘tell application |System
Events| to tell process |Live| to click menu item 4 of menu 3 of menu
bar 1′;
#P window linecount 1;
#P newex 27 230 19 196617 34;
#P newex 27 211 45 196617 sel 124;
#P newex 27 280 44 196617 itoa;
#P newex 27 261 45 196617 thresh;
#P newex 27 192 45 196617 spell;
#P newex 27 299 45 196617 shell;
#P connect 9 0 1 0;
#P connect 6 0 1 0;
#P connect 1 0 4 0;
#P connect 4 0 5 0;
#P connect 4 1 2 0;
#P connect 5 0 2 0;
#P connect 2 0 3 0;
#P connect 3 0 0 0;
#P connect 7 0 8 0;
#P connect 7 0 9 0;
#P connect 8 0 6 0;
#P window clipboard copycount 10;

You can also replace the menu numbers with the proper names as strings:

osascript -e ‘tell application |System Events| to tell process |
MaxMSP| to click menu item 6 of menu 4 of menu bar 1′

Becomes:

osascript -e ‘tell application |System Events| to tell process |
MaxMSP| to click menu item |Paste| of menu |Edit| of menu bar 1′

HTH,
Philippe

#106752
Jun 17, 2007 at 12:28pm

many thanks again Philippe.!. is there any reason for the 1000ms Delay? The Patch only seems to have an effect in Live when the Delay > 350ms.

#106753
Jun 19, 2007 at 2:03am

Quote: !Include wrote on Sun, 17 June 2007 14:28
—————————————————-
> is there any reason for the 1000ms Delay? The Patch only
> seems to have an effect in Live when the Delay > 350ms.
—————————————————-

Yes, 350 to 500 seems a good range for an inter-application scripting. When a such script doesn’t work, just increase the delay(s) between each statement.

Bye

#106754

You must be logged in to reply to this topic.