This
is a list of commands babelscript current supports. It is possible to
add arbitrary new commands, since any file "xyz.bls" will be used as a
new command xyz (see below section Library commands). In general, each parameter of a command may contain variables (enclosed in curly brackets { }) or constant text or both, the examples show only the normal usage.
In
babelscript, strings are written without quotation marks and any string
variables are directly inserted into these strings. The parser
recognizes variables by means of curly brackets. The following
special string variables may be used:
- {newline} means a line feed character. When searching for it with find, it also matches the sequence CR-LF. - {tab} is a tab character. - {empty} is the empty string. - {blank} is a space character. - {app} is the path to the babelscript installation folder (without trailing slash) - {temp} is the system's temporary folder (without trailing slash)
find xyz in {text} Searches xyz in {text}, beginning from the last position. If the search fails, the program continues at the next repeat command belonging to the current loop. If there is no surounding loop, the program exits with a message. xyz may contain unbound variables, which are set to content found in {text}.
load http://en.wikipedia.org as {page} striphtml {page} find Welcome to {text}.{blank} in {page} print {text}// will print "Wikipedia, the free encyclopedia that anyone can edit"
findfirst xyz in {text} Same as find, but first resets the position in {text}, so the search starts at the first character.
insert xyz into{text} Inserts
the given string into the text variable. As insert position the last
position is used. This may be either the position behind the last insert command or the position behind the text found in the last find / findfirst command. The initial position is the beginning of the text.
add xyz to {hash} Adds the given string to the hash variable. This allows fast testing if a string collection contains a certain string via if...contains or if...misses.
let {text}= xyz Sets the text variable to the given string.
striphtml{htmlpage} Converts a html page into plain text.
load http://en.wikipedia.org as {page}
striphtml{page}
print {page}
removetag <tag> from{htmlpage} Removes all html tags of the given form <tag> from the string variable {html}. A tag may include arguments.
load http://en.wikipedia.org as {page}
removetag script from{page}
removetag span class="mw-headline" from{page}
save{page}as wikipedia.html
utf8toascii{text} Converts a UTF-8 encoded text to plain ASCII.
load http://en.wikipedia.org as {page}
utf8toascii{page}
save {page} as wikipedia.html
Flow control
loop Starts a loop; the respective repeat command jumps back to this position.
repeat Checks
if during the last loop pass any variable has been changed (this check
covers only variables that are used outside the loop and includes the reading position of the variables). If so,
erases all variables that are introduced inside the loop and jumps back
to the loop command. Otherwise the loop is exited.
load http://en.wikipedia.org as {page} loop find <a href="/wiki/{internalLink}" in {page} print {internalLink}// prints a list of page names of all internal links on the wikipedia main page repeat
if {variable}contains xyz The commands until the corresponding endifwill only be executed if the text abc contains xyz. Both parameters may contains variables. {variable} may be both a string or a hash (see add command).
if {variable}misses xyz The commands until the corresponding endifwill only be executed if the text abc does not contain xyz. Both parameters may contains variables. {variable} may be both a string or a hash (see add command).
if {variable}== xyz The commands until the corresponding endifwill only be executed if the text in {variable} is equal to xyz. Both parameters may contains variables.
if {variable} != xyz The commands until the corresponding endifwill only be executed if the text in {variable} is different from xyz. Both parameters may contains variables.
I/O
load filename.ext as {text} Loads contents of the file filename.ext into the variable {text}. The
file may be in the local file system or in the internet. In case of a
HTTP request, it will be repeated if it fails. The file name may
contain variables.
reload filename.ext as {text} Same as load, but will not use babelscript's internet cache.
save {text}as filename.ext Saves the string {text} into the file filename.ext. The file name may also be a variable.
append {text}to filename.ext Same as save, but {text}is appended to the file. If the file does not exist, it is created.
delete filename.ext Deletes the file.
print text Prints
the argument to the command line. All variables are replaced with their
content. If the argument is left out, a blank line is printed. As a
shortcut for print, a question mark may be used.
open xyz with parameters Opens
the argument in either browser or text editor. Any parameters are optional. If the argument is a
link, not the link itself but its target will be opened.
open http://www.google.com // opens web site in the browser open test.jpg // opens image test.jpg in the associated image viewer open {variable}// opens the content of {variable}. If {variable} begins with http:// or file:///, the link target will be opened. open C:\windows\regedit.exe with /e {temp}\startup.txt HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run // list Windows startup entries
Library commands
If
a script contains an unknown command, first the current directory is
searched for scripts with the name of the command plus extension
".bls". Afterwards the directory library in the babelscript application
folder is searched. If a script is found, it will be called.
Inside a user-defined command script two special variables may be used:
{arg1} This variable is automatically set to the first parameter of the command in the calling script.
{result} This is automatically replaced with the second parameter of the command in the calling script.
The calling script must use the keyword as to
seperate two parameters. Alternatively library commands with one
parameter or no parameters are allowed. The following command
scripts are part of the
current distribution:
query{text}as{link} Queries a free meta search engine for {text} and sets {link} to the first link on the result page.