source: mpd-status/trunk/examples/status-actions-menu @ 28

Last change on this file since 28 was 25, checked in by simon, 19 years ago

Update README with more general instructions. Add wmii status rc script examples.

  • Property svn:executable set to *
File size: 3.1 KB
RevLine 
[25]1#!/usr/lib/9base/bin/rc
2# periodically print stuff to the bar
3
4PIDFILE=/tmp/.ixp-$USER/statuspid-$WMII_IDENT
5if(test -r $PIDFILE) {
6    kill -2 `{cat $PIDFILE} >[2]/dev/null
7}
8echo $pid >$PIDFILE
9
10# current track playing in mpd
11
12# Implement many of mpc's actions in a menu
13wmiir create /menu/items/mpc/prev 'prev'
14wmiir create /menu/items/mpc/play 'play'
15wmiir create /menu/items/mpc/pause 'pause'
16wmiir create /menu/items/mpc/stop 'stop'
17wmiir create /menu/items/mpc/next 'next'
18wmiir create /menu/items/mpc/toggle 'toggle'
19wmiir create /menu/items/mpc/start 'seek 00:00:00'
20wmiir create /menu/items/mpc/back 'seek -00:00:05'
21wmiir create /menu/items/mpc/fwd 'seek +00:00:05'
22wmiir create /menu/items/mpc/clear 'clear'
23wmiir create /menu/items/mpc/shuffle 'shuffle'
24wmiir create /menu/items/mpc/load 'load wmii'
25wmiir create /menu/items/mpc/save 'save wmii'
26wmiir create /menu/items/mpc/voldn 'volume -10'
27wmiir create /menu/items/mpc/volup 'volume +10'
28wmiir create /menu/items/mpc/repeat 'repeat'
29wmiir create /menu/items/mpc/random 'random'
30wmiir create /menu/items/mpc/update 'update'
31
32mpdlab=`{wmiir read /bar/new}
33# Colour between selected and normal
34wmiir write /bar/$mpdlab/fgcolor '#d4d4d4'
35wmiir write /bar/$mpdlab/bgcolor '#293139'
36wmiir write /bar/$mpdlab/bordercolor '#303840'
37
38wmiir write /bar/$mpdlab/b1press 'extern mpc toggle'
39wmiir write /bar/$mpdlab/b2press 'wmiir write /menu/precmd ''extern mpc''; wmiir write /menu/lookup /items/mpc; wmiir write /menu/ctl ''display 1'''
40wmiir write /bar/$mpdlab/b3press 'extern mpc next'
41
42# When changing the volume, display it
43# (Involves calling bash because I don't really know how to do 9rc)
44wmiir create /bar/$mpdlab/x-delay 0
45wmiir write /bar/$mpdlab/b4press 'wmiir write /bar/'^$mpdlab^'/x-delay 1; extern bash -c ''wmiir write /bar/'^$mpdlab^'/data "$(mpc volume -5 | grep ^volume:)"'''
46wmiir write /bar/$mpdlab/b5press 'wmiir write /bar/'^$mpdlab^'/x-delay 1; extern bash -c ''wmiir write /bar/'^$mpdlab^'/data "$(mpc volume +5 | grep ^volume:)"'''
47
48# date and load average
49
50label=`{wmiir read /bar/new}
51wmiir write /bar/$label/b1press 'wmiir write /wm/ctl ''select prev'''
52wmiir write /bar/$label/b3press 'wmiir write /wm/ctl ''select next'''
53wmiir write /bar/$label/b4press 'wmiir write /wm/ctl ''select prev'''
54wmiir write /bar/$label/b5press 'wmiir write /wm/ctl ''select next'''
55
56# install signal handler for artificial sigexit:
57fn sigint {
58    if(test -f $PIDFILE && ~ `{cat $PIDFILE} $pid)
59        rm -f $PIDFILE
60    wmiir write /bar/ctl 'destroy '^$mdlab
61    wmiir write /bar/ctl 'destroy '^$label
62    exit
63}
64
65fn mpdstatus {
66    echo (`{$HOME/.wmii/scripts/mpd-status.py})
67}
68
69fn statustext {
70    # if you need a formatted date, use awk
71    echo (`{date} `{uptime | sed 's/.*://; s/,//g'})
72}
73
74mpdtext=`{mpdstatus}
75text=`{statustext}
76while(wmiir write /bar/$label/data $"text >[2]/dev/null) {
77    sleep 2
78    text=`{statustext}
79    # If we've been told to delay, don't update this time round
80    delay=`{wmiir read /bar/$mpdlab/x-delay}
81    if(~ $delay 1) wmiir write /bar/$mpdlab/x-delay 0
82    if not {
83        mpdtext=`{mpdstatus}
84        wmiir write /bar/$mpdlab/data $"mpdtext >[2]/dev/null
85    }
86}
Note: See TracBrowser for help on using the repository browser.