#!/bin/sh ## ## SCRIPT: 00_GEN_objectsDownHTMLpage_4txtFiles_withTOC.sh ## ## PURPOSE: Generate an HTML file with ''-tag sections down ## the web page --- one statment for each '.txt' ## file in the current directory. ## ## I usually use this for making pages to display script code. ## The '.sh' files need to be renamed to have a '.txt' suffix ## so that the web server displays the script files as text blocks. ## I use one of my batch-renaming scripts, seen via my freedomenv.com ## Handy-Nautilus-Scripts pages, to simply add a '.txt' suffix to ## each script file in the current directory. ## ## HOW TO USE: Put this script in a directory of '.txt' 'objects' and run it. ## Then rename and edit the 'temp.htm' file that is created in ## the current directory. Edit to tailor titles, intro section, etc. ## ## You can look at the freedomenv.com pages that show ## Nautilus-Scripts to extract samples of explanatory text ## and HTML formatting tags to add to the 'temp.htm' file. ## ## Started: 2011jan04 ## Updated: ## FOR TESTING: # set -v set -x ################################### ## Initialize the htm output file. ################################### HTMFILE="temp.htm" CURDIR=`pwd` echo " Title Goes Here

Title Goes Here

subtitle goes here

A few more notes or links may be added.

Introduction :

Table of Contents: (of this page)

    " > "$HTMFILE" ################################# ## Set the filenames list. ################################# FILENAMES=`ls | grep '\.txt$'` ## FOR TESTING: # echo "$FILENAMES" > $HTMFILE # exit ############################################ ## START THE LOOP on the filenames ## --- to create the Table-of-Contents ## section of the HTML page. ############################################ FILECNT=0 for FILENAME in $FILENAMES do FILECNT=`expr $FILECNT + 1` # FILENAMECROP=`echo "$FILENAME" | sed 's|\.txt$||'` ## Write out TOC
  • statement. echo "

  • $FILENAME - script to yada yada yada " >> "$HTMFILE" done ################################################# ## Write the HTML for the end of the TOC section ## and the START of the list section. ################################################# echo "

    End of Table of Contents. See the warning notes below.

How the code samples (below) are presented - and other notes :

Each of these nautilus-script code samples is presented as an HTML embedded plain-text 'object' so that you can scroll the text, vertically or horizontally.

Note that the batch ('multi' named) image processing scripts can handle one file as well as multiple files.

Generally, in the scripts, I use double-# (##) to indicate a true comment. That is, it is not an executable statement and should never be de-commented.

I use single-# (#) to indicate an executable statement that has been commented. Typically this is because I might want to decomment the statement when doing testing of the script in a terminal window. Generally, the statement should be re-commented --- or a neighboring statement should be commented --- when finished testing.

I do not try to make one-liner scripts, nor do I try for the ultimate in processing efficiency. (But I am aware of several things to avoid that would make scripts run slow as molasses.) I try to make the scripts readable (to me). At the same time, they execute quite rapidly, even on a directory containing over a hundred files. These scripts can be MAJOR time savers.

In the batch code samples, you will see that I may be using the Linux/Unix variable

$@

to 'pick up' the list of selected file names. If this proves to be a problem (for example, with embedded spaces in some filenames), I may have to resort to using a nautilus variable:

  • NAUTILUS_SCRIPT_SELECTED_URIS or
  • NAUTILUS_SCRIPT_SELECTED_FILE_PATHS

This is a sign that these code samples are NOT the 'be all and end all'. You (and I) will probably have to edit them somewhat to handle particular issues.


The image-processing scripts below are presented roughly in the order in which I use them:

  • a converting script for converting '.png' or '.gif' files (like screen captures or images from the web) to '.jpg' --- script name starts with '00'

  • renaming scripts (several) for JPG files from my digital camera --- the several script names start with '01'

  • I do the cropping and gamma-correction manually, usually with 'mtpaint'. The script that starts up 'mtPaint', on a set of selected files, starts with the '02' prefix.

  • batch renaming of image files (jpg --- and even png or gif) to contain X-Y pixel size in the names --- script name starts with '03'

  • batch down-sizing scripts for image files, putting the new-sized files into a (new) subdirectory, or putting the original files into a subdirectory --- the (two) script names start with '04' --- a Y-size is prompted for, using zenity

  • batch renaming script, that changes an MMMxNNN size in the filename to a new, actual XXXxYYY size --- script prefix '05'

  • batch thumbnailing script, which prompts for Y-size using zenity --- script prefix '06'

  • several animated GIF scripts --- prefix 'ani'

  • some colorizing scripts --- prefix 'color'

  • several seamless tile scripts --- prefix 'tile'


Navigation :

Use the table-of-contents (above) to go directly to the desired image-processing code listing. OR simply scroll down this page to spot samples of interest.

Alternatively, use the 'Find text' option of your web browser to look for keywords on this page. For example, when looking for examples of scripts using the 'convert' or 'identify' command, use 'convert' or 'identify' --- or when looking for a script involving 'jpg' or 'png' or 'gif' files, use keyword 'jpg' or 'png' or 'gif'.


Shell considerations :

Most of these samples are intended to run with the Bourne or the Korn shells (command interpreters), as well as with the Bash command interpreter. Most of these samples employ Linux/Unix commands (and their parameters) available to all three interpreters, so the scripts will generally run in any of these three interpreters.

In fact, the Korn and Bash interpreters are offshoots of the Bourne command interpreter.


Warnings :

Although I have used these scripts, I have used them, for the most part, on directories of files with no spaces (blanks) in the filenames. The scripts may not be tested thoroughly enough for every application environment. Use at your own risk.

    This may sound too dire. The scripts are generally quite safe. If they are meant change a file, they will, in most cases,

    • put the change in a new file
    • simply rename the file (If the renaming is not what was wanted, just rename.)
    • or fail, not doing anything to the original file.

    Examine the code, to erase doubt.

The code is presented here mostly for my own personal use --- as a reference (for example, from different computers, at home or away) and as a means of organized archival and backup. I may use portions of the scripts for working code fragments to be applied in other scripts.

If other people use these scripts, they should test them on test data before using in a 'serious' mode.

Start of Display of the Code of the Scripts :

> "$HTMFILE" ############################################ ## START THE LOOP on the filenames ## --- to create the statements, ## down the HTML page. ############################################ FILECNT=0 for FILENAME in $FILENAMES do FILECNT=`expr $FILECNT + 1` # FILENAMECROP=`echo "$FILENAME" | sed 's|\.txt$||'` ## Write out object-display statement. echo "

FILE - $FILENAME :

< Return to Table of Contents, above. >

Script for yada yada yada :

File is not shown. Technical difficulties. " >> "$HTMFILE" done #################################################### ## END OF FILES LOOP. Write out bottom of htm file. #################################################### echo "

Bottom of Title Goes Here page.

To return to a previously visited web page location, click on the
Back button of your web browser, a sufficient number of times.
OR, use the History-list option of your web browser.
OR ...

< Go to start of Text Objects display, above. >
< Go to start of Table of Contents, above. >
< Go to Top of Page, above. >

Page created 2011 xxx 00. Page changed 2011 xxx 00.

" >> "$HTMFILE" #################### ## EDIT HTML FILE #################### # kwrite "$HTMFILE" gedit "$HTMFILE" ################### ## SHOW HTML FILE ################### seamonkey "$HTMFILE" # firefox "$HTMFILE"