You are not logged in.

#1 2016-03-29 16:32:04

Sector11
Mod Squid Tpyo Knig
From: Upstairs
Registered: 2015-08-20
Posts: 8,028

[SOLVED] Can not implement OB pipemenu: date-menu.sh

I can not figure out how, for the life of me, to get date-menu.sh, found here, to work

EDIT: CODE and other fixes reflected in this post.

Code repeated here for convenience: (EDIT: Edited to work properly - stripped spaces & added "-h") Thanks to xaos52

#!/bin/sh
#
# date-menu.sh
#
# This is in the public domain.  Honestly, how can you claim anything to
# something this simple?
#
# Outputs a simple openbox pipe menu to display the date, time, and calendar.
# You need 'date' and 'cal'.  You should have these.  Additionally, the
# calendar only appears properly formated if you use a mono spaced font.

# Outputs the selected row from the calender output.
# If you don't use a mono spaced font, you would have to play with spacing here.
# It would probably involve a very complicated mess.  Is there a way to force a
# different font per menu?
function calRow() {
  cal -h | gawk -v row=$1 '{ if (NR==row) { print $0 } }'
}

# Build the menu
cat << EOFMENU
<openbox_pipe_menu>
  <separator label="`date +%A\ \ \ \ \ \ \ \ \ \ \ \ %I\:%M\ %p`" />
  <item label="`date +%B\ %d,\ %Y`" />
  <separator />
  <item label="`calRow 2`" />
  <item label="`calRow 3`" />
  <item label="`calRow 4`" />
  <item label="`calRow 5`" />
  <item label="`calRow 6`" />
  <item label="`calRow 7`" />
  <item label="`calRow 8`" />
</openbox_pipe_menu>
EOFMENU

EDIT: use:

<menu execute="date-menu.sh" id="pipe-month" label="Month"/>

Any help appreciated.

Last edited by Sector11 (2016-03-30 19:43:03)


Debian 12 Beardog, SoxDog and still a Conky 1.9er

Offline

#2 2016-03-29 17:03:40

xaos52
The Good Doctor
From: Planet of the @pes
Registered: 2015-09-30
Posts: 695

Re: [SOLVED] Can not implement OB pipemenu: date-menu.sh

#!/bin/sh
#
# date-menu.sh
#
# This is in the public domain.  Honestly, how can you claim anything to something
# this simple?
#
# Outputs a simple openbox pipe menu to display the date, time, and calendar.
# You need 'date' and 'cal'.  You should have these.  Additionally, the calendar
# only appears properly formated if you use a mono spaced font.

# Outputs the selected row from the calender output.
# If you don't use a mono spaced font, you would have to play with spacing here.
# It would probably involve a very complicated mess.  Is there a way to force a
# different font per menu?
calRow() {
  cal | gawk -v row=$1 '{ if (NR==row) { print $0 } }'
}

# Build the menu
cat << EOFMENU
<openbox_pipe_menu>
  <separator label="`date +%A\ \ \ \ \ \ \ \ \ \ \ \ %I\:%M\ %p`" />
  <item label="`date +%B\ %d,\ %Y`" />
  <separator />
  <item label="`calRow 2`" />
  <item label="`calRow 3`" />
  <item label="`calRow 4`" />
  <item label="`calRow 5`" />
  <item label="`calRow 6`" />
  <item label="`calRow 7`" />
  <item label="`calRow 8`" />
</openbox_pipe_menu>
EOFMENU

This works.
Launch with sh ./<name>
or make executable and launch with ./<name>

Offline

#3 2016-03-29 17:11:40

PackRat
jgmenu user Numero Uno
Registered: 2015-10-02
Posts: 2,660

Re: [SOLVED] Can not implement OB pipemenu: date-menu.sh

@S11 -
You getting any error message when you try to run it? I'm getting an invalid output from pipe-menu error.

Last edited by PackRat (2016-03-29 17:43:56)


You must unlearn what you have learned.
    -- yoda

Online

#4 2016-03-29 18:31:40

xaos52
The Good Doctor
From: Planet of the @pes
Registered: 2015-09-30
Posts: 695

Re: [SOLVED] Can not implement OB pipemenu: date-menu.sh

Problem is that cal highlights the current date, but those highlights are not well interpreted by openbox. You won't be able to use the scripts as is.

Using 'cal -h' in stead of 'cal' in the script removes that problem, but also removes the highlight.

cal.th.png

Looks like the first non-space-character in a line with leading spaces gets underscored. I don't know how to remedy that. Anyone?

Offline

#5 2016-03-30 10:36:29

Sector11
Mod Squid Tpyo Knig
From: Upstairs
Registered: 2015-08-20
Posts: 8,028

Re: [SOLVED] Can not implement OB pipemenu: date-menu.sh

@xoas52

I can't for the life of me see the difference in your code and the original.  However using your code in ~/bin/date-menu.sh the script works in a terminal (as did the original) but not with the "sh ./date-menu.sh" or "./date-menu.sh":

 30 Mar 16 @ 07:29:58 ~
  $ ~/bin/date-menu.sh
<openbox_pipe_menu>
  <separator label="Wednesday            07:30 AM" />
  <item label="March 30, 2016" />
  <separator />
  <item label="Su Mo Tu We Th Fr Sa  " />
  <item label="       1  2  3  4  5  " />
  <item label=" 6  7  8  9 10 11 12  " />
  <item label="13 14 15 16 17 18 19  " />
  <item label="20 21 22 23 24 25 26  " />
  <item label="27 28 29 30 31        " />
  <item label="                      " />
</openbox_pipe_menu>
 
 30 Mar 16 @ 07:30:16 ~
  $ sh ./date-menu.sh
sh: 0: Can't open ./date-menu.sh
 
 30 Mar 16 @ 07:30:41 ~
  $ ./date-menu.sh
bash: ./date-menu.sh: No such file or directory
 
 30 Mar 16 @ 07:31:07 ~
  $ date-menu.sh
<openbox_pipe_menu>
  <separator label="Wednesday            07:31 AM" />
  <item label="March 30, 2016" />
  <separator />
  <item label="Su Mo Tu We Th Fr Sa  " />
  <item label="       1  2  3  4  5  " />
  <item label=" 6  7  8  9 10 11 12  " />
  <item label="13 14 15 16 17 18 19  " />
  <item label="20 21 22 23 24 25 26  " />
  <item label="27 28 29 30 31        " />
  <item label="                      " />
</openbox_pipe_menu>
 
 30 Mar 16 @ 07:31:19 ~
  $ 

That wasn't the real problem ... for as many (atleast 6 pipemenus that I have here, I can not figure out what the line/command in the menu.xml file needs to me.

My apologies.


Debian 12 Beardog, SoxDog and still a Conky 1.9er

Offline

#6 2016-03-30 10:37:18

Sector11
Mod Squid Tpyo Knig
From: Upstairs
Registered: 2015-08-20
Posts: 8,028

Re: [SOLVED] Can not implement OB pipemenu: date-menu.sh

PackRat wrote:

@S11 -
You getting any error message when you try to run it? I'm getting an invalid output from pipe-menu error.

Yea, I got that too .. once.


Debian 12 Beardog, SoxDog and still a Conky 1.9er

Offline

#7 2016-03-30 11:05:38

xaos52
The Good Doctor
From: Planet of the @pes
Registered: 2015-09-30
Posts: 695

Re: [SOLVED] Can not implement OB pipemenu: date-menu.sh

@Sector11
Here is a diff file between t12.orig (the  script copy/pasted from your post) and t12 (the script after my modifications)

/h/m/t/t/quicktests diff t12.orig t12
2,10c2,10
<  #
<  # date-menu.sh
<  #
<  # This is in the public domain.  Honestly, how can you claim anything to
<  # something this simple?
<  #
<  # Outputs a simple openbox pipe menu to display the date, time, and calendar.
<  # You need 'date' and 'cal'.  You should have these.  Additionally, the
<  # calendar only appears properly formated if you use a mono spaced font.
---
> #
> # date-menu.sh
> #
> # This is in the public domain.  Honestly, how can you claim anything to something
> # this simple?
> #
> # Outputs a simple openbox pipe menu to display the date, time, and calendar.
> # You need 'date' and 'cal'.  You should have these.  Additionally, the calendar
> # only appears properly formated if you use a mono spaced font.
12,18c12,18
<  # Outputs the selected row from the calender output.
<  # If you don't use a mono spaced font, you would have to play with spacing here.
<  # It would probably involve a very complicated mess.  Is there a way to force a
<  # different font per menu?
<  function calRow() {
<    cal | gawk -v row=$1 '{ if (NR==row) { print $0 } }'
<  }
---
> # Outputs the selected row from the calender output.
> # If you don't use a mono spaced font, you would have to play with spacing here.
> # It would probably involve a very complicated mess.  Is there a way to force a
> # different font per menu?
> calRow() {
>   cal | gawk -v row=$1 '{ if (NR==row) { print $0 } }'
> }
20,34c20,34
<  # Build the menu
<  cat << EOFMENU
<  <openbox_pipe_menu>
<    <separator label="`date +%A\ \ \ \ \ \ \ \ \ \ \ \ %I\:%M\ %p`" />
<    <item label="`date +%B\ %d,\ %Y`" />
<    <separator />
<    <item label="`calRow 2`" />
<    <item label="`calRow 3`" />
<    <item label="`calRow 4`" />
<    <item label="`calRow 5`" />
<    <item label="`calRow 6`" />
<    <item label="`calRow 7`" />
<    <item label="`calRow 8`" />
<  </openbox_pipe_menu>
<  EOFMENU
---
> # Build the menu
> cat << EOFMENU
> <openbox_pipe_menu>
>   <separator label="`date +%A\ \ \ \ \ \ \ \ \ \ \ \ %I\:%M\ %p`" />
>   <item label="`date +%B\ %d,\ %Y`" />
>   <separator />
>   <item label="`calRow 2`" />
>   <item label="`calRow 3`" />
>   <item label="`calRow 4`" />
>   <item label="`calRow 5`" />
>   <item label="`calRow 6`" />
>   <item label="`calRow 7`" />
>   <item label="`calRow 8`" />
> </openbox_pipe_menu>
> EOFMENU
 /h/m/t/t/quicktests 

TL;DR:
- In your version, all lines after the first one start on position 2. I changed that to position 1.
- Leave out the 'function' keyword.

Here is how I start it in rc.menu, after copying the script to /usr/local/bin and making it executable.

            <menu execute="bl-sshconfig-pipemenu" id="sshconfig" label="SSH"/>
            <separator label="Services"/>
            <menu execute="bl-dropbox-pipemenu" id="dropbox" label="Dropbox"/>
            <menu execute="t12" id="calendar" label="Calendar"/>
        </menu>
        <menu id="office" label="Office">



            <menu id="libreoffice" label="LibreOffice" execute="bl-libreoffice-pipemenu" />
            <item label="Google Docs">
                <action name="Execute">

This will give you an error when executed from the menu - because of the highlights produced by the cal command.

If you then change the script to call 'cal' with argument -h (no highlight), it works for me, as shown in the screenshot.

hth

Offline

#8 2016-03-30 11:35:30

damo
....moderator....
Registered: 2015-08-20
Posts: 6,734

Re: [SOLVED] Can not implement OB pipemenu: date-menu.sh

Sector11 wrote:

@xoas52

I can't for the life of me see the difference in your code and the original. ....

The original code has whitespace at the beginning of the lines, so

line 34: warning: here-document at line 21 delimited by end-of-file (wanted `EOFMENU')

If you remove the single-space indents then it runs OK.

If you make the script executable, and in your SPATH, then you can just use the name of the command in the menu.xml. Otherwise if you are starting it with the `sh` command then it needs the full path - the `./` format is a relative path I think. Also it seems that `sh` doesn't like the use of `function`, so removing that prevents this error:

[damo@bunsen ~]$ sh ~/bin/date-menu2.sh
/home/damo/bin/date-menu2.sh: 16: /home/damo/bin/date-menu2.sh: Syntax error: "(" unexpected

menu-scrot.png
With @xaos52's "fixes"...

 #!/bin/sh
 #
 # date-menu.sh
 #
 # This is in the public domain.  Honestly, how can you claim anything to
 # something this simple?
 #
 # Outputs a simple openbox pipe menu to display the date, time, and calendar.
 # You need 'date' and 'cal'.  You should have these.  Additionally, the
 # calendar only appears properly formated if you use a mono spaced font.

 # Outputs the selected row from the calender output.
 # If you don't use a mono spaced font, you would have to play with spacing here.
 # It would probably involve a very complicated mess.  Is there a way to force a
 # different font per menu?
calRow() {
cal -h | gawk -v row=$1 '{ if (NR==row) { print $0 } }'
}

# Build the menu
cat << EOFMENU
<openbox_pipe_menu>
<separator label="`date +%A\ \ \ \ \ \ \ \ \ \ \ \ %I\:%M\ %p`" />
<item label="`date +%B\ %d,\ %Y`" />
<separator />
<item label="`calRow 2`" />
<item label="`calRow 3`" />
<item label="`calRow 4`" />
<item label="`calRow 5`" />
<item label="`calRow 6`" />
<item label="`calRow 7`" />
<item label="`calRow 8`" />
</openbox_pipe_menu>
EOFMENU

Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#9 2016-03-30 14:05:17

PackRat
jgmenu user Numero Uno
Registered: 2015-10-02
Posts: 2,660

Re: [SOLVED] Can not implement OB pipemenu: date-menu.sh

The month isn't showing on my system (Debian Sid) -

cal-screenshot2016-03-3010-00-53.png

the command:

cal -h

doesn't work; get a list for general usage options. However, the 'h" is given as an option in the man page.

Last edited by PackRat (2016-03-30 14:11:59)


You must unlearn what you have learned.
    -- yoda

Online

#10 2016-03-30 14:15:20

xaos52
The Good Doctor
From: Planet of the @pes
Registered: 2015-09-30
Posts: 695

Re: [SOLVED] Can not implement OB pipemenu: date-menu.sh

^ What if you run the script in a terminal window?
  Do you have 'cal' and 'gawk' installed?

What package does your 'cal' command come from?

apt-file search /usr/bin/cal

Offline

#11 2016-03-30 14:21:51

PackRat
jgmenu user Numero Uno
Registered: 2015-10-02
Posts: 2,660

Re: [SOLVED] Can not implement OB pipemenu: date-menu.sh

Yes, I checked - cal, date, and gawk are installed.

with "cal -h" in the script I get:

<separator />
<item label="" />
<item label="" />
<item label="" />
<item label="" />
<item label="" />
<item label="" />
<item label="" />
</openbox_pipe_menu>

after the date line, if I just use "cal" the output is:

<separator />
<item label="Su Mo Tu We Th Fr Sa  " />
<item label="       1  2  3  4  5  " />
<item label=" 6  7  8  9 10 11 12  " />
<item label="13 14 15 16 17 18 19  " />
<item label="20 21 22 23 24 25 26  " />
<item label="27 28 29 30 31        " />
<item label="                      " />
</openbox_pipe_menu>
bsdmainutils: /usr/bin/cal

it's a symlink to ncal (using vsido)

Last edited by PackRat (2016-03-30 14:29:33)


You must unlearn what you have learned.
    -- yoda

Online

#12 2016-03-30 14:27:03

xaos52
The Good Doctor
From: Planet of the @pes
Registered: 2015-09-30
Posts: 695

Re: [SOLVED] Can not implement OB pipemenu: date-menu.sh

I suspect you have a newer version of cal which uses -h for help and perhaps another option for _not_ highlighting the current day. See 'man cal' (and hope they did not forget to change the man page)

Offline

#13 2016-03-30 14:30:25

PackRat
jgmenu user Numero Uno
Registered: 2015-10-02
Posts: 2,660

Re: [SOLVED] Can not implement OB pipemenu: date-menu.sh

From the man page -

 -h      Turns off highlighting of today.

cal -h in a terminal does give the usage options, so it looks like -h is for help and the man page is inaccurate.

Last edited by PackRat (2016-03-30 14:31:36)


You must unlearn what you have learned.
    -- yoda

Online

#14 2016-03-30 15:19:32

tknomanzr
BL Die Hard
From: Around the Bend
Registered: 2015-09-29
Posts: 1,057

Re: [SOLVED] Can not implement OB pipemenu: date-menu.sh

You could try to check the source. Chances are very good that there will be an arg parser prior to the main function that will show you the arguments it accepts. Here is a bash example that only accepts short arguments. I was being lazy for this script and chose not to parse long ones.

# Get options passed in via cli
getopt --test > /dev/null
if [[ $? != 4 ]]; then
    echo "I’m sorry, `getopt --test` failed in this environment."
    exit 1
fi
usage="$(basename "$0") [-h] [-k n] -- cleans apt-btrfs-snapper snapshots

where:
    -h  show this help text
    -k  set the number of snapshots to keep (default: 0)"

seed=42
while getopts ':hk:' option; do
  case "$option" in
    h) echo "$usage"
       exit
       ;;
    k) keep=$OPTARG
       ;;
    :) printf "missing argument for -%s\n" "$OPTARG" >&2
       echo "$usage" >&2
       exit 1
       ;;
   \?) printf "illegal option: -%s\n" "$OPTARG" >&2
       echo "$usage" >&2
       exit 1
       ;;
  esac
done

Python will look very similar, although it is usually setup to call a main() function. C++ would be structured very similar to python.

Offline

#15 2016-03-30 15:39:30

PackRat
jgmenu user Numero Uno
Registered: 2015-10-02
Posts: 2,660

Re: [SOLVED] Can not implement OB pipemenu: date-menu.sh

^ thanks - but lets not derail S11's thread  8o


You must unlearn what you have learned.
    -- yoda

Online

#16 2016-03-30 16:14:16

Sector11
Mod Squid Tpyo Knig
From: Upstairs
Registered: 2015-08-20
Posts: 8,028

Re: [SOLVED] Can not implement OB pipemenu: date-menu.sh

^ @ALL by all means - keep going, with any discussion re: cal or whatever.

Sooner or later what is in testing/sid now will be in Stable, hence BL, and this will be all discussed and problems ironed out.  smile


Debian 12 Beardog, SoxDog and still a Conky 1.9er

Offline

#17 2016-03-30 16:41:08

Sector11
Mod Squid Tpyo Knig
From: Upstairs
Registered: 2015-08-20
Posts: 8,028

Re: [SOLVED] Can not implement OB pipemenu: date-menu.sh

/home/sector11/bin/date-menu.sh <<-- it's in my path, (spaces removed) as per xaos52's file update, and in OpenBox menu.xml file I have:

<menu execute="date-menu.sh" id="pipe-month" label="Month"/>

and I get: 2016_03_30_13_38_16_Scrot11.jpg

Sometimes I hate being a freaking noob, and this is one of those times.  sad


Debian 12 Beardog, SoxDog and still a Conky 1.9er

Offline

#18 2016-03-30 16:54:25

xaos52
The Good Doctor
From: Planet of the @pes
Registered: 2015-09-30
Posts: 695

Re: [SOLVED] Can not implement OB pipemenu: date-menu.sh

Run following commands in a terminal window, and post results:

ls -al $HOME/bin/date-menu.sh
echo $PATH
cat $HOME/bin/date-menu.sh

From that terminal-window can you run

date-menu.sh

and does it produce any output?

Offline

#19 2016-03-30 17:10:14

Sector11
Mod Squid Tpyo Knig
From: Upstairs
Registered: 2015-08-20
Posts: 8,028

Re: [SOLVED] Can not implement OB pipemenu: date-menu.sh

@xoas52
Everything works as expected:

 30 Mar 16 @ 14:04:07 ~
  $ ls -al $HOME/bin/date-menu.sh
-rwxr-xr-x 1 sector11 sector11 1256 Mar 30 13:18 /home/sector11/bin/date-menu.sh
 
 30 Mar 16 @ 14:04:16 ~
  $ echo $PATH
/home/sector11/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/home/sector11/bin
 
 30 Mar 16 @ 14:04:28 ~
  $ cat $HOME/bin/date-menu.sh
#!/bin/sh
#
# Update xoas52 - leading spaces removed.
# <menu execute="t12" id="calendar" label="Calendar"/>
#
# /home/sector11/bin/date-menu.sh
# <menu execute="date-menu.sh" id="calendar" label="Month"/>
#
# This is in the public domain.  Honestly, how can you claim anything to something
# this simple?
#
# Outputs a simple openbox pipe menu to display the date, time, and calendar.
# You need 'date' and 'cal'.  You should have these.  Additionally, the calendar
# only appears properly formated if you use a mono spaced font.

# Outputs the selected row from the calender output.
# If you don't use a mono spaced font, you would have to play with spacing here.
# It would probably involve a very complicated mess.  Is there a way to force a
# different font per menu?
calRow() {
  cal | gawk -v row=$1 '{ if (NR==row) { print $0 } }'
}

# Build the menu
cat << EOFMENU
<openbox_pipe_menu>
  <separator label="`date +%A\ \ \ \ \ \ \ \ \ \ \ \ %I\:%M\ %p`" />
  <item label="`date +%B\ %d,\ %Y`" />
  <separator />
  <item label="`calRow 2`" />
  <item label="`calRow 3`" />
  <item label="`calRow 4`" />
  <item label="`calRow 5`" />
  <item label="`calRow 6`" />
  <item label="`calRow 7`" />
  <item label="`calRow 8`" />
</openbox_pipe_menu>
EOFMENU 
 30 Mar 16 @ 14:04:42 ~
  $ date-menu.sh
<openbox_pipe_menu>
  <separator label="Wednesday            02:04 PM" />
  <item label="March 30, 2016" />
  <separator />
  <item label="Su Mo Tu We Th Fr Sa  " />
  <item label="       1  2  3  4  5  " />
  <item label=" 6  7  8  9 10 11 12  " />
  <item label="13 14 15 16 17 18 19  " />
  <item label="20 21 22 23 24 25 26  " />
  <item label="27 28 29 30 31        " />
  <item label="                      " />
</openbox_pipe_menu>
 
 30 Mar 16 @ 14:04:55 ~
  $ 

Debian 12 Beardog, SoxDog and still a Conky 1.9er

Offline

#20 2016-03-30 17:22:15

Sector11
Mod Squid Tpyo Knig
From: Upstairs
Registered: 2015-08-20
Posts: 8,028

Re: [SOLVED] Can not implement OB pipemenu: date-menu.sh

@damo - yea, did that still getting errors!  sad


Debian 12 Beardog, SoxDog and still a Conky 1.9er

Offline

Board footer

Powered by FluxBB