LIL File Actions Documentation

LIL File Actions, or just lilfa, is a tool to provide a simple GUI for running a command inside a folder that contains a series of files. When lilfa runs it checks the current folder and its parents for a LIL script named fileacts.lil and runs it to populate a list of files using the instructions in the script (alternatively lilfa can run the script passed to it as the first parameter, but the main use case is having it find the script automatically).

Common uses for this is to present list of files in the folder to be viewed with a specific viewer or editor (e.g. all PDF files in a directory) with folder-specific settings, run bytecode under a VM, build source files for a project or even run custom maps for a game. In fact, the examples at the bottom of the page show exactly that.

Scripting

The script accepts all LIL commands (see LIL documentation) as well as LILGUI commands (see LILGUI documentation) which allows it to optionally show some custom GUI controls for running the command. The example Quake script at the bottom uses LILGUI commands to provide an option to run the game in fullscreen and to optionally activate one of the two official expansion packs for the game.

In addition to the above commands, the following lilfa-specific commands are also provided:

Adding files

Scanning files

Filename manipulation

Running commands

Multiple selection

Misc

Callbacks (or special user-defined functions)

Two functions can be defined that lilfa will call when the selection changes and when the user clicks the Run button (or presses Enter or double clicks a file name). These functions are:

Examples

Duke Nukem 3D custom map launcher

The following code is a very simple fileacts.lil script that can be placed inside a Duke Nukem 3D game installation with the EDuke32 engine to launch custom map files:

set-caption "Come Get Some Maps"
add-files . *.map
func select {filename} {
    set-command "eduke32 -nologo -nosetup -map $filename"
}

Fossil Web UI repository launcher

The following code is a slightly more advanced fileacts.lil script that can be placed inside a directory with Fossil repositories (assuming they all use the .fossil file extension) to launch the Web UI for the selected one. This script also shows how to use the output of run-command to obtain additional information as well as store external files (in this case, a temporary batch file used to collect all names in a single call):

# Fancy caption
set-caption "Open Fossil Web UI"

# Scan all fossil files
add-files . *.fossil

# Create a temporary batch file to collect project names
set bat {@echo off}
for-each-file {
    set bat $bat{
        fossil info "}$filename{" | findstr /C:project-name
    }
}
store fileacts.bat $bat

# Run and delete the batch file (its output is a project name per line)
set titles [run-command "cmd /c fileacts.bat && del fileacts.bat"]
set titles [split $titles "\n"]

# Go over all files again and set the display for each one
set i 0
for-each-file {
    set display "[substr [index $titles $i] 14] (${filename})"
    inc i
}

# Set the command when a file is select to launch Fossil's web UI
func select {filename} { set-command "fossil ui $filename" }

Quake 1 custom map launcher

The following code is a more advanced fileacts.lil script that can be placed inside a Quake 1 game installation with the Quakespasm engine under Windows to launch custom maps (note, however, that this is just an example - MiniQL is a better launcher for this purpose) with custom GUI options and nice file display:

# Fancy caption
set-caption "Run Custom Quake Map"

# Scan for single map files
add-files id1\maps *.map
add-files hipnotic\maps *.map
add-files rogue\maps *.map

# Scan for map packs with a start map
scan-dirs . {
    if [file-exists "${filename}\\maps\\start.bsp"] {
        add-file "start +game [get-filename $filename]"
    }
}

# Prettify file display
for-each-file {
    if [streq [substr $filename 0 12] {start +game }] {
        set display "Game: [substr $filename 12]"
    } {
        set filename [get-filename $filename]
        set filename [get-filename-without-extension $filename]
        set display "Map: $filename"
    }
}

# Variables used to build the command to run
set mapfile {}
set fullscreen 1
set game base

# This build the command based on the current selected file and options
func build-command {} {
    local p
    set p {}
    if $fullscreen {
        set p "$p -current"
    } {
        set p "$p -window -width 640 -height 480"
    }
    if not [streq $game base] { set p "$p -$game" }
    set-command "quakespasm $p +map $mapfile"
}

# Show and create the control panel.  The fullscreen and game variables
# are bound to the checkbox and radio buttons
show-panel
checkbox 'Fullscreen' fullscreen
radio 'Base' game base
radio 'Hipnotic' game hipnotic
radio 'Rogue' game rogue

# Called when the file selection changes
func select {fn} {
    set mapfile $fn
    build-command
}

# Watch the fullscreen and game variables (which are bound to the GUI
# controls) and call build-command if they get modified
watch fullscreen game { build-command }