We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOther Libraries › using cocoa library to run applescript
Page Index Toggle Pages: 1
using cocoa library to run applescript (Read 11758 times)
using cocoa library to run applescript
Nov 1st, 2008, 7:38pm
 
I am trying to run an applescript from processing in the manner that is described here http://processing.org/hacks/doku.php?id=hacks:applescript.  
(I'm currently using the same code described there)
However I can't seem to find the right place to put the files that contain the  com.apple.cocoa.foundation.* library.  I have tried copying the 'com' directory from System/Library/Java directory and putting it into the 'libraries' folder of my sketch's folder but the IDE still says
"Starting with release 0149, libraries must be installed in a folder named 'libraries' inside the 'sketchbook' folder."  
I have tried putting the the 'com' folder into processing's application bundle 'libraries' folder , and that produces the same error as well, at compile time.

I have tried reading and following the documentation for importing libraries (I walked through the example of importing the 'sonia' library) and was able to get that to work, but tried the same process for the apple library and had no luck.

your help is much appreciated.  thanks in advance!

Sean
Re: using cocoa library to run applescript
Reply #1 - Nov 2nd, 2008, 5:15am
 
a quick workaround for this:
create folders cocoa/library in /sketchbook/libraries
go to System/Library/Java and "create archive of com" (ctrl+mouse click on folder)
a zip file com.jar is created. rename the zip to cocoa.jar
move cocoa.jar to /sketchbook/libraries/cocoa/library
restart processing and run your sketch.

the sketchbook folder refers to the folder in which processing stores your sketches (sketches inside this folder can be accessed in processing's menubar under File->sketchbook).  
on mac this folder is located at
~/Documents/Processing
contributed libraries go into
~/Documents/Processing/libraries

on windows it is located at
~/My Documents/Processing
(e.g. C:\Documents and Settings\username\My Documents\Processing)
contributed libraries go into
~/My Documents/Processing/libraries

Re: using cocoa library to run applescript
Reply #2 - Nov 4th, 2008, 5:26am
 
That worked just great!  strangely adding the jar file to the library of the sketchbook didn't work for me though.  So I just added the library to processing's application bundle library and it works just great now.  Thanks again!

-Sean
Re: using cocoa library to run applescript
Reply #3 - Nov 4th, 2008, 10:06am
 
it's "libraries" not "library".

~/Documents/Processing/libraries

you should put it there as the app-bundle will be replaced when you upgrade to a newer release.

F
Re: using cocoa library to run applescript
Reply #4 - Nov 15th, 2008, 8:18pm
 
alright I have one more question regarding the running of applescripts through processing.  I currently have my code set up using the serial event listener and whenever it senses activity on the serial port it will run an applescript.  that applescript plays a certain playlist in itunes and (the applescript)delays until that playlist is done then I have (the same applescript) it switch to another playlist and then the applescript ends.  Once all of that is finished the flow of the program returns back the processing code .  currently , if a serial event occurs while the applescript is running, the command received over serial isn't processed until the applescript finishes its execution. What I want to know is, is it possible to interrupt a applescript while its running (during the 'myScript.execute(errors);' command)if a serial event occurs while that previously executed  applescript is running  ?
Re: using cocoa library to run applescript
Reply #5 - Aug 29th, 2009, 5:58am
 
I tried using the workaround, however, I have no folder named "com" inside System/Library/Java.

Where do i find that thing then?
Re: using cocoa library to run applescript
Reply #6 - Dec 10th, 2009, 10:00am
 
Is it possible to pass a Processing variable to the AppleScript? Also, is there any reference materials for using AppleScript with Processing? Thanks for any help.
Re: using cocoa library to run applescript
Reply #7 - Jan 7th, 2010, 4:27pm
 
Since I wrote my last post questioning how one passes Processing variables to AppleScript code I've discovered a few things. I'm just a beginner in Processing and only moderately proficient with AppleScript so my comments below are for beginners. They may be obvious to everyone else (they sure weren't to me). Please correct or call me on anything you might see amiss. I apologize for not being able to include reference URL's here as I wanted but I have not been on the forum long enough.

Using AppleScript in Processing Sketches

1) Add Cocoa foundation library to Processing - use the link elsewhere on this page for directions

2) Add this line at the beginning of your Processing sketch to import the Cocoa library (which will know what to do with the AppleScript code): import com.apple.cocoa.foundation.*;

3) Add your AppleScript code to the void draw() block

4) Start the first line with "String script = ". Example:   String script = "tell application \"Finder\"" + "\n"

5) Start every other AS line with a plus sign (+)

6) Put these lines after your AS code in the void block:
 println(script);
 executeScript(script);}

void executeScript(String script) {
 NSAppleScript myScript = new NSAppleScript(script);
 NSMutableDictionary errors = new NSMutableDictionary();
 myScript.execute(errors);

7) Put quotations around every AS line

8) "Escape" or put a backslash ("\") before every quotation mark (except the beginning and ending marks of each line) in your AS code

9) End every line (what is usually a line in any AppleScript editor) with what's inside these parenthesis (+ "\n")

10) You can put everything on one line or break the lines using point #9 above

11) The last line requires a semicolon (";") at the end

12) I couldn't get conditionals (if something equals/doesn't equal or is greater/lesser than) to work in AppleScript so I used Processing conditionals within the AppleScript code. To do so end that part of your AS code with a quotation mark, add the plus sign, the Processing code, another plus sign and then continue your AS code with a quotation mark. Example:     + "if " + (v_push != 999) + " then tell application \"System Events\" to key code " + v_push + "\n"

13) The draw block automatically loops (at the speed specified by the frameRate line in the setup block). Example:  frameRate(6);

14) If you don't want the draw block to loop add the noLoop(); line in the setup block

15) You have to declare your AS variables in the first part of the sketch. See here for instructions on the Processing site
Re: using cocoa library to run applescript
Reply #8 - Mar 27th, 2010, 2:07pm
 
I also cannot find "com" inside my /System/Library/Java folder...

OS X 10.6.2, installed all updates as of 3/27/10 (there was a Java update early 2010, if that makes any difference)

Please help!

Thanks.
Re: using cocoa library to run applescript
Reply #9 - Jul 5th, 2010, 8:34am
 
Wind Up Toy wrote on Mar 27th, 2010, 2:07pm:
I also cannot find "com" inside my /System/Library/Java folder...

OS X 10.6.2


The Java/Cocoa bridge has been removed by Apple in 10.6. :-( AFAIK you can use the files from 10.5 – or switch to http://code.google.com/p/rococoa/
Page Index Toggle Pages: 1