You are not logged in.

#1 2015-12-20 16:47:52

gako
Member
Registered: 2015-10-02
Posts: 241

Openbox Menu generation with M4 Macros

Hate xml but like editing your openbox menu without gui

Yes you have obmenu (GUI menu editor) but here is another way to play
with your openbox menu using the GNU m4 macro processor.

So you'll need to install m4 if you don't have it.

m4 (GNU Macro Processor ) makes it easy to write definitions on the fly
and can embed system commands so you can use the output in variables in your menu

like finding width of screen:

define(`WIDTH', esyscmd(xwininfo -root | awk '/Width/{print $2}'))

You could further pass the Width definition to new definitions containing geometries

In the macros below I didn't go too crazy but applied one example
where we test if "/etc/alternatives/bl-terminal-emulator" exists
If it does it is applied to the TERM variable, otherwise it uses x-terminal-emulator

My m4 macros contain three writing styles:

Long hand
meaning

ITEM(LABEL(`Media Player'))
  ACTION(NAME(`Execute'_NAME))
    EXECUTE(`bl-media-player'_EXECUTE)
  _ACTION
_ITEM

Short hand

IL(Media Player)
  AX
    X(bl-media-player)
  _A
_I

and In-line

_exec(Media Player,bl-media-player)

will all produce the same output

It may look scary at first but look at the menu files (one short-hand, one in-line)
and scale back in the definitions file to see there meaning.

The shorthand are actually abbreviations for the long hand, and the in-line is an abbreviation for the short-hand

I separated the definitions from the menus so look at the first line of the menu files.
They contain an include(/path/to/definitions-file)
Make sure to edit that line to the path of the definitions file

Generating menu:
example:
m4 in-line-menu | less
or
m4 in-line-menu > menu.xml

Definitions:

define(`NL',`
')dnl
define(`OB', `~/.config/openbox')dnl
define(`ObMenu_',
`<?xml version="1.0" encoding="utf-8"?>
<openbox_menu xmlns="http://openbox.org/"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://openbox.org/
              file:///usr/share/openbox/menu.xsd">')dnl
define(`_ObMenu',`</openbox_menu>')dnl
define(`MENU',`<menu $1>')dnl
define(`_MENU',`</menu>')dnl
define(`ITEM', `<item $1>')dnl
define(`_ITEM', `</item>')dnl
define(`ACTION', `<action $1>')dnl
define(`_ACTION', `</action>')dnl
define(`EXECUTE', `<execute>$1')dnl
define(`_EXECUTE', `</execute>')dnl
define(`SEPARATOR', `<separator$1/>')dnl
define(`ID', `id="$1"')dnl
define(`NAME', `name="$1"')dnl
define(`LABEL', `label="$1"')dnl
define(`XCUTE',`execute="$1"')dnl
define(`MIL', `MENU(ID(`$1') LABEL(`$2'))')dnl
define(`MXIL',`MENU(XCUTE(`$1') ID(`$2') LABEL(`$3')`/')')dnl
define(`_M',`_MENU')dnl
define(`IL',`ITEM(LABEL(`$1'))')dnl
define(`AX',`ACTION(NAME(`Execute'))')dnl
define(`AN',`ACTION(NAME(`$1')`/')')dnl
define(`_A',`_ACTION')dnl
define(`X',`EXECUTE($1`'_EXECUTE)')dnl
define(`_I',`_ITEM')dnl
define(S, `SEPARATOR')dnl
define(SL, `SEPARATOR(` 'LABEL($1))')dnl
define(`ISBLTERM', `esyscmd(ls /etc/alternatives/bl-terminal-emulator 2>1)')dnl
define(`BLTERM_TRUE',`/etc/alternatives/bl-terminal-emulator
')dnl
define(`BLTERMINAL',`bl-terminal-emulator')dnl
define(`XTERMINAL',`x-terminal-emulator')dnl
define(`TERM', ifelse(ISBLTERM,BLTERM_TRUE,BLTERMINAL,XTERMINAL))dnl
define(`_exec', `IL($1) AX X($2) _A _I')dnl

## MENUs I used bunsenlabs default menu for example
short-hand-menu:

include(/home/user/tmp/definitions)
ObMenu_
  MIL(root-menu,Openbox 3)
    IL(Run)
      AX
        X(gmrun)
      _A  
    _I
    S
    IL(Terminal)
      AX
        X(TERM)
      _A
    _I
    IL(Web Browser)
      AX
        X(x-www-browser)
      _A
    _I
    IL(File Manager)
      AX
        X(bl-file-manager)
      _A
    _I
    IL(Text Editor)
      AX
        X(bl-text-editor)
      _A
    _I
    IL(Media Player)
      AX
        X(bl-media-player)
      _A
    _I
    S
    MIL(accessories,Accessories)  
      IL(Catfish File Search)
        AX
          X(catfish)
        _A
      _I
      IL(Archive Manager)
        AX
          X(file-roller)
        _A
      _I
      IL(Task Manager (htop))
        AX
          X(TERM -T 'htop task manager' -e htop)
        _A
      _I
    _M
    MXIL(bl-graphics-pipemenu,bl-graphics-pipemenu,Graphics)    
    MXIL(bl-multimedia-pipemenu,bl-multimedia-pipemenu,Multimedia)
    MIL(network,Network)
      MXIL(bl-x-www-browser-pipemenu,wwwbrowsers,WWW Browsers,)
      IL(Filezilla FTP Client)
        AX
          X(filezilla)
        _A
      _I
      IL(Transmission BitTorrent Client)
        AX
          X(transmission-gtk)
        _A
      _I
      IL(HexChat IRC Client)
        AX
          X(hexchat)
        _A
      _I
      IL(Remote Filesystems)
        AX
          X(gigolo)
        _A
      _I
      MXIL(bl-remote-desktop-pipemenu,remotedesktop,Remote Desktop)
      MXIL(bl-sshconfig-pipemenu,sshconfig,SSH)
      SL(Services)    
      MXIL(bl-dropbox-pipemenu,dropbox,Dropbox)
    _M
    MIL(office,Office)
      MXIL(bl-libreoffice-pipemenu,libreoffice,LibreOffice)
      IL(Google Docs)
        AX
          X(x-www-browser https://drive.google.com/)
        _A
      _I
      IL(Gnumeric Spreadsheet)
        AX
          X(gnumeric)
        _A
      _I
        IL(Calculator)
        AX
          X(galculator)
        _A
      _I
        IL(Evince PDF Viewer)
        AX
          X(evince)
        _A
      _I
    _M
    S
    MXIL(bl-places-pipemenu,pipe-placesmenu,Places)
    MXIL(bl-recent-files-pipemenu -rl15,pipe-recentfilesmenu,Recent Files)
    S
    MIL(preferences,Preferences)
      MIL(obConfig,Openbox)
        IL(Edit menu.xml)
          AX
            X(bl-text-editor OB/menu.xml)
          _A
        _I
        IL(Edit rc.xml)
          AX
            X(bl-text-editor OB/rc.xml)
          _A
        _I
        IL(Edit autostart)
          AX
            X(bl-text-editor ~/.config/openbox/autostart)
          _A
        _I
        IL(GUI Menu Editor)
          AX
            X(obmenu)
          _A
        _I
        IL(GUI Config Tool)
          AX
            X(obconf)
          _A
        _I
        IL(How to Edit Menu)
          AX
            X(zenity --text-info --title=&quot;How to Edit the Menu&quot; --filename=&quot;/usr/share/bunsen/bunsen-docs/helpfile-menu.txt&quot; --width=900 --height=700)
          _A
        _I
        IL(Reconfigure)
          AN(Reconfigure)
        _I
        IL(Restart)
          AN(Restart)
        _I
      _M
      MXIL(bl-compositor,CompositingPipeMenu,Compositor)
      MXIL(bl-conky-pipemenu,pipe-conkymenu,Conky)
      MXIL(bl-tint2-pipemenu,pipe-tint2menu,Tint2)
        IL(Appearance)
          AX
            X(lxappearance)
          _A
        _I
        IL(Choose Wallpaper)
          AX
            X(nitrogen)
          _A
        _I
        IL(Notifications)
          AX
            X(xfce4-notifyd-config)
          _A
        _I
        IL(Power Management)
          AX
            X(xfce4-power-manager-settings)
          _A
        _I
        MIL(dmenuconfig,dmenu)
          IL(Edit Start-up Script)
            AX
              X(bl-text-editor ~/.config/dmenu/dmenu-bind.sh)
            _A
          _I
          SL(Help?)
          IL(man page)
            AX
              X(TERM -T 'man dmenu' -e man dmenu)
            _A
          _I
        _M
        MIL(gmrunconfig,gmrun)
          IL(Edit Config File)
            AX
              X(bl-text-editor ~/.gmrunrc)
            _A
          _I
          SL(Help?)
          IL(man page)
            AX
              X(TERM -T 'man gmrun' -e man gmrun)
            _A
          _I
        _M
        MIL(DisplaySettings,Display)
          IL(ARandR Screen Layout Editor)
            AX
              X(arandr)
            _A
          _I
          SL(Help?)
          IL(man xrandr)
            AX
              X(TERM -T 'man xrandr' -e man xrandr)
            _A
          _I
        _M
    _M
    MIL(system,System)
      MXIL(bl-printing-pipemenu,PrintingPipeMenu,Printers)
      IL(Synaptic Package Manager)
        AX
          X(gksudo synaptic)
        _A
      _I
      IL(File Manager as root)
        AX
          X(gksudo bl-file-manager)
        _A
      _I
      IL(Text Editor as root)
        AX
          X(gksudo bl-text-editor)
        _A
      _I
      IL(Login Settings)
        AX
          X(gksudo bl-text-editor /etc/lightdm/lightdm-gtk-greeter.conf /etc/lightdm/lightdm.conf)
        _A
      _I
      IL(GParted)
        AX
          X(gksudo gparted)
        _A
      _I
      IL(Edit Debian Alternatives)
        AX
          X(gksudo galternatives)
        _A
      _I
      S
      IL(About Bunsen Alternatives)
        AX
          X(zenity --text-info --title=&quot;About Bunsen Alternatives&quot; --filename=&quot;/usr/share/bunsen/bunsen-docs/helpfile-bl-alternatives.txt&quot; --width=900 --height=700)
        _A
      _I
    _M
    MXIL(bl-help-pipemenu,help,Help)
    S
    MXIL(bl-kb-pipemenu,keybinds,Display Keybinds)
    S
    IL(Lock Screen)
      AX
        X(bl-lock)
      _A
    _I
    IL(Exit)
      AX
        X(bl-exit)
      _A
    _I
  _M  
_ObMenu

in-line-menu:

include(/home/user/tmp/definitions)
ObMenu_
  MIL(root-menu,Openbox 3)
    _exec(Run,gmrun)
    S
    _exec(Terminal, TERM)
    _exec(Web Browser,x-www-browser)
    _exec(File Manager,bl-file-manager)
    _exec(Text Editor,bl-text-editor)
    _exec(Media Player,bl-media-player)
    S
    MIL(accessories,Accessories)  
    _exec(Catfish File Search,catfish)
    _exec(Archive Manager,file-roller)
    _exec(Task Manager (htop),TERM -T 'htop task manager' -e htop)
    _M
    MXIL(bl-graphics-pipemenu,bl-graphics-pipemenu,Graphics)    
    MXIL(bl-multimedia-pipemenu,bl-multimedia-pipemenu,Multimedia)
    MIL(network,Network)
      MXIL(bl-x-www-browser-pipemenu,wwwbrowsers,WWW Browsers,)
      _exec(Filezilla FTP Client,filezilla)
      _exec(Transmission BitTorrent Client,transmission-gtk)
      _exec(HexChat IRC Client,hexchat)
      _exec(Remote Filesystems,gigolo)
      MXIL(bl-remote-desktop-pipemenu,remotedesktop,Remote Desktop)
      MXIL(bl-sshconfig-pipemenu,sshconfig,SSH)
      SL(Services)    
      MXIL(bl-dropbox-pipemenu,dropbox,Dropbox)
    _M
    MIL(office,Office)
      MXIL(bl-libreoffice-pipemenu,libreoffice,LibreOffice)
      _exec(Google Docs,x-www-browser https://drive.google.com/)
      _exec(Gnumeric Spreadsheet,gnumeric)
      _exec(Calculator,galculator)
      _exec(Evince PDF Viewer,evince)
    _M
    S
    MXIL(bl-places-pipemenu,pipe-placesmenu,Places)
    MXIL(bl-recent-files-pipemenu -rl15,pipe-recentfilesmenu,Recent Files)
    S
    MIL(preferences,Preferences)
      MIL(obConfig,Openbox)
        _exec(Edit menu.xml,bl-text-editor OB/menu.xml)
        _exec(Edit rc.xml,bl-text-editor OB/rc.xml)
        _exec(Edit autostart,bl-text-editor ~/.config/openbox/autostart)
        _exec(GUI Menu Editor,obmenu)
        _exec(GUI Config Tool,obconf)
        _exec(How to Edit Menu,zenity --text-info --title=&quot;How to Edit the Menu&quot; --filename=&quot;/usr/share/bunsen/bunsen-docs/helpfile-menu.txt&quot; --width=900 --height=700)
        IL(Reconfigure) AN(Reconfigure) _I
        IL(Restart) AN(Restart) _I
      _M
      MXIL(bl-compositor,CompositingPipeMenu,Compositor)
      MXIL(bl-conky-pipemenu,pipe-conkymenu,Conky)
      MXIL(bl-tint2-pipemenu,pipe-tint2menu,Tint2)
        _exec(Appearance,lxappearance)
        _exec(Choose Wallpaper,nitrogen)
        _exec(Notifications,xfce4-notifyd-config)
        _exec(Power Management,xfce4-power-manager-settings)
        MIL(dmenuconfig,dmenu)
          _exec(Edit Start-up Script,bl-text-editor ~/.config/dmenu/dmenu-bind.sh)
          SL(Help?)
          _exec(man page,TERM -T 'man dmenu' -e man dmenu)
        _M
        MIL(gmrunconfig,gmrun)
          _exec(Edit Config File,bl-text-editor ~/.gmrunrc)
          SL(Help?)
          _exec(man page,TERM -T 'man gmrun' -e man gmrun)
        _M
        MIL(DisplaySettings,Display)
          _exec(ARandR Screen Layout Editor,arandr)
          SL(Help?)
          _exec(man xrandr,TERM -T 'man xrandr' -e man xrandr)
        _M
    _M
    MIL(system,System)
      MXIL(bl-printing-pipemenu,PrintingPipeMenu,Printers)
      _exec(Synaptic Package Manager,gksudo synaptic)
      _exec(File Manager as root,gksudo bl-file-manager)
      _exec(Text Editor as root,gksudo bl-text-editor)
      _exec(Login Settings,gksudo bl-text-editor /etc/lightdm/lightdm-gtk-greeter.conf /etc/lightdm/lightdm.conf)
      _exec(GParted,gksudo gparted)
      _exec(Edit Debian Alternatives,gksudo galternatives)
      S
      _exec(About Bunsen Alternatives,zenity --text-info --title=&quot;About Bunsen Alternatives&quot; --filename=&quot;/usr/share/bunsen/bunsen-docs/helpfile-bl-alternatives.txt&quot; --width=900 --height=700)
    _M
    MXIL(bl-help-pipemenu,help,Help)
    S
    MXIL(bl-kb-pipemenu,keybinds,Display Keybinds)
    S
    _exec(Lock Screen,bl-lock)
    _exec(Exit,bl-exit)
  _M  
_ObMenu

When you write this to file make sure to remove leading new lines at the top of the file or
obmenu will complain if you decide to use it.
Also when using obmenu and you click save,  it will readjust xml with tabs and new lines.

Thanks, and hopefully useful to someone.
If you can think of some useful definitions to add for openbox menu feel free to chime in.
Or any corrections in my macros too of course tongue

Last edited by gako (2015-12-20 16:51:04)

Offline

Board footer

Powered by FluxBB