Scripting

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.

Open a filer window showing a file I'm editing

There are various possibilities:

  • ROX-style applications like Edit should already have an Up button on their toolbar for this.

  • You can get some window managers to provide such a button in the title bar. This code creates a change-to-parent action for sawfish:

    (defun change-to-parent (window)
      "Close window and open the parent directory viewer"
      (interactive "%W")
      (let ((title (caddr (get-x-property window 'WM_NAME))))
        (when (and title (string-match "[~/][^*?]+" title))
          (let ((path (substring title (match-start 0) (match-end 0))))
            (system (concat "rox -s " path))
            (delete-window-safely window)
    ))))
  • You can script other applications. For example, Stephen Watson gives these instructions for Emacs:

    (defun rox-view-file (file)
      "Open ROX-Filer window for named file"
      (interactive "fFile to show: ")
      (call-process "rox" nil 0 nil "-s" file)
      )
    (defun rox-view-current ()
      "Open ROX-Filer window for the current file"
      (interactive)
      (rox-view-file buffer-file-name)
      )
  • For Vim (or GVim), put this in your ~/.vimrc file:

      map <F12> :silent !rox -s %<CR>

Open a filer window with a particular style, size, position

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:ns="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."

Open html file in Firefox

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

Openbox 3 appdirs menu

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>"

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;