# Specials and Built-in Global Variables

# Specials and Built-in Global Variables

Specials are functions that are processed by &kommander;. You should be aware that whe using the old style parser all &kommander; specials will be executed first and then the script will be executed. In most cases this is not a problem, but in a few (mostly in loops, conditions) it is.

The below list might be slightly outdated. It is recommended to use the Function Browser to get help about the available functions. The Function Browser can be reached from inside the Kommander Text editor, by clicking the Function... button.

`@dcop(`appId`, `object`, `function`, `arguments`)`

  Make a &DCOP; call. @dcop(kmail, KMailIface, checkMail(), )

`@dcopid`

  The &DCOP; id of the process. (kmdr-executor-@pid)

`@dialog(`dialog`[,`parameters`])`

  Launches the specified Kommander dialog. Dialog is sought in dialog directory and in current directory - in that order. This prepends the call to the executor and sets the default directory to the one the Kommander application is in. Parameters can be passed in the usual Unix way or you can pass named parameters like variable=value. You can then find passed parameters in the global pool. @global(variable) would return value.

`@env(`environmentVariable`)`

  Expands to the specified environment variable. @env(PWD) expands to $PWD. Remember that $ is part of the shell and shouldn't be used.

`@exec(`command`)`

  returns the output of executing the specified command. @exec(ls -l).

`@execBegin ... @execEnd`

  same as `@exec`, but supports shebang and multiline scripts. This serves for various scripting languages either by decalring them or using a shebang.

  - `@execBegin(php)`

  - `@execBegin`(#!/usr/bin/php)

  The first one uses the name of the PHP executable. &kommander; searches PATH for php and if it is not found looks to see if it is registered with &kommander; in a location outside of your path. If not it tells the user it cannot be found. The second examples uses the classic shebang which can have some benefits and also problems. If you have a beta copy of PHP5, for instance, in `/usr/local/bin` which would not be found because it would find on in `/usr/bin` this is useful. If, however, you distribute the dialog to someone who has PHP in `/usr/local/bin` only it will not be found with the shebang used. So using shebangs is cautioned and using the executable is recommenede if you are sharing files.

`@global(`variable`)`

  expands to the value of the specified global variable.

`@null`

  Returns null. Now that Kommander checks for empty widgetText on execution this will prevent erroneous errors in the case of an unset state on a widget.

`@parentPid`

  The &PID; of the parent process.

`@pid`

  The &PID; of the process.

`@readSetting(`key`, `defaultValue`)`

  reads a value from `kommanderrc`. See also @writeSetting.

`@selectedWidgetText`

  the selected content in a widget that can show more than one value, like list widgets

`@setGlobal(`variable`, `value`)`

  Sets the global variable to the specified value.

`@widgetText`

  the content of a widget

`@writeSetting(`key`, `value`)`

  write value to `kommanderrc`. All &kommander; dialogs share the same kommanderc file, each one will have its own section inside it.

## Array Function Group

`@Array.values(`array`)`

  Returns an EOL-separated list of all values in the array. Can be used to walk through an array.

`@Array.keys(`array`)`

  Returns an EOL-separated list of all keys in the array.

`@Array.setValue(`array`, `key`, `value`)`

  Sets a key and value for an element of an array. If no array exists it is created.

`@Array.clear(`array`)`

  Remove all elements from the array.

`@Array.count(`array`)`

  Return number of elements in the array.

`@Array.value(`array`,`key`)`

  Return the value associated with the given key.

`@Array.remove(`array`,`key`)`

  Remove element with the given key from the array.

`@Array.fromString(`array`,`string`)`

  Add all elements in the string to the array. String should have key\tvalue\n format."

`@Array.toString(`array`,`string`)`

  "Return all elements in the array in key\tvalue\n format."

## File Function Group

`@File.read(`file`)`

  Return content of the given file.

`@File.write(`file``string`)`

  Write given string to a file.

`@File.append(`file``string`)`

  Append given string to the end of a file.

## String Function Group

`@String.length(`string`)`

  Return number of chars in the string.

`@String.contains(`string`,`substring`)`

  Check if the string contains given substring.

`@String.find(`string`)`

  Return position of a substring in the string, or -1 if it isn't found."

  This will have an optional integer start postion for find next uses in Alpha 6.

`@String.left(`string`, `int`)`

  Return first n chars of the string.

`@String.right(`string`, `int`)`

  Return last n chars of the string.

`@String.mid(`string`, `int start`, `int end`)`

  Return substring of the string, starting from given position.

`@String.remove(`string`, `substring`)`

  Remove all occurences of a given substring.

`@String.replace(`string`, `substring find`, `substring replace`)`

  Replace all occurences of a given substring with a given replacement.

`@String.upper(`string`)`

  Convert the string to uppercase.

`@String.lower(`string`)`

  Convert the string to lowercase.

`@String.compare(`string`, `string`)`

  Compare two strings. Return 0 if they are equal, -1 if the first one is lower, 1 if the first one is higher

`@String.isEmpty(`string`)`

  Check if string is empty.

`@String.isNumber(`string`)`

  Check if string is a valid number.

## Built-in Globals

Built-in globals are accessed just like regular global variables with `@global`.

`@global(_KDDIR)`

  The directory the current dialog is in.

`@global(_NAME)`

  The name of the dialog