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 › Starting an apple script. Cant't find library
Page Index Toggle Pages: 1
Starting an apple script. Cant't find library (Read 1220 times)
Starting an apple script. Cant't find library
Feb 1st, 2008, 3:29pm
 
Hi,
I'm using  the following:

import com.apple.cocoa.foundation.*;

and

NSAppleScript shutdownComputer = new NSAppleScript( "tell application \"Finder\" to shut down" );
....
 shutdownComputer.execute(errors);
...
etc.

It can run an apple script to shut down my installation. It works fine if I run it out of the Processing IDE, but if I export it as an application, I get the following error message:

java.lang.NoClassFoundError: com/apple/cocoa/foundation/NSAppleScript

I've googled all over m but fouond no solution. Any ideas?

thanks.

jmfuo
Re: Starting an apple script. Cant't find library
Reply #1 - Feb 1st, 2008, 3:58pm
 
you can run it as shell script:

Code:

void setup()
{
shellExec("osascript -e \"tell application \\\"Finder\\\" to display dialog \\\"hello processing!\\\"\"");
}

Vector shellExec ( String command )
{
return shellExec ( new String[]{ "/bin/bash", "-c", command } );
}

Vector shellExec ( String[] command )
{
Vector lines = new Vector();
try {
Process process = Runtime.getRuntime().exec ( command );

BufferedReader inBufferedReader = new BufferedReader( new InputStreamReader ( process.getInputStream() ) );
BufferedReader errBufferedReader = new BufferedReader( new InputStreamReader ( process.getErrorStream() ) );

String line, eline;
while ( (line = inBufferedReader.readLine() ) != null && !errBufferedReader.ready() )
{
lines.add(line);
}
if ( errBufferedReader.ready() ) {
while ( (eline = errBufferedReader.readLine() ) != null )
{
println( eline );
}
return null;
}
int exitVal = process.waitFor();

inBufferedReader.close(); process.getInputStream().close();
errBufferedReader.close(); process.getErrorStream().close();
}
catch (Exception e)
{
e.printStackTrace();
return null;
}

return lines;
}


"osascript -e" lets you run applescripts directly from the shell ..

F
Re: Starting an apple script. Cant't find library
Reply #2 - Feb 1st, 2008, 6:32pm
 
Thanks very much. that did the trick.

more generally however, if I import an apple java library such as com.apple.cocoa.foundation, why does it work when the app is started from the IDE, but not from the exported app. Is there a way to make exported apps find these libraries?

thanks

fuo
Page Index Toggle Pages: 1