View previous topic :: View next topic |
Author |
Message |
tigrezno Apprentice


Joined: 28 Jun 2002 Posts: 251 Location: Spain
|
Posted: Fri Dec 12, 2003 5:18 pm Post subject: Openbox3 scripts, share them!! |
|
|
Hi all, i'm using openbox 3.0, and it rock's.
I have thought that could be a nice idea to share all our scripts, in order to improve our nice wm.
So, here is mine:
Code: |
#!/bin/bash
#
# Shows all files in "DIR" location, associating an action "CMD" to them.
# Be careful with file names, openbox doesn't work fine with strange characters
# in its menu. Use only english characters.
#
# In order to use it, you must add the following line to your menu.xml:
#
# <menu id="1234" label="My files" execute="/path/filemenu" />
#
# Configuration:
#
# file location with terminal slash
DIR=/home/carl/images/
# command to call
CMD=/usr/bin/display
#
# Simple script:
echo "<openbox_pipe_menu>"
for name in $DIR*
do
echo "<item label=\"$(echo $name | gawk -F/ '{print $NF}' | tr 'A-Z' 'a-z')\">"
echo "<action name=\"Execute\"><execute>$CMD $name</execute></action>"
echo "</item>"
done
echo "</openbox_pipe_menu>"
|
|
|
Back to top |
|
 |
Xemoka n00b

Joined: 08 Jul 2004 Posts: 32 Location: BC, Canada
|
Posted: Sat Dec 25, 2004 7:38 pm Post subject: |
|
|
Here's a bash script for mountable drives like cdrom, floppies, and cameras.. here i have it setup for a CD-Rom, Camera, and my Floppy Drive. This script is easily customizable.. just copy the group of text, as and fill out as follows
Code: |
mountable<INSERT NUMBER, ANY NUMBER>="<MOUNT DIR>"
MOUNT<SAME NUMBER>=`cat /etc/mtab | grep "$mountable<SAME NUMBER>"`
if [ -n "$MOUNT<SAME NUMBER>" ]; then
echo " <item label=\"Unmount $mountable<SAME NUMBER>\">"
echo " <action name=\"Execute\"><execute>umount $mountable<SAME NUMBER></execute></action>"
echo " </item>"
else
echo " <item label=\"Mount $mountable<SAME NUMBER>\">"
echo " <action name=\"Execute\"><execute>mount $mountable<SAME NUMBER></execute></action>"
echo " </item>"
fi
|
Of, 'course dont include the <'s and >'s when replacing...
And here's what I use Exactly
Code: |
#!/bin/bash
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
echo "<openbox_pipe_menu>"
mountable1="/mnt/cdrom"
MOUNT1=`cat /etc/mtab | grep "$mountable1"`
if [ -n "$MOUNT1" ]; then
echo " <item label=\"Unmount $mountable1\">"
echo " <action name=\"Execute\"><execute>umount $mountable1</execute></action>"
echo " </item>"
else
echo " <item label=\"Mount $mountable1\">"
echo " <action name=\"Execute\"><execute>mount $mountable1</execute></action>"
echo " </item>"
fi
mountable2="/mnt/camera"
MOUNT2=`cat /etc/mtab | grep "$mountable2"`
if [ -n "$MOUNT2" ]; then
echo " <item label=\"Unmount $mountable2\">"
echo " <action name=\"Execute\"><execute>umount $mountable2</execute></action>"
echo " </item>"
else
echo " <item label=\"Mount $mountable2\">"
echo " <action name=\"Execute\"><execute>mount $mountable2</execute></action>"
echo " <action name=\"Execute\"><execute>rox -s=$mountable2/</execute></action>"
echo " </item>"
fi
mountable3="/mnt/floppy"
MOUNT2=`cat /etc/mtab | grep "$mountable3"`
if [ -n "$MOUNT3" ]; then
echo " <item label=\"Unmount $mountable3\">"
echo " <action name=\"Execute\"><execute>umount $mountable3</execute></action>"
echo " </item>"
else
echo " <item label=\"Mount $mountable3\">"
echo " <action name=\"Execute\"><execute>mount $mountable3</execute></action>"
echo " <action name=\"Execute\"><execute>rox -s=$mountable3/</execute></action>"
echo " </item>"
fi
echo "</openbox_pipe_menu>"
|
_________________ #gentoo-glbt
Spend a little time and answer a few questions!
Learn how to Properly emerge ~arch |
|
Back to top |
|
 |
bladdo Guru


Joined: 19 Jul 2004 Posts: 334 Location: NJ
|
Posted: Sat Dec 25, 2004 9:24 pm Post subject: |
|
|
I made this simple script to check my gmail account to see if it had any new messages.
gmail.pl :
Code: |
#!/usr/bin/perl
#Simple openbox pipe menu programmed in perl to see how many new messages there are.
#1.chmod this file +x
#2.Edit the menu.xml file accordingly to execute this script like any other
#3.Then where in this script it says yourusernamehere and yourpasswordhere in this script
#Fill in accordingly
#4.Finally do the following in shell:
#su
#cpan
#install
#Mail::Webmail::Gmail
#exit
#Made By Mello aka Mi
use Mail::Webmail::Gmail;
$user = "yourusernamehere";
$pass = "yourpasswordhere";
my $count;
my $gmail = Mail::Webmail::Gmail->new(
username => $user, password => $pass,
);
my @l = $gmail->get_labels();
foreach $currleb (@l) {
my $m = $gmail->get_messages( label => $currleb );
foreach ( @{ $m } ) {
if ( $_->{ 'new' } ) {
$count++;
}
}
}
print "<openbox_pipe_menu>\n";
print "<item label=\"You have $count new messages\">\n";
print "<action name=\"Execute\"><execute>true</execute></action>\n";
print "</item>\n";
print "</openbox_pipe_menu>\n";
|
Also , if anyone knows the link to get straight to your gmail account depending on the url please tell me. I will incorporate it into the script. _________________ Bladdo formerly >Milo<
bladdo.net - scripting and design
Creator of AIM Bot: Tiny Tiny Bot - the bot that learns
distro: gentoo | window manager: pekwm |
|
Back to top |
|
 |
tigrezno Apprentice


Joined: 28 Jun 2002 Posts: 251 Location: Spain
|
Posted: Sat Dec 25, 2004 9:38 pm Post subject: |
|
|
yaw!! One year later  |
|
Back to top |
|
 |
twstd3bc Apprentice

Joined: 07 Feb 2003 Posts: 289 Location: Los Angeles, USA
|
Posted: Sun Dec 26, 2004 2:26 am Post subject: Re: Openbox3 scripts, share them!! |
|
|
Very nice! It's about time someone generalized this process. Why don't you alter this slightly so it can take the DIR and CMD as command line arguments. That way the file will never have to be edited.
tigrezno wrote: | Hi all, i'm using openbox 3.0, and it rock's.
I have thought that could be a nice idea to share all our scripts, in order to improve our nice wm.
So, here is mine:
Code: |
#!/bin/bash
#
# Shows all files in "DIR" location, associating an action "CMD" to them.
# Be careful with file names, openbox doesn't work fine with strange characters
# in its menu. Use only english characters.
#
# In order to use it, you must add the following line to your menu.xml:
#
# <menu id="1234" label="My files" execute="/path/filemenu" />
#
# Configuration:
#
# file location with terminal slash
DIR=/home/carl/images/
# command to call
CMD=/usr/bin/display
#
# Simple script:
echo "<openbox_pipe_menu>"
for name in $DIR*
do
echo "<item label=\"$(echo $name | gawk -F/ '{print $NF}' | tr 'A-Z' 'a-z')\">"
echo "<action name=\"Execute\"><execute>$CMD $name</execute></action>"
echo "</item>"
done
echo "</openbox_pipe_menu>"
|
|
|
|
Back to top |
|
 |
bladdo Guru


Joined: 19 Jul 2004 Posts: 334 Location: NJ
|
Posted: Sun Dec 26, 2004 3:31 pm Post subject: |
|
|
Gmail Check v.2.0
Fixed:
*Shows you messages subjects
*No longer depends on Labels
*Brings you to your inbox when you click on it
*Reduced code size
*More clear instructions
Code: |
#!/usr/bin/perl
#############--------------------------Gmail Checker v.2.0---------------------------##############
#Simple openbox pipe menu programmed in perl to see how many new
#messages there are.
#1.chmod this file +x
#2.To install just edit the menu.xml file and put
#<menu id="gmail" label="Gmail" execute="~/.config/openbox/scripts/gmail.pl" /> near the top where the other menues are being definded
#and <menu id="gmail" /> in the root menu
#3.Then where in this script it says yourusernamehere and yourpasswordhere
#Fill in accordingly
#4.Finally do the following in shell:
#su
#cpan
#install
#Mail::Webmail::Gmail
#exit
#Made By Mello
############------------------------End Instructions--------------------########################
use Mail::Webmail::Gmail;
#Your username
$user = "yourusernamehere";
#Your password
$pass = "yourpasswordhere";
#Your browser
$browser = "firefox";
my $count;
my $gmail = Mail::Webmail::Gmail->new(
username => $user, password => $pass,
);
my @subjects;
$m = $gmail->get_messages();
foreach ( @{ $m } ) {
if ( $_->{ 'new' } ) {
$count++;
$_->{'subject'} =~ s/<(.|\n)+?\>//g;
push @subjects, $_->{'subject'};
}
}
print "<openbox_pipe_menu>\n";
print "<item label=\"You have $count new messages\">\n";
print "<action name=\"Execute\"><execute>$browser https://www.google.com/accounts/ServiceLoginBoxAuth?service=mail&continue=https%3A%2F%2Fgmail.google.com%2Fgmail&Email=$user&Passwd=$pass</execute></action>\n";
print "</item>\n";
print "<menu id=\"messages\" label=\"Messages\"> /\n";
foreach $tempsub (@subjects) {
print "<item label=\"$tempsub\">\n";
print "<action name=\"Execute\"><execute>true</execute></action>\n";
print "</item>\n";
}
print "</menu>\n";
print "</openbox_pipe_menu>\n";
|
_________________ Bladdo formerly >Milo<
bladdo.net - scripting and design
Creator of AIM Bot: Tiny Tiny Bot - the bot that learns
distro: gentoo | window manager: pekwm |
|
Back to top |
|
 |
tigrezno Apprentice


Joined: 28 Jun 2002 Posts: 251 Location: Spain
|
Posted: Sun Dec 26, 2004 3:38 pm Post subject: |
|
|
the problem when using internet resources is that openbox gets frozen until the end of the script, so if your connection is very slow (lots of downloads) you will get a frozen desktop :S |
|
Back to top |
|
 |
syscrash Guru


Joined: 14 Apr 2003 Posts: 541
|
Posted: Sun Dec 26, 2004 4:37 pm Post subject: |
|
|
http://syscrash.hopto.org/stuff/temphax.png
Something I've been working on (the older versions definitely aren't as quick as this one). You have to run a daemon in the background that fetches the weather data at a user-defined interval, and it isn't much of a resource hog
Its still experimental though, probably not ready for release. _________________ Play ET? Come by #gentoo.et on freenode!
http://syscrash.ca |
|
Back to top |
|
 |
tigrezno Apprentice


Joined: 28 Jun 2002 Posts: 251 Location: Spain
|
Posted: Sun Dec 26, 2004 7:04 pm Post subject: |
|
|
Here is another one, this time printing current users in the form (with no action):
3 users
----------------------
john [192.168.0.6]
larry [192.168.0.4]
mary [192.168.0.3]
[edit] updated (response time depends on dns queries)
Code: | #!/bin/bash
echo "<openbox_pipe_menu>"
echo "<item label=\"$(w | head -n 1 | awk '{print $4,"users"}')\" />"
echo "<separator />"
w -fh | awk '{ print "<item label=\""$1,"[",$3,"]\" />" }'
echo "</openbox_pipe_menu>"
|
|
|
Back to top |
|
 |
Xemoka n00b

Joined: 08 Jul 2004 Posts: 32 Location: BC, Canada
|
Posted: Mon Dec 27, 2004 2:46 am Post subject: Re: Openbox3 scripts, share them!! |
|
|
twstd3bc wrote: | Very nice! It's about time someone generalized this process. Why don't you alter this slightly so it can take the DIR and CMD as command line arguments. That way the file will never have to be edited.
|
Yes, that i would, except.. I have to learn how to do that. lol. As it is, i'm new to coding for bash, and openbox.
Hmm.. the only problem i can think of htis, is it would have to take the Number of cl args and decide how many things to put in the menu, otherwise it would have a seperate menu for each device (not exactly what i was personally after...) give me a few hints and i'll give 'er a try.. heh _________________ #gentoo-glbt
Spend a little time and answer a few questions!
Learn how to Properly emerge ~arch |
|
Back to top |
|
 |
twstd3bc Apprentice

Joined: 07 Feb 2003 Posts: 289 Location: Los Angeles, USA
|
Posted: Mon Dec 27, 2004 5:18 am Post subject: Re: Openbox3 scripts, share them!! |
|
|
Xemoka wrote: | twstd3bc wrote: | Very nice! It's about time someone generalized this process. Why don't you alter this slightly so it can take the DIR and CMD as command line arguments. That way the file will never have to be edited.
|
Yes, that i would, except.. I have to learn how to do that. lol. As it is, i'm new to coding for bash, and openbox.
Hmm.. the only problem i can think of htis, is it would have to take the Number of cl args and decide how many things to put in the menu, otherwise it would have a seperate menu for each device (not exactly what i was personally after...) give me a few hints and i'll give 'er a try.. heh |
Would you believe that Daniel Robbins wrote a three-part Bash tutorial on IBM Developerworks? It's a quick read, and very useful. Anyway, the $@ variable gives you all the command line arguments, $0 gives the name of the script, $1 gives the fisrt argument, $2 gives the second, etc... You would only need to change a couple lines in your script for the basic functionality. |
|
Back to top |
|
 |
twstd3bc Apprentice

Joined: 07 Feb 2003 Posts: 289 Location: Los Angeles, USA
|
Posted: Mon Dec 27, 2004 5:23 am Post subject: Re: Openbox3 scripts, share them!! |
|
|
Xemoka wrote: | twstd3bc wrote: | Very nice! It's about time someone generalized this process. Why don't you alter this slightly so it can take the DIR and CMD as command line arguments. That way the file will never have to be edited.
|
Yes, that i would, except.. I have to learn how to do that. lol. As it is, i'm new to coding for bash, and openbox.
Hmm.. the only problem i can think of htis, is it would have to take the Number of cl args and decide how many things to put in the menu, otherwise it would have a seperate menu for each device (not exactly what i was personally after...) give me a few hints and i'll give 'er a try.. heh |
Opps! Jut realized, I wasn't responding to your post originally. I was responding to the irst post in this thread. |
|
Back to top |
|
 |
Xemoka n00b

Joined: 08 Jul 2004 Posts: 32 Location: BC, Canada
|
Posted: Mon Dec 27, 2004 6:51 am Post subject: Re: Openbox3 scripts, share them!! |
|
|
twstd3bc wrote: | Opps! Jut realized, I wasn't responding to your post originally. I was responding to the irst post in this thread. |
actually thats my fault, I assumed what your quote contained, and not what it actually contained. lol.. whops... anyway, still a good idea.. lol, going to try to work it in heh _________________ #gentoo-glbt
Spend a little time and answer a few questions!
Learn how to Properly emerge ~arch |
|
Back to top |
|
 |
tigrezno Apprentice


Joined: 28 Jun 2002 Posts: 251 Location: Spain
|
Posted: Mon Dec 27, 2004 4:40 pm Post subject: |
|
|
Here is a modified version of my first script, so you don't have to edit it, just pass parameters.
Code: |
#!/bin/bash
#
# Usage: readdir DIR CMD
#
# Example: readdir /home/carl/images "display -geometry 640x480"
#
DIR=$1
CMD=$2
echo "<openbox_pipe_menu>"
if [ "$DIR" -a "$CMD" -a -d "$DIR" ]
then
for name in $DIR/*
do
echo "<item label=\"$(echo $name | gawk -F/ '{print $NF}' | tr 'A-Z' 'a-z')\">"
echo "<action name=\"Execute\"><execute>$CMD $name</execute></action>"
echo "</item>"
done
else
echo "<item label=\"Error in parameters\" />"
fi
echo "</openbox_pipe_menu>"
|
|
|
Back to top |
|
 |
s0r0k n00b

Joined: 04 Jul 2004 Posts: 31
|
Posted: Tue Dec 28, 2004 4:31 pm Post subject: |
|
|
Hi,
I've got a script that shows the currently playing song from a web radio:
Code: |
#!/usr/bin/perl
use strict;
use IO::Socket;
my ($host,$port,$file);
if($ARGV[0] =~ /http:\/\/([^\/:]*):?([0-9]{0,5})?\/?(.*)/) {
$host = $1;
$port = $2;
$file = $3;
} else {
print "usage: radio-obpipe.pl http://someurl[:someport][/somefile]\n";
exit;
}
my $sock = IO::Socket::INET->new(PeerAddr => $host,
PeerPort => $port,
Proto => 'tcp')
or die "Connection failed";
print $sock "GET /$file HTTP/1.0\nicy-metadata:1\n\n";
print "<openbox_pipe_menu>\n";
while(my $line = <$sock>) {
if($line =~ /^.*StreamTitle=\'(.*)\';S.*$/) {
print "<item label=\"$1\"/>\n";
print "</openbox_pipe_menu>\n";
exit;
}
}
|
|
|
Back to top |
|
 |
misza n00b

Joined: 12 Dec 2003 Posts: 10 Location: Sydney, Australia
|
Posted: Sat Jan 29, 2005 3:41 am Post subject: A few scripts I have written |
|
|
Hi everyone,
I've just found out about openbox's script menu capability and it rocks!
Here's some nice scripts that I've written (bash scripts with alot of awk/sed), first some simple ones
This one gets the date and time, the date item executes xcalendar.
Code: |
#!/bin/bash
echo "<openbox_pipe_menu>"
datestr=`date '+%a %d %b'`
timestr=`date '+%H:%M:%S'`
echo "<item label=\"$datestr\">"
echo "<action name=\"Execute\"><execute>xcalendar</execute></action>"
echo "</item>"
echo "<item label=\"$timestr\">"
echo "</item>"
echo "</openbox_pipe_menu>"
|
This one gets a little summary of disk usage. Uses rox to open each mountpoint.
Code: |
#!/bin/bash
echo "<openbox_pipe_menu>"
df -h | grep '^/dev' | awk '{printf("<item label=\"%s %s/%s %s\">\n<action name=\"Execute\"><execute>rox %s</execute></action>\n</item>\n",$6,$3,$2,$5,$6)}'
echo "</openbox_pipe_menu>"
|
[/code]
This one gets ip address, mem usage, battery usage, and core and system temps.
Launches nedit for ip address for easy copying.
Code: |
#!/bin/sh
echo "<openbox_pipe_menu>"
ipaddr=`/sbin/ifconfig | awk ' /^eth0/ {getline; gsub(":"," "); print $3}'`
echo "<item label=\"$ipaddr\">"
echo "$ipaddr" > /tmp/ip
echo "<action name=\"Execute\"><execute>nedit /tmp/ip</execute></action>"
echo "</item>"
free -m | awk '$1 ~ /Mem/ {printf("<item label=\"M %s/%s %.0f%\">\n</item>\n",$3,$2,$3/$2*100)}'
batt=`cat /proc/acpi/battery/BAT0/state | awk '/^rem/{printf("%d%\n",$3/4400*100)}'`
echo "<item label=\"B $batt\">"
echo "</item>"
tcore=`cat /proc/acpi/thermal_zone/THRC/temperature | awk '{print $2 "C"}'`
tsys=`cat /proc/acpi/thermal_zone/THRS/temperature | awk '{print $2 "C"}'`
echo "<item label=\"C $tcore\">"
echo "</item>"
echo "<item label=\"S $tsys\">"
echo "</item>"
echo "</openbox_pipe_menu>"
|
The trickiest of them all, a recursive dir lister.
Someone must have done it before, but probably with perl or python,
this is an awk/bash version
Script is named obdirlist in your $PATH.
Uses rox to open up the folders, supports folders with spaces in their names.
Nice and fast
Has an open option at the top of each dir with subdirs
Subdirs can be opened by clicking on the item.
Weird things may happen if you have @ in your filenames (unlikely).
The inclusion of $RANDOM as the menu id, with a nanosecond id is sufficient to produce unique menu items most of the time (when fast switching between menus isn't happening).
Code: |
#!/bin/bash
nextdir=`echo "$*" | sed 's/@/ /g'`
cd "$nextdir"
parf=`pwd`
echo "<openbox_pipe_menu>"
echo "<item label=\"open\">"
echo "<action name=\"Execute\"><execute>rox \"$parf\"</execute></action>"
echo "</item>"
echo "<separator />"
for x in `ls -l | grep '^d' | awk '$9 !~ /^\./ {for(i=9;i<=NF;i++) if(i<NF) printf $i "@"; else printf $i;printf "\n";}'`
do
dir=`echo "$x" | sed 's/@/ /g'`
hasdir=`ls -l "$dir" | grep '^d'`
if [ "$hasdir" != "" ]; then
echo "<menu id=\"$parf/$dir/$RANDOM\" label=\"$dir\" execute=\"obdirlist $parf/$dir \" />"
#need to reset random on nanosecond scale, otherwise weird stuff happens!
RANDOM=`date '+%N'`
else
echo "<item label=\"$dir\">"
echo "<action name=\"Execute\"><execute>rox \"$parf/$dir\"</execute></action>"
echo "</item>"
fi
done
echo "</openbox_pipe_menu>"
|
Installation, in ~/.config/openbox/menu.xml
Code: |
<separator />
<menu id="datetime-info" label="date_time" execute="obdate" />
<menu id="sys-info" label="sys_info" execute="obsys" />
<menu id="disk-usage" label="disk_info" execute="obdf" />
<menu id="dir-list_home" label="dir_list ~" execute="obdirlist /home/brent" />
<menu id="dir-list_root" label="dir_list /" execute="obdirlist /" />
<separator />
|
You must specify a dir to obdirlist (the last script, recursive dir lister).
edit: I have made another script, for listing .tex files, you can find it here
I hope you've found these scripts useful!
Last edited by misza on Sat Jan 29, 2005 1:36 pm; edited 3 times in total |
|
Back to top |
|
 |
tigrezno Apprentice


Joined: 28 Jun 2002 Posts: 251 Location: Spain
|
Posted: Sat Jan 29, 2005 11:08 am Post subject: |
|
|
The directory recursive dir have a problem, i tried it time ago, and is that if you enter a directory with a numer of items greater than your screen height, then they will not be showed. There is no menu split or menu scroll function in openbox like in windows. That's the problem. |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|