This is the old ROX web-site. Please use the new website instead.

Scripting hints

Many functions of ROX can be called by external programs using the SOAP interface. See the httpappendix C of the manual for more information on this.

There is a small Python script for calling these SOAP methods from the command line or from Python code. You can find it httphere.

An easy way to launch App Dirs from your shell without patching the shell.

This only works with httpzsh

Add to your /.zshrc:

  alias rehash="rehash; . ~/bin/load-appdir-cache.sh"
  [ "$DISPLAY" ] && . ~/bin/load-appdir-cache.sh

Create this /bin/load-appdir-cache.sh:

  APPDIR_CACHE=${HOME}/.appdir_cache
  if [ -f $APPDIR_CACHE ]; then
    cat $APPDIR_CACHE | while read item; do hash $item; done
  fi

And this /bin/update-appdir-cache:

  #!/bin/sh
  APPDIR_CACHE=${HOME}/.appdir_cache
  echo Updating AppDir cache... >/dev/stderr
  echo -n > $APPDIR_CACHE
  find /ROX-Apps ~/Apps -name AppRun | while read app; do
    echo "$(basename $(dirname $app))=$app" >> $APPDIR_CACHE
  done

Make sure to change /ROX-Apps to where your appdirs live, like /usr/local/apps

Then make this script executable:

  chmod +x ~/bin/update-appdir-cache

And put it in your Auto Start folder:

ln -sf ~/bin/update-appdir-cache ~/Choices/ROX-Session/AutoStart/

Opening a ROX window quickly from the shell

If you're using the httpzsh shell, add this to your ~/.zshrc:

open-rox-cwd() { rox }
zle -N open-rox-cwd
bindkey '\e[24~' open-rox-cwd

Now, pressing F12 will open a ROX filer window showing the current directory (even in the middle of editing a line). The actual keycode (the odd string after bindkey) varies by terminal; press <Ctrl-V> <Key> at a shell prompt to see what it should be (replacing ^[ with \e).

How can I open a filer window with a particular style, size, position, etc?

You can use the OpenDir SOAP method to set the style of the window directly (see the SOAP section of the filer's manual). You can also use use this to set the WM_CLASS, so that your window manager can be set to treat the window specially.

Matthew Weier O'Phinney writes:

"I now have an XML file entitled appsDir.xml containing the following:

<env:Envelope xmlns_env="http://www.w3.org/2001/12/soap-envelope">
  <env:Body xmlns_="http://rox.sourceforge.net/SOAP/ROX-Filer">
    <ns:OpenDir>
      <ns:Filename>/home/matthew/Apps</ns:Filename>
      <ns:Style>Large</ns:Style>
      <ns:Class>AppsDir</ns:Class>
    </ns:OpenDir>
  </env:Body>
</env:Envelope>

In addition, I have installed httpbbappconf. In addition, I have applied a patch (link is now broken; is the bug fixed now?) that makes the program behave when in an iconic or withdrawn (read: dockapp) state, as well as allowing for certain "geometry" type tags.

I run bbappconf as 'bbappconf -i &' in my .xinitrc file.

bbappconf looks for the WM_CLASS name and class. The Class defined in the SOAP RPC xml file above is the WM_CLASS name; class remains "ROX-Filer". Based on the combination of class and name, it applies the settings specified in a configuration file to the window in question when it appears.

In my ~/.bbtools/bbappconf.bb file, I have a series of applications for which I want to control either geometry, stickiness, starting workspace, or toggling decor. I have the following entry now, corresponding to the above SOAP RPC xml file:

bbappconf.3.classHint.class:    ROX-Filer
bbappconf.3.classHint.name:     AppsDir
bbappconf.3.positionX:          698
bbappconf.3.positionY:          0
bbappconf.3.width:              324
bbappconf.3.height:             200
bbappconf.3.Stick:              true

This places a window 324x200 in the upper right corner of my desktop and makes it sticky.

bbappconf, while originally developed as a blackbox tool, can be used without blackbox. A file entitled bbappconf.nobb contains settings that should be used if not using blackbox.

Also, the positionX, positionY, width, and height attributes are undocumented. They are a part of the patch to bbappconf detailed above -- this is why I include a sample configuration in here."

Can I get drag-and-drop saving with Vim?

You need something like this in your ~/.vimrc file:

function! Save()
  let tmpname = tempname()
  let fname = expand('%')
  if fname == ''
    let fname = 'TextFile'
  endif
  silent exec 'write !savebox ' . fname . ' &gt; ' . tmpname
  let newname = system('cat ' . tmpname)
  let tmp = system('rm ' . tmpname)
  if tmpname != ''
    exec 'file ' . escape(newname, ' ')
    set nomodified
  endif
endfunction

command! Save call Save()
map <F3> :Save<CR>

You'll need the savebox command from httphttp://rox.sourceforge.net/snapshots/gui_utils.tgz. Extract the archive and run './configure && make install' as root to install savebox.

Once you have the script saved to .vimrc or .gvimrc, you can then hit F3 to get a savebox from which you may then drag and drop to a ROX-Filer window; updating the text within this box will change the name under which it is saved.

How can I open a filer window showing a file I'm editing?

There are various possibilities:

A script to add rox and AppDirs to the openbox menu

After I switched from the fluxbox wm to the openbox wm, I noticed in the docs that for this wm one can generate menu items dynamicly by external scripts. Below a small perl script that walks through the filesystem generating menu entries that open a directory with rox. Also, more interesting, if it encounters AppDirs, program entries are generated.

To use it edit ~/.openbox/menu (or /usr/share/commonbox/menu) to include for example :

  [pipe] (/)    {/path/to/menu.pl /}
  [pipe] (Apps) {/path/to/menu.pl /usr/local/apps ~/apps}

Thus you can open any dir via the '/' entry and apps are automatically listed under the 'Apps' entry.

File menu.pl given below.

#!/usr/bin/perl
$no_idx = $#ARGV;
die "$0 needs a directory as argument.\n" unless @ARGV;
for (@ARGV) {
        $dir = $_ || next;
        opendir DIR, $dir || die "Could not open $dir\n";
        print "[exec] (.)  {rox $dir}\n"   unless $no_idx;
        $dir =~ s#/$##;
        print "[pipe] (..) {$0 $dir/..}\n" unless $no_idx;
        push @entries,
                map {   -x "$dir/$_/AppRun"
                        ? [$_, "[exec] ($_) {$dir/$_/AppRun}\n"]
                        : [$_, "[pipe] ($_) {$0 $dir/$_}\n"]
                }
                grep {$_ !~ /^\./ and -d "$dir/$_"}
                readdir DIR;
        closedir DIR;
}
print map {$$_[1]} sort {$$a[0] cmp $$b[0]} @entries;

Openbox 3 appdirs menu (httpAndrew Stephens)

OB3 uses XML for its configuration files, so I made my own small python script to create XML dynamic menu entries for files, appdirs, and normal directories (in that order). Files are opened/run using the rox filer (so it relies on what run action you've specified for the file type). Application Directories are simply run like usual, and normal directories are turned into their own submenus.

For your menu file, use an entry something like this:

<menu id="roxmenu-menu" label="ROX Menu" execute="/home/andrew/.config/openbox/scripts/roxapps.py /home/andrew/Apps" />

This will give you a menu of all your files, appdirs, and directories in your personal Apps folder. I like to the script to take my ROX-Menu entries so I use '/home/andrew/Choices/ROX-Menu-bin/Menu_Root' as the argument for script. The main thing to note is that the script DOES require a path as an argument.

Here it is... I'm new to Python (n++ doesn't work?) so feel free to make it better - There probably should be some exception handling in it... among other things...


#!/usr/bin/python

import sys
import os.path

print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
print "<openbox_pipe_menu>"

def scan( menu_path ):

        mylist = os.listdir( menu_path )
        mylist.sort()

        filelist = []
        appdirlist = []
        dirlist = []
        for name in mylist:
                fullname = os.path.join( menu_path, name )
                fullappdir = os.path.join( fullname,"AppRun" )
                if os.path.isfile( fullname ):
                        if name <> ".DirIcon":
                                filelist.append( "<item label=\"" + name + "\"><action name=\"Execute\"><execute>rox \"" \
                                + fullname + "\"</execute></action></item>" )
                elif os.path.isdir( fullname ):
                        if os.path.exists( fullappdir ):
                                appdirlist.append( "<item label=\"" + name + "\"><action name=\"Execute\"><execute>" \
                                + fullappdir + "</execute></action></item>" )
                        else:
                                dirlist.append( name )

        for f in filelist:
                print f

        for a in appdirlist:
                print a

        for d in dirlist:
                fullname = os.path.join( menu_path, d )
                print "<menu id=\"" + d + "\" label=\"" + d + "\">"
                scan( fullname )
                print "</menu>"

scan ( sys.argv[1] )

print "</openbox_pipe_menu>"

Can I open html file gracefully in httpMozilla Firefox? Even in new tabs everytime?

Sure. One way is to put the script below into (for example) ~/bin. Name it 'Firefox' or something and make it executable. Check if that /opt install path applies to your system.

#!/bin/bash

FIREFOX="/opt/firefox/firefox"

if [ -x "$FIREFOX" ]; then
      "$FIREFOX" "$1" || "$FIREFOX" -remote "OpenURL($1, new-tab)"
fi

Then right click on some HTML file in ROX-Filer and choose Set Run Action. Drag the `Firefox' script you created into the box, and you're set.

Here's another firefox script, make sure to change FIREFOXDIR to the right directory:

#!/bin/sh

FIREFOXDIR=/Programs/FireFox/Current
REMOTE="$FIREFOXDIR/mozilla-xremote-client -a firefox"
if ( $REMOTE "ping()" 2>/dev/null); then
        exec $REMOTE "openurl($1,new-tab)"
else
        exec firefox "$1"
fi

How can I get thumbnails for files other than images (ie. videos)?

You need version 2.1.1 (or later) of ROX-Filer and a Thumbnail Helper. For thumbnails of video files you will need httpVideoThumbnail, ROX-Lib2 version 1.9.12 and httpMPlayer.

Call I make a Set As Wallpaper menu item appear for images?

Use the SOAP method, see the manual for ROX. You can make a small script that takes a file argument and call ROX to set that image as background on the pinboard. You can't use the rootwindow for background, the pinboard is actually one big window that covers your desktop!

Example script (untested, but should work):

#!/bin/sh
rox --RPC << EOF
<?xml version="1.0"?>
<env:Envelope xmlns:env="http://www.w3.org/2001/12/soap-envelope">
 <env:Body xmlns="http://rox.sourceforge.net/SOAP/ROX-Filer">
  <SetBackdrop>
   <Filename>$1</Filename>
   <Style>Stretch</Style>
  </SetBackdrop>
 </env:Body>
</env:Envelope>
EOF

Change the Style element to your prefered mode (Stretch, Scale, Center, Tile), make the script executable (chmod +x scriptname) and put in in your ~/Choices/Send To/.image and it should show up when you shift-rightclick on an image. Though it will not show up at the top of the file menu when right click, if you want this you will have to choose Customise Menu from the top of the File menu (ROX-Filer 2.1.0 or later required).


Last edited on December 13, 2005 11:16 am.