You are not logged in.
As always Anonymous comes through. This works perfectly.
And being a true genius he prefers to remain anonymous. 
I gotta take a look at this.
#! Etiquette | Conky PitStop | VSIDO | Interactive LUA
Weather v9000 | Teo x4 Sites | Arclance | Finnish
Offline
Known bugs:
Doesn't handle characters like '&' well because Openbox's XML doesn't much like them.
You have to escape '&' as '&', also > < " or ' if they should appear in a filename (unlikely, agreed) need to be escaped as
< > " or ' respectively. The places menu does it in bash with:
case "$path" in # only escape if string needs it
*\&*|*\<*|*\>*|*\"*|*\'*) pathe=$(sed "s/\&/\&/g;s/</\</g;s/>/\>/g;s/\"/\"/g;s/'/\'/g;") <<XXX
$path
XXX
;;
*)pathe=$path;;
esacwhere $path is the path to the file, and $pathe is the escaped version. I can't offer any help with python though. 
John
--------------------
( a boring Japan blog , and idle twitterings )
Offline
I can't offer any help with python though.
Perhaps not, but you led me in the right direction. I've added support for handling '&'s into the script. Seems to work quite well now -- at least for my uses. The updated version also includes a few cleanups and additional comments for anyone interested in modifying it.
So here it is, a python pipemenu for recursive listing of recently modified files:
http://crunchbanglinux.org/pastebin/1129
EDIT: Fixed a bug to avoid hanging on non-existing directories (helpful with network mounts that are missing.) Also cleaned up / slimmed down a good deal.
Last edited by jmbarnes (2011-07-19 00:58:51)
IRC: PizzaAndWine Script bits: Incremental Backup | Sleep Timer
Offline
Just wanted to thanks anonymous for posting the MoC script. If I didn't read this thread I wouldn't have known about MoC. Just installed it and fired it up and works beautifully. Light and fast music player. Very cool. Just might end up dumping DeadBeef for this one.
The script will come in handy for a console based media player. Thanks anon.
Last edited by h8uthemost (2011-09-08 23:03:03)
We are a nice, friendly community here and I hope we stay that way.
Offline
I made a devices pipe menu. It shows you the mountpoint and device file it corresponds to. It also lets you open it in a file manager (default thunar) or device manager (default palimpsest). If you have any optical disks, it will show you the type of disk (cd, dvd etc.) and lets you open it in the default file manager or eject it. It will also show any loop devices: it shows mountpoint and source directory (if needed, the end is shortened to fit the entry). In it's sub-menu, it shows the name of the source image and device file, and lets you open the mountpoint or source directory. On the bottom, it has a link to the recycle bin.
(I've almost finished describing it, I promise!) It has a load of configuration options at the top of the script. It lets you choose the default file manager, the disk manager, eject command and recycle bin command, and lets you choose whether to show the recycle bin in the menu, and whether to show the disk manager, and whether to show the eject command.
Maybe a screenshot would show it better... so:
The only bug I've noticed is that the first time you start it when you log on, it takes a long time to show anything, and freezes openbox. But after ~10 seconds, it works fine again, and is quite fast any time after that in the same session.
Script:
#!/bin/bash
##############################################################################
##############################################################################
##########CONFIGURATION#######################################################
##############################################################################
##############################################################################
filemanager='thunar ' #points to your favoured file manager. If this isn't working, try removing or deleting a space as applicable on this variable.
diskmanager='palimpsest --show-volume=' #points to your favoured disk manager. If this isn't working, try removing or deleting a space as applicable on this variable.
##############################################################################
showbin='true' #set as either true or false (defaults to true). Sets whether to link to the rubbish bin in the menu or not.
bincommand='thunar trash://' #the command to use to open the rubbish bin. Not needed if showbin=false.
##############################################################################
showeject='true' #set as either true or false (defaults to true). Sets whether to show an eject option for optical disks.
ejectcommand='eject -T' #points to the command to use for ejecting disks
##############################################################################
showdm='true' #set as either true or false (defaults to true). Sets whether to show a disk management option for block devices.
##############################################################################
mediaplayer='vlc' #sets the media player to be used. Bear in mind, the media player has to be able to accept block devices on the command line
showmp='true' #set as either true or false (defaults to true). Sets whether to show a media player in the optical disk menus
##############################################################################
##############################################################################
##########END CONFIGURATION###################################################
##############################################################################
##############################################################################
echo "<openbox_pipe_menu>" #start of pipemenu
###############
#block devices#
###############
list=$(ls /sys/block | grep -v sr0 | grep -v scd0 | grep -v ram* | grep -v loop* | grep -v fd* | while read line; do ls /dev | grep -e "$line"; done)
devs=$(echo "$list" | while read line; do blkid /dev/$line; done)
echo "$devs" | while read line; do
device=${line%%:*}
devline=$(mount | grep $device)
devlinepass1=${devline##/dev/*on }
mountpoint=${devlinepass1%% type *}
devlinepass1=
devline=
if [ -n "$mountpoint" ]; then
echo "<menu id=\"$device\" label=\"$device mounted at $mountpoint\">"
echo "<item label=\"open in file manager\"><action name=\"Execute\"><execute>$filemanager\"$mountpoint\"</execute></action></item>"
if [ ! "$showdm" = "false" ]; then
echo "<item label=\"open in disk utility\"><action name=\"Execute\"><execute>$diskmanager$device</execute></action></item>"
fi
echo "</menu>"
fi
done
###############
#optical disks#
###############
ls /sys/block | grep -e 'sr\|scd' | while read optdisks; do
line=$(udisks --show-info /dev/$optdisks | grep -e "has media:" | column -t | grep -w 1)
if [ -n "$line" ]; then
media1=$(udisks --show-info /dev/$optdisks | grep -e "media:" | column -t | grep -v rotational | grep -v "has" | column -t | tr '_' ' ')
media=${media1##media:}
echo "<separator/>"
echo "<menu id=\"device\" label=\"$media\">"
if [ ! "$showmp" = "false" ]; then
echo "<item label=\"Open in VLC\"><action name=\"Execute\"><execute>$mediaplayer \"/dev/$optdisks\"</execute></action></item>"
fi
echo "<item label=\"Open in file manager\"><action name=\"Execute\"><execute>$filemanager\"/media/cdrom0\"</execute></action></item>"
if [ ! "$showeject" = "false" ]; then
echo "<item label=\"eject disk\"><action name=\"Execute\"><execute>$ejectcommand</execute></action></item>"
fi
echo "</menu>"
fi
done
##############
#loop devices#
##############
mount | grep -e "/dev/loop[[:digit:]]" | while read line; do
device=${line// on*}
infodmp=$(udisks --show-info $device | grep -e "filename" | tr -s ' ')
source1=${infodmp//*filename: }
name=$(basename "$source1")
source=$(dirname "$source1" | head -c 30)...
pass1=${line//$device on }
mountpoint=${pass1// type*}
if [ -n "$mountpoint" ]; then
echo "<separator/>"
echo "<menu id=\"$source\" label=\"$source on $mountpoint\">"
echo "<separator label=\"$name ($device)\" />"
echo "<item label=\"Open in file manager\"><action name=\"Execute\"><execute>$filemanager\"$mountpoint\"</execute></action></item>"
echo "<item label=\"Open source directory in file manager\"><action name=\"Execute\"><execute>$filemanager\"$source\"</execute></action></item>"
echo "</menu>"
fi
done
#############
#rubbish bin#
#############
if [ ! "$showbin" = "false" ]; then
echo "<separator/>"
echo "<item label=\"Rubbish bin\"><action name=\"Execute\"><execute>$bincommand</execute></action></item>"
fi
echo "</openbox_pipe_menu>" #end of pipemenuLast edited by jazzerit (2011-10-29 14:37:13)
Offline
For device management there is also obdevicemenu
Offline
ok ive just discovered the joys of pipe menus
and as there doesnt seem to be a crunchbang forum thread so i thought i would start one.ok heres mine, used for controlling MPD
#!/usr/bin/env python # # Author: Ben Holroyd <holroyd.ben@gmail.com> # License: GPL 3.0+ # # This script requires python-mpd # # Usage: # Put an entry in ~/.config/openbox/menu.xml: # <menu id="mpd" label="MPD" execute="~/.config/openbox/scripts/ompb.py" /> # import mpd, os, sys, socket mpdport = 6600 musicfolder ='/home/ben/music/' filelist = True #potentially slow and unwieldy with a large collection of music playlist = True #same for this program = sys.argv[0] client = mpd.MPDClient() try: client.connect("localhost", mpdport) except socket.error: print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" print "<openbox_pipe_menu>" print " <item label=\"MPD not running, click to start\">" print " <action name=\"Execute\"><execute>mpd</execute></action>" print " </item>" print "</openbox_pipe_menu>" sys.exit(0) song = client.currentsong() stats = client.stats() status = client.status() def play(): if status['state'] == "stop" or status['state'] == "pause": client.play() elif status['state'] == "play": client.pause() def volume(vol): if vol == "up": client.setvol(int(status['volume'])+10) elif vol == "down": client.setvol(int(status['volume'])-10) try: if (sys.argv[1] == "play"): play() elif (sys.argv[1] == "stop"): client.stop() elif (sys.argv[1] == "prev"): client.previous() elif (sys.argv[1] == "next"): client.next() elif (sys.argv[1] == "add"): client.add(sys.argv[2]); client.play() elif (sys.argv[1] == "clear"): client.clear() elif (sys.argv[1] == "volume"): volume(sys.argv[2]) elif (sys.argv[1] == "playlist"): client.delete(client.playlist().index(sys.argv[2])) elif sys.argv[1] == "random": client.random(int(not int(client.status()['random'])and True or False)) elif sys.argv[1] == "repeat": client.repeat(int(not int(client.status()['repeat'])and True or False)) except IndexError: pass def item_entry(indent, label, option = '', song = ''): """label = label on menu, option = play/pause/stop etc, song = path to song """ print "%s<item label=\"%s\">"%(indent, label) print "%s <action name=\"Execute\"><execute>%s %s '%s'</execute></action>" % (indent, program, option, song) print "%s</item>" % (indent) def file_walk(dir,indent): """ walks through music directory building a menu to view albums""" files = os.listdir(dir) files.sort() for file in files: path = os.path.join(dir,file) if os.path.isdir(path): print "%s<menu id=\"%s\" label=\"%s\">"%(indent, file, file) item_entry(indent+' ','Add all to playlist','add' ,path.replace(musicfolder,'')) print "%s <separator />" % indent file_walk(path,indent+' ') print "%s</menu>" % indent else: item_entry(indent,file,'add',path.replace(musicfolder,'')) indent = indent[2:] def track_info(label): print " <menu id=\"%s\" label=\"%s\">"%(label,label) print " <item label=\"Artist: %s\"/>" % song['artist'] print " <item label=\"Album: %s\"/>" % song['album'] print " <item label=\"Tracklength: %.2f\"/>" % ((int(song['time'])/60)+(int(song['time'])%60.0/100)) print " <item label=\"Track: %s\"/>" % song['track'] print " <item label=\"filetype: %s\"/>" % song['file'][song['file'].rfind('.')+1:] #print " <item label=\"Genre: %s\"/>" % song['genre'] print " </menu>" print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" print "<openbox_pipe_menu>" if status['state'] != "stop": track_info("Playing: %s - " % song['artist']) track_info(song['title']) print " <separator />" print " <item label=\"Status: %s\"/>" % {'play':'Playing','pause':'Paused','stop':'Stopped'}[status['state']] print " <separator />" item_entry(' ', 'Play/Pause', 'play') item_entry(' ', 'Stop', 'stop') item_entry(' ', 'Prev', 'prev') item_entry(' ', 'Next', 'next') print " <separator />" if filelist == True: print " <menu id=\"Albums\" label=\"Albums\">" file_walk(musicfolder,' ') print " </menu>" print " <separator />" if playlist == True: print " <menu id=\"Playlist\" label=\"Playlist\">" print " <item label=\"Click to remove from playlist\"/>" print " <separator />" for entries in client.playlist(): item_entry(' ', entries, 'playlist', entries) print " </menu>" print " <separator />" item_entry(' ', 'Clear Playlist', 'clear') item_entry(' ', 'Random %s' % (int(status['random']) and '[On]' or '[Off]'), 'random') item_entry(' ', 'Repeat %s' % (int(status['repeat']) and '[On]' or '[Off]'), 'repeat') print " <menu id=\"volume\" label=\"Volume [%s]\">" % (int(status['volume']) > 0 and status['volume']+'%' or 'mute') item_entry(' ', 'Volume + 10\% ', 'volume up') item_entry(' ', 'Volume - 10\%', 'volume down') print " </menu>" print " <separator />" print " <menu id=\"stats\" label=\"Database Stats\">" print " <item label=\"Artists in database: %s\"/>" % stats['artists'] print " <item label=\"Albums in database: %s\"/>" % stats['albums'] print " <item label=\"Songs in database: %s\"/>" % stats['songs'] print " </menu>" print "</openbox_pipe_menu>"to use you need to add an entry to ~/.config/openbox/menu.xml
(also accessible through the menu preferences-->openbox config --> edit menu.xml)
something like<menu id="mpd" label="MPD" execute="path/to/ompb.py"/>
Invalid Output from menu is all i keep getting
Say your prayer's,Eat your vitamins....AND WHAT YOU GONNA DO BROTHA
Offline
Can anyone please post the menu.xml from the Statler latest buid - I did overwrite with an older one and now I have entries that don't fit the system. Or if enyone knows how to extract the file from usb installer I would appreciate it.
Thanks
Offline
Look in /etc/skel - you should find default user files there, including menu.xml.
while ( ! ( succeed = try() ) );
We've earned a reputation as a nice, friendly community; please help us keep it that way.
Offline
Look in /etc/skel - you should find default user files there, including menu.xml.
Didn't know about that folder.
Thanks pvsage, you've really saved my day!
Offline
jmad2011 - I'm getting a similar error.
benj1 - could it be something in the code?
Offline
I am starting to enter into the world of pipemenus! But I have not been able to get one particular pipemenu working, a python mpd script.
I made a ,py file with the code o found on benj1's ultimate pipemenu thread. I made it executable and made a pipemenu entry using the ob gui editor - and I am getting the following error when I try to access the pipemenu.
Failed to execute command for pipe-menu "home/manning/bin/mpd-menu.py": Failed to execute child process for pipe-menu "home/manning/bin/mpd-menu.py" (Permission Denied)
Here is the code I am using:
#!/usr/bin env python
#
# Author: Ben Holroyd <holroyd.ben@gmail.com>
# License: GPL 3.0+
#
# This script requires python-mpd
#
# Usage:
# Put an entry in ~/.config/openbox/menu.xml:
# <menu id="mpd" label="MPD" execute="~/.config/openbox/scripts/ompb.py" />
#
import mpd, os, sys, socket
mpdport = 6600
musicfolder ='/home/manning/music'
filelist = True #potentially slow and unwieldy with a large collection of music
playlist = True #same for this
program = sys.argv[0]
client = mpd.MPDClient()
try:
client.connect("localhost", mpdport)
except socket.error:
print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
print "<openbox_pipe_menu>"
print " <item label=\"MPD not running, click to start\">"
print " <action name=\"Execute\"><execute>mpd</execute></action>"
print " </item>"
print "</openbox_pipe_menu>"
sys.exit(0)
song = client.currentsong()
stats = client.stats()
status = client.status()
def play():
if status['state'] == "stop" or status['state'] == "pause":
client.play()
elif status['state'] == "play":
client.pause()
def volume(vol):
if vol == "up":
client.setvol(int(status['volume'])+10)
elif vol == "down":
client.setvol(int(status['volume'])-10)
try:
if (sys.argv[1] == "play"): play()
elif (sys.argv[1] == "stop"): client.stop()
elif (sys.argv[1] == "prev"): client.previous()
elif (sys.argv[1] == "next"): client.next()
elif (sys.argv[1] == "add"): client.add(sys.argv[2]); client.play()
elif (sys.argv[1] == "clear"): client.clear()
elif (sys.argv[1] == "volume"): volume(sys.argv[2])
elif (sys.argv[1] == "playlist"):
client.delete(client.playlist().index(sys.argv[2]))
elif sys.argv[1] == "random":
client.random(int(not int(client.status()['random'])and True or False))
elif sys.argv[1] == "repeat":
client.repeat(int(not int(client.status()['repeat'])and True or False))
except IndexError:
pass
def item_entry(indent, label, option = '', song = ''):
"""label = label on menu, option = play/pause/stop etc, song = path to song """
print "%s<item label=\"%s\">"%(indent, label)
print "%s <action name=\"Execute\"><execute>%s %s '%s'</execute></action>" % (indent, program, option, song)
print "%s</item>" % (indent)
def file_walk(dir,indent):
""" walks through music directory building a menu to view albums"""
files = os.listdir(dir)
files.sort()
for file in files:
path = os.path.join(dir,file)
if os.path.isdir(path):
print "%s<menu id=\"%s\" label=\"%s\">"%(indent, file, file)
item_entry(indent+' ','Add all to playlist','add' ,path.replace(musicfolder,''))
print "%s <separator />" % indent
file_walk(path,indent+' ')
print "%s</menu>" % indent
else:
item_entry(indent,file,'add',path.replace(musicfolder,''))
indent = indent[2:]
def track_info(label):
print " <menu id=\"%s\" label=\"%s\">"%(label,label)
print " <item label=\"Artist: %s\"/>" % song['artist']
print " <item label=\"Album: %s\"/>" % song['album']
print " <item label=\"Tracklength: %.2f\"/>" % ((int(song['time'])/60)+(int(song['time'])%60.0/100))
print " <item label=\"Track: %s\"/>" % song['track']
print " <item label=\"filetype: %s\"/>" % song['file'][song['file'].rfind('.')+1:]
#print " <item label=\"Genre: %s\"/>" % song['genre']
print " </menu>"
print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
print "<openbox_pipe_menu>"
if status['state'] != "stop":
track_info("Playing: %s - " % song['artist'])
track_info(song['title'])
print " <separator />"
print " <item label=\"Status: %s\"/>" % {'play':'Playing','pause':'Paused','stop':'Stopped'}[status['state']]
print " <separator />"
item_entry(' ', 'Play/Pause', 'play')
item_entry(' ', 'Stop', 'stop')
item_entry(' ', 'Prev', 'prev')
item_entry(' ', 'Next', 'next')
print " <separator />"
if filelist == True:
print " <menu id=\"Albums\" label=\"Albums\">"
file_walk(musicfolder,' ')
print " </menu>"
print " <separator />"
if playlist == True:
print " <menu id=\"Playlist\" label=\"Playlist\">"
print " <item label=\"Click to remove from playlist\"/>"
print " <separator />"
for entries in client.playlist():
item_entry(' ', entries, 'playlist', entries)
print " </menu>"
print " <separator />"
item_entry(' ', 'Clear Playlist', 'clear')
item_entry(' ', 'Random %s' % (int(status['random']) and '[On]' or '[Off]'), 'random')
item_entry(' ', 'Repeat %s' % (int(status['repeat']) and '[On]' or '[Off]'), 'repeat')
print " <menu id=\"volume\" label=\"Volume [%s]\">" % (int(status['volume']) > 0 and status['volume']+'%' or 'mute')
item_entry(' ', 'Volume + 10\% ', 'volume up')
item_entry(' ', 'Volume - 10\%', 'volume down')
print " </menu>"
print " <separator />"
print " <menu id=\"stats\" label=\"Database Stats\">"
print " <item label=\"Artists in database: %s\"/>" % stats['artists']
print " <item label=\"Albums in database: %s\"/>" % stats['albums']
print " <item label=\"Songs in database: %s\"/>" % stats['songs']
print " </menu>"
print "</openbox_pipe_menu>"
exit 0
Thanks for any input!! I am diggin this crunchbang community!!!
Offline
Can you guys update this thread ? for example mdp is not woking form and the batter script is also not working.
Offline
Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.