IdEst – ID3 Editing and Scripting Tool (split by node):   Section:   Chapter:FastBack: Scripting   Up: batch   FastForward: Backups   Contents: Table of ContentsIndex: Concept Index

10.4.1 How to Write New Batch Modules

The rules for writing batch modules are similar to those for formats (see format modules) with only few differences.

The source for format module name must be saved in the file named name.scm located in the subdirectory idest/batch somewhere in the Guile load path. It must begin with the following clause:

(define-module (idest batch name))

The module must define and export the ‘idest-main’ function, whose calling convention is the same as that in the usual idest scripts (see idest-main). This function must return the new list of frames. If it returns an empty list, all existing frames will be deleted. If the function chooses not to modify any frames, it must return #f.

If the module needs to process command line arguments, it should do so in the function ‘idest-init’, defined as:

(define-public (idest-init)
  ...)

Finally, the module should export the symbol ‘description’ with a concise description of the module. This description will be shown in the --batch=help output (see help batch).

To illustrate this, here is the code for module ‘delfrm’, which removes the requested frames from all argument files:

(define-module (idest batch delfrm))

(define-public description
 "remove requested frames from the input files")

(define frame-list '())

(define-public (idest-main)
  (filter
   (lambda (frame)
     (not (member (car frame) frame-list)))
   frames))

(define-public (idest-init)
  (let ((cmd (command-line)))
    (cond
     ((< (length cmd) 3)
      (error
       "usage: idest --batch=delfrm FRAME-LIST FILE...")
      (exit 1))
     (else
      (set! frame-list (string-split (list-ref cmd 1) #\,))
      (set-program-arguments
        (cons (car cmd) (list-tail cmd 2)))))))

IdEst – ID3 Editing and Scripting Tool (split by node):   Section:   Chapter:FastBack: Scripting   Up: batch   FastForward: Backups   Contents: Table of ContentsIndex: Concept Index