Showing posts with label gedit. Show all posts
Showing posts with label gedit. Show all posts

Wednesday, September 16, 2009

Read selection

And onto further adventures!

After making that zenspeak script I got told that it'd be more useful, if you could enter a whole lot of text into it. So then it dawned on me that maybe having a Gedit plugin like that could be useful.

So, if you got the External Tools plug-in installed in Gedit, you can put this script in there somewhere, tweak it a bit to use your favorite speech generator, voice, etc., and you're all set to never read a single word again.

One drawback: it won't be easy to stop it if you've let it run, so if you make it read a lot of text, it might be troublesome.

I suppose I don't have it in me to really write stuff here today.

The code:
 
1 #!/bin/bash
2 text=`xargs -0 echo`
3
4 SYSTEM=espeak
5
6 if [ -n "$text" ]
7 then
8 echo "Reading \"$text\" with $SYSTEM."
9
10 if [ $SYSTEM == espeak ]
11 then
12 padsp espeak "$text" -v en+f3
13 elif [ $SYSTEM == festival ]
14 then
15 echo "$text" | festival --tts
16 fi
17 fi


The code is also available at GitHub as gedit/gedit_read_selection.

Tuesday, November 11, 2008

Scripting in gedit

Hey. I didn't know this before, but you can run your own scripts out of gedit. Well, obviously, I was vaguely aware that this was possible, but I didn't know it was so gorram easy! So I've made some scripts that would help me script in the future.

All these scripts are installed by going to Tools > Extrenal Tools, then pressing New and then filling out the fields - most importantly, the Command(s) field.

Ok, here's what I've concocted.

First of all, I didn't want to go to the command line every time I want to make something executable, so there's this:
 
1 #!/bin/bash
2
3 chmod a+x $GEDIT_CURRENT_DOCUMENT_PATH


It's pretty self explanatory, methinks.

Then, I wanted to run a script from gedit, so I did this script:
 
1 #!/bin/bash
2
3 # Open the document's directory (just in case)
4 cd $GEDIT_CURRENT_DOCUMENT_DIR;
5
6 # Display information about script
7 echo -e "Running script: $GEDIT_CURRENT_DOCUMENT_NAME";
8 echo -e "\tin directory: $GEDIT_CURRENT_DOCUMENT_PATH";
9 echo -e "\n";
10
11 # Run script
12 $GEDIT_CURRENT_DOCUMENT_PATH;


It's mostly straightforward (just follow the comments). It displays a lot of info, because I'm the kind of guy who forgets what he ran just a second ago and needs constant reminding.

Finally, I added the ability to insert parameters with a GUI. I stole this concept from one of those default scripts that are put into gedit.
 
1 #!/bin/bash
2
3 # Get parameters for command from user.
4 params=`zenity --entry --title="Run $GEDIT_CURRENT_DOCUMENT_NAME" --text="with these parameters"`
5
6 # Open the document's directory (just in case)
7 cd $GEDIT_CURRENT_DOCUMENT_DIR;
8
9 # Display information about script
10 echo -e "Running script: $GEDIT_CURRENT_DOCUMENT_NAME";
11 echo -e "\tin directory: $GEDIT_CURRENT_DOCUMENT_PATH";
12 echo -e "\twith params: $params";
13 echo -e "\n";
14
15 # Run script
16 $GEDIT_CURRENT_DOCUMENT_PATH $params;


Here, in line 4 I call zenity to gather the parameters from the user and then just stick them to the end of the name of the script. Simple!

Hope this comes in handy.

The code is also available at GitHub in the directory gedit.