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 & HelpIntegration › open() function in ubuntu9.10
Page Index Toggle Pages: 1
open() function in ubuntu9.10 (Read 2150 times)
open() function in ubuntu9.10
Jan 25th, 2010, 2:16pm
 
Hi,
i want to run a shellscript via processing.
to do so I wrote: open("/home/.../script.sh")
This keeps opening it with gnome´s standard application (gedit) instead of running it. CHMOD is set to 777 and I deleted gedit as default for the scriptfile and replaced it with "bash".
However, it´s still opening in gedit.
I´m quite new to processing and i could really use some help here.

Thanks in advance, chris
Re: open() function in ubuntu9.10
Reply #1 - Jan 25th, 2010, 2:32pm
 
I achieved this in Ubuntu 9.04 (french version, so maybe the labels below are incorrect) :

right click on your script file / properties / open with / add : custom command : "bash" (without the quotes)

it should then run as expected.
Re: open() function in ubuntu9.10
Reply #2 - Jan 25th, 2010, 2:38pm
 
Thanks for your reply, unfortunately I´ve already tried this and it didn´t work. I even removed everything but "bash" from the "Open With" tab in the file´s properties.
Any other ideas?
Re: open() function in ubuntu9.10
Reply #3 - Jan 26th, 2010, 1:24am
 
try a shebang in the first line of your script, like this:

#!/bin/bash
Re: open() function in ubuntu9.10
Reply #4 - Jan 27th, 2010, 12:29am
 
The shebang was already in there.
Meanwhile I installed Debian, hoping the function would work with another OS; nope.
Slowly I get the feeling that I must be missing something elementary.
This is the code I use:

import processing.serial.*;

Serial myPort;
char inBuffer;
int wait, now, timeout = 10000;
boolean hold = false;

void setup() {
 size(200,200);
 println(Serial.list());
 myPort = new Serial(this, Serial.list()[0], 9600);
 fill(#36ff00);
}

void draw() {
 
 while (myPort.available() > 0)
 {
   inBuffer = myPort.readChar();  

   if(inBuffer=='1')
   {      
     if ( !hold )
     {
       fill(#ff0000);
       println("so far it works");
       open("/home/chis/script.sh");        
       wait = millis();
       hold = true;
     }
   }
 }
 
 now = millis();
   
 if (now > (wait + timeout))
 {
   hold = false;
   fill(#36ff00);
 }
   
 rect(0,0,200,200);
}

Re: open() function in ubuntu9.10
Reply #5 - Jan 27th, 2010, 2:50am
 
works here. Ubuntu 8.10, processing 1.05. what's in your script?
Re: open() function in ubuntu9.10
Reply #6 - Jan 27th, 2010, 3:27am
 
It´s a script that should post something on twitter, which it does when executed manually.
The odd thing is:
Processing opens the script in gedit, which is ok so far.
When I change the "open with" option to "bash", nothing happens.
Now I tried to change it back to gedit (just for the fun of it), but even this doesn´t seem to work anymore.
It´s like Gnome doesnt even notice/apply the changes I made after removing gedit from the list.
I experienced this on both Ubuntu and Debian now.
I´m going nuts about this.
Re: open() function in ubuntu9.10
Reply #7 - Jan 27th, 2010, 4:15am
 
I can reproduce the problem if I put a text editor at the top of the "open with" list. But then if I put /bin/bash at the top, it fixes it. I'm using Xfce though, so maybe Gnome is the culprit. There's a howto on Gnome file associations here: http://ubuntuforums.org/archive/index.php/t-51012.html maybe that helps
Re: open() function in ubuntu9.10
Reply #8 - Jan 27th, 2010, 6:12am
 
Thank you very much for the info! I´ll try this when I´m home.  When it won´t help, I´ll try Xfce too.
Re: open() function in ubuntu9.10
Reply #9 - Jan 27th, 2010, 12:49pm
 
there's an entry in ~/.processing/preferences.txt called 'launcher' which it uses. mine's set to gnome-open (ubuntu koala, gnome as a desktop)

i think gnome-open is the thing that isn't respecting the mime-type. i've tried a bunch of stuff and nothing changed, it just opened in gedit every time

i changed my launcher preference to 'bash' and it runs within bash...
Re: open() function in ubuntu9.10
Reply #10 - Jan 27th, 2010, 12:54pm
 
ah, ok, it's not enough to right click on the object and choose 'open with', you need to right click on file and choose 'Properties' and set the 'Open With' there. only then will it open in bash in gnome-open and thus in processing open()

(don't forget to change launcher property back if you have. and you need to do this whilst processing isn't running)
Re: open() function in ubuntu9.10
Reply #11 - Jan 28th, 2010, 2:15am
 
It works!
I used KDE instead of gnome; no problems at all.
I didn´t yet try your suggestions regarding gnome, but both, changing the mime-association and editing the the preferences.txt (the preferences´"open with"-tab allready had bash on top) make perfect sense to me. I´ll definitly have a look at this the next time I´m on a gnome sytem.
Thank you very much for your help!
chris
Page Index Toggle Pages: 1