Since it is very common to create a list containing a sequence of numeric values there is a shorthand to create such a list using [<number> to <number>, <step size>]:
Examples:
list=[1 to 10];//without the optional step size for (a in list)
A while-loop evaluates a block of code as long as a condition is true.
Example:
a = 0;
while (a < 10)
Built in functions can be called to calculate trigonometric values, create lists, extract values from an XML and much more.
Examples:
a = sin(1.2);//evaluates to 0.932039...
a = max(1, 2, 3, 4, 5);//evaluates to 5 a = isEmpty([1 to 10]);//evaluates to false
a = containsElement([1 to 10, 2], 3);//evaluates to true
Tip: Please also see the Script examples page that shows some commonly used script snippets.
Object getValue(String name, Object default)
Returns the value of the variable named name or returns default when the variable is undefined or null.
Object setValue(String name, Object value) Sets the variable named name to value and returns value Object removeVariable(String name)
Removes the variable named name. Number abs(Number value) Returns the absolute value of value.
Number pow(Number base, Number exponent)
Returns the value of the first argument raised to the power of the second argument.
Number sqrt(Number a)
Returns the square root of the number.
Number sin(Number a)
Returns the sine of the angle in radians.
Number cos(Number a)
Returns the cosine of the angle in radians.
Number tan(Number a)
Returns the tangent of the angle in radians.
Number asin(Number a)
Returns the sine of the angle in radians.
Number acos(Number a)
Returns the arc cosine of the angle in radians.
Number atan(Number a)
Returns the arc tangent of the angle in radians.
Number atan2(Number y, Number x)
Returns the angle of the polar representation of the rectangular coordinate (x, y).
Number sinh(Number a)
Returns the hyperbolic sine of the value.
Number cosh(Number a)
Returns the hyperbolic cosine of the value.
Number tanh(Number a)
Returns the hyperbolic tangent of the value.
Number toRadians(Number a)
Converts the Number from degrees to radians.
Number toDegrees(Number a)
Converts the Number from radians to degrees.
Number round(Number a)
Rounds the number to the nearest integer.
Number ceil(Number a)
Returns the next highest integer value by rounding up value if necessary.
Number floor(Number a)
Returns the next lowest integer value by rounding down value if necessary.
Date addDays(Date d, Number a)
Returns a new date by adding a number of days to the date d. Date addHours(Date d, Number a)
Returns a new date by adding a number of hours to the date d. Date addMinutes(Date d, Number a)
Returns a new Date by adding a number of minutes to the date d. Date addSeconds(Date d, Number a)
Returns a new date by adding a number of seconds to the date d. Date getDate()
Returns the current date and time.
Date getDate(String date, String pattern)
Converts the string to a date using the specified pattern. (see pattern characters.) Date getDate(Number year, Number month, Number day)
Returns the Date specified by the arguments.
Date getDate(Number year, Number month, Number day, Number hours, Number minutes, Number seconds) Returns the date specified by the arguments.
Date getDate(Date date, Number hours, Number minutes, Number seconds) Returns the date specified by the arguments.
Number getUptimeMillis()
Returns milliseconds since boot, not counting time spent in deep sleep.
Number getElapsedRealtimeMillis()
Returns milliseconds since boot, including time spent in sleep.
Number getDurationMillis(String duration)
Returns the duration in milliseconds specified by the duration string (e.g. "2m 15s" returns 135000).
String getDurationString(Number duration)
Returns the duration string representing the specified milliseconds (e.g. 135000 returns "2m 15s").
Number getByteSize(String byteSize)
Returns the number of bytes specified by the string (e.g. "10kb 15b" returns 10255).
String getByteSizeString(Number byteSize)
Returns the formatted byte string representing the specified bytes (e.g. 10255 returns "10kb 15b").
Number toNumber(String number) Converts the specified parameter to a number.
Number min(Number n1, Number n2, ...) Returns the smallest number of the arguments.
Number max(Number n1, Number n2, ...) Returns the largest number of the arguments.
Boolean isEmpty(String s)
Returns whether the string is empty or not.
Number length(String s)
Returns the number of characters in string s.
String substring(String s, Number start, Number end) Returns the substring of the specified string.
String substring(String s, Number start) Returns the substring starting at the specified index.
String left(String s, Number length)
Returns the first length characters of the specified string.
String right(String s, Number length)
Returns the last length characters of the specified string.
Number indexOf(String s, String search) Returns the first index of search in s.
Number indexOf(String s, String search, Number start) Returns the first index of search after start in s.
Number lastIndexOf(String s, String search) Returns the last index of search in s.
Number lastIndexOf(String s, String search, Number start) Returns the last index of search before start in s.
Boolean startsWith(String s, String prefix) Checks whether the string s starts with prefix. Boolean endsWith(String s, String suffix) Checks whether the string s ends with suffix. Boolean contains(String s, String search) Checks whether the string s contains the substring search. List split(String s, String pattern)
Splits the string s into a list of strings by using the regular expression pattern as the delimiter. (see Regular expressions.)
List splitCSVRecord(String s)
Splits the comma delimited string s into a list of tokens. Takes double quotes for escaped fields into consideration.
Boolean matches(String s, String pattern)
Returns whether the string s matches the regular expression pattern. (see Regular expressions.) Boolean matches(String s, String pattern, List groups)
Returns whether the string s matches the regular expression pattern and fills the captured groups into the existing list groups. (see Regular expressions.)
String replace(String s, String search, String replace)
Returns a modified string by replacing all occurrences of search with replace in string s. String replaceAll(String s, String regex, String replacement)
Returns a modified string by replacing all substrings matching regex with replacement in string s. (see Regular expressions.)
String trim(String s)
Returns a modified string by removing all leading and trailing whitespace from string s. String concat(Object o1, ...)
Returns the string concatenation of the specified objects.
String toUpperCase(String s)
Converts the string to upper case using the rules of the default locale.
String toLowerCase(String s)
Converts the string to lower case using the rules of the default locale.
String encodeURLForm(String urlPart)
URL-encodes the specified urlPart (for application/x-www-form-urlencoded, spaces are encoded as +).
String encodeURL(String urlPart)
URL-encodes the specified urlPart (spaces are encoded as %20).
String encodeHTML(String text) HTML-encodes the specified text. List newList(Object o1, ...)
Returns a new list containing the specified objects.
List copyList(List list)
Returns a copy of specified list (flat copy).
Number length(List list)
Returns the number of elements in list. Boolean isEmpty(List list)
Returns whether the list contains any elements or not.
List addElement(List list, Object o1)
Returns the same list after adding the object at the end of the list. Returns a new list when the list should not exist yet.
List addElement(List list, Number index, Object o1)
Returns the same list after adding the object at the specified index (zero based).
List removeElementValue(List list, Object o1)
Returns the same list after removing all elements with the specified value.
Boolean containsElement(List list, Object o1)
Returns true when the list contains the specified element.
Object removeElement(List list, Number index)
Removes the object at the specified index (zero based) and returns the removed object.
Object getElement(List list, Number index) Returns the object at the specified index (zero based).
Object getRandomElement(List list) Returns a random element of the list.
Number indexOfElement(List list, Object value)
Returns the first index of the element in the list or -1 when the element is not contained in the list.
List sort(List list, Boolean casesensitive, Boolean natural) Modifies the list by sorting the values.
List reverse(List list)
Modifies the list by reversing the order of the contained values.
Map newMap()
Returns a new empty map Boolean isEmpty(Map map)
Returns whether the map contains any elements or not.
Number length(Map map)
Returns the number of elements in map. Map copyMap(Map map)
Returns a copy of specified map (flat copy).
Map addMapEntry(Map map, String key, Object value)
Adds a new entry key->value to the map and returns the map. Returns a new map when the map should not exist yet.", Object getMapValue(Map map, String key)
Returns the object for key or null when no mapping for key exists.
Object getMapValue(Map map, String key, Object default) Returns the object for key or default when no mapping for key exists.
Object removeMapEntry(Map map, String key) Removes the entry for the given key and returns the value.
List getMapKeys(Map map) Returns a list of the keys of map. List getMapValues(Map map) Returns a list of the values of map.
String evaluateXPathAsString(String xml, String xpath)
Evaluates the XPath expression on the given XML and returns the result as a string. (see XPath Specification.) String hash(String value, String encoding, String algorithm)
Calculates the hash of value using the specified encoding (like UTF-8 or UTF-16LE) and hashing algorithm (like MD5 or SHA1).
Object log(Object value)
Logs the specified object in the Automagic log and returns the unmodified object.
Object eval(String script)
Evaluates the string as a script and returns the value of the last expression.
Number random()
Returns a random number between 0.0 and 1.0 (exclusive).
Number random(Number low, Number high)
Returns a random number between low and high (inclusive).
Boolean sleep(Number milliseconds) Waits for the specified amount of milliseconds. Boolean sleep(String duration)
Waits for the specified duration like "2m 30s".
Boolean existsFile(String path)
Checks whether the file denoted by path exists or not.
Boolean isDirectory(String path)
Checks whether the file denoted by path is a directory.
Number getPixelColor(Bitmap image_data, Number x, Number y) Returns the color (argb) of the pixel of the image at location x, y. Number getRed(Number color)
Returns the red component of the specified color. Number getGreen(Number color)
Returns the green component of the specified color. Number getBlue(Number color)
Returns the blue component of the specified color. Number getAlpha(Number color)
Returns the alpha component of the specified color.
Number newColor(Number a, Number r, Number g, Number b) Returns a new color from the specified ARGB components.
Number distance(Location loc1, Location loc2)
Calculates the distance between locations loc1 and loc2 in meters.
Location newLocation(Number latitude, Number longitude) Creates a new Location for the specified latitude and longitude. String setHTTPResponseHeader(String header, String value) Sets the HTTP response header to the specified value and returns the value.
Number setHTTPResponseStatus(Number status)
Sets the HTTP response status to the specified value and returns the value.
Object getWidgetElementProperty(String widgetName, String elementName, String property) Gets the current value of the property of the specified widget element.
Object setWidgetElementProperty(String widgetName, String elementName, String property, Object value)
Sets the given property of the specified widget element to value. String getAppName(String packageName)
Returns the display name of the app from the specified package or null when not available.
String getActivityName(String packageName, String className)
Returns the display name of the activity from the specified package and class or null when not available.
String getServiceName(String packageName, String className)
Returns the display name of the service from the specified package and class or null when not available.
List getFlowNames()
Returns a list containing the names of all flows.
List getWidgetNames()
Returns a list containing the names of all widgets.
Note: Are you missing a function? Please let us know in the forum.