Re: Calling Applescript from Netbeans
Re: Calling Applescript from Netbeans
- Subject: Re: Calling Applescript from Netbeans
- From: Philip Ershler <email@hidden>
- Date: Tue, 06 Sep 2011 17:14:18 -0600
On Sep 6, 2011, at 4:47 PM, Alex Zavatone wrote:
> How would you call an external application in NetBeans?
>
> On Sep 6, 2011, at 4:39 PM, Philip Ershler wrote:
>
>> Hi,
>> I am running Snow Leopard 10.6.8 and Netbeans IDE 7.0.1. I am trying to learn now to call an Applescript from Java in Netbeans. I need to pass a parameter to the Applescript as well. Can anyone suggest any links that might help me out. So far I have been unable to ask Mr. Google the appropriate question(s) to find any useful links.
>>
>> Thanks, Phil
Actually, I finally found the "magic incantation" for Google that produced the following link.
http://www.devdaily.com/blog/post/java/how-run-multi-multiple-line-applescript-java-program
With the above link and another link embedded on the page I kludged up this code that works like a champ in a NetBeans GUI.
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
private void recordButtonActionPerformed(java.awt.event.ActionEvent evt) {
String theScript = "tell application \"QuickTime Player 7\"\n"
+ "activate\n"
+ "new movie recording\n"
+ "set name of window 1 to \"junk\"\n"
+ "start first recording\n"
+ "delay 10\n"
+ "stop first recording\n"
+ "close window 1 saving no\n"
+ "end tell";
ScriptEngineManager mgr = new ScriptEngineManager();
ScriptEngine engine = mgr.getEngineByName("AppleScript");
try {
engine.eval(theScript);
} catch (ScriptException ex) {
Logger.getLogger(HTS_UI.class.getName()).log(Level.SEVERE, null, ex);
}
}
Thanks, Phil
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden