#cp.tools

A collection of handy miscellaneous tools for Lua development.


#API Overview

Functions - API calls offered directly by the extension


#API Documentation

#Functions

Signaturecp.tools.appleScriptViaTask(script) -> none
TypeFunction
DescriptionTriggers an AppleScript command via hs.task to avoid potential memory leaks in hs.osascript.applescript.
Parameters
  • script - A single line AppleScript.
Returns
  • None
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 203

Signaturecp.tools.between(value, min, max) -> boolean
TypeFunction
DescriptionIs a value between the minimum and the maximum value?
Parameters
  • value - the value to check
  • min - the minimum value
  • max - the maximum value
Returns
  • A boolean
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 188

Signaturecp.tools.camelCase(str) -> string
TypeFunction
DescriptionConverts the supplied string to camelcase.
Parameters
  • str - The string you want to manipulate
Returns
  • A string
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 2162

Signaturecp.tools.centre(frame) -> hs.geometry point
TypeFunction
DescriptionGets the centre point of a frame.
Parameters
  • frame - an hs.geometry rect
Returns
  • A hs.geometry point
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 1655

Signaturecp.tools.characterToPercentEncodedString(input) -> string
TypeFunction
DescriptionEncodes a character as a percent encoded string.
Parameters
  • input - The string to process
Returns
  • A string
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 2505

Signaturecp.tools.cleanupButtonText(value) -> string
TypeFunction
DescriptionRemoves the … symbol and multiple >'s from a string.
Parameters
  • value - A string
Returns
  • A cleaned string
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 1966

Signaturecp.tools.contentsInsideBrackets(value) -> string | nil
TypeFunction
DescriptionGets the contents of any text inside the first bracket set.
Parameters
  • value - The string to process
Returns
  • The contents as a string or nil
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 2425

Signaturecp.tools.convertSingleHexStringToDecimalString(hex) -> string
TypeFunction
DescriptionConverts a single hex string (i.e. "3") to a binary string (i.e. "0011")
Parameters
  • hex - A single string character
Returns
  • A four character string
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 2314

Signaturecp.tools.desktopPath() -> string
TypeFunction
DescriptionGets the users Desktop Path
Parameters
  • None
Returns
  • The path as a string.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 112

Signaturecp.tools.dirFiles(path) -> table
TypeFunction
DescriptionGets all the files in a directory
Parameters
  • path - A path as string
Returns
  • A table containing filenames as strings, or nil followed by the error message if an error occurs.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 2041

Signaturecp.tools.doesDirectoryExist(path) -> boolean
TypeFunction
DescriptionReturns whether or not a directory exists.
Parameters
  • path - Path to the directory
Returns
  • true if the directory exists otherwise false
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 1494

Signaturecp.tools.doesFileExist(path) -> boolean
TypeFunction
DescriptionReturns whether or not a file exists.
Parameters
  • path - Path to the file
Returns
  • true if the file exists otherwise false
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 1512

Signaturecp.tools.doubleLeftClick(point[, delay]) -> none
TypeFunction
DescriptionPerforms a Left Mouse Double Click.
Parameters
  • point - A point-table containing the absolute x and y co-ordinates to move the mouse pointer to
  • delay - The optional delay between multiple mouse clicks
Returns
  • None
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 1706

Signaturecp.tools.encodeURI(input) -> string
TypeFunction
DescriptionReplaces all characters (except for those listed in the notes) with the appropriate UTF-8 escape sequences.
Parameters
  • input - The string to process
Returns
  • A string
Notes
  • Except these characters: ; , / ? : @ & = + $ # alphabetic, decimal digits, - _ . ! ~' ( )
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 2518

Signaturecp.tools.encodeURIComponent(input) -> string
TypeFunction
DescriptionEscapes all characters (except for those listed in the notes) with the appropriate UTF-8 escape sequences.
Parameters
  • input - The string to process
Returns
  • A string
Notes
  • Except these characters: alphabetic, decimal digits, - _ . ! ~' ( )
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 2534

Signaturecp.tools.endsWith(str, ending) -> boolean
TypeFunction
DescriptionChecks to see if str has the same ending as ending.
Parameters
  • str - String to analysis
  • ending - End of string to compare against
Returns
  • table
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 2214

Signaturecp.tools.ensureDirectoryExists(rootPath, ...) -> string | nil
TypeFunction
DescriptionEnsures all steps on a provided path exist. If not, attempts to create them. If it fails, nil is returned.
Parameters
  • rootPath - The root path
  • ... - The list of path steps to create
Returns
  • The full path, if it exists, or nil if unable to create the directory for some reason.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 2229

Signaturecp.tools.escapeTilda(input) -> string
TypeFunction
DescriptionEscapes a tilda.
Parameters
  • input - The string you want to escape.
Returns
  • A new string or "" if no input is supplied.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 255

Signaturecp.tools.exactMatch(value, pattern, plain, ignoreCase) -> boolean
TypeFunction
DescriptionCompares two strings to see if they're an exact match.
Parameters
  • value - The first string
  • pattern - The second string, including any patterns
  • plain - Whether or not to ignore patterns. Defaults to false.
  • ignoreCase - Ignore the case of the value & pattern.
Returns
  • true if there's an exact match, otherwise false.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 2366

Signaturecp.tools.executeWithAdministratorPrivileges(input[, stopOnError]) -> boolean or string
TypeFunction
DescriptionExecutes a single or multiple shell commands with Administrator Privileges.
Parameters
  • input - either a string or a table of strings of commands you want to execute
  • stopOnError - an optional variable that stops processing multiple commands when an individual commands returns an error
Returns
  • true if successful, false if cancelled and a string if there's an error.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 1564

Signaturecp.tools.fileLinesBackward(filename) -> function
TypeFunction
DescriptionAn iterator function that reads a file backwards.
Parameters
  • filename - The file to open in read only mode
Returns
  • An iterator function
Notes
  • This is similar to io.lines, but works in reverse.
  • Example Usage: for line in cp.tools.fileLinesBackward("file") do print(line) end
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 142

Signaturecp.tools.findCommonWordWithinTwoStrings(a, b) -> string
TypeFunction
DescriptionFinds a common word within two strings.
Parameters
  • a - The first string
  • b - The second string
Returns
  • The first common word that's found or nil if something goes wrong.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 661

Signaturecp.tools.firstToUpper(str) -> string
TypeFunction
DescriptionMakes the first letter of a string uppercase.
Parameters
  • str - The string you want to manipulate
Returns
  • A string
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 2182

Signaturecp.tools.getEmail() -> string
TypeFunction
DescriptionReturns the current users Email, otherwise an empty string.
Parameters
  • None
Returns
  • String
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 1313

Signaturecp.tools.getExternalDevices() -> string
TypeFunction
DescriptionReturns a string of USB & Thunderbolt Devices.
Parameters
  • None
Returns
  • String
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 1282

Signaturecp.tools.getFileExtensionFromPath(input) -> string
TypeFunction
DescriptionGets the file extension from a path.
Parameters
  • input - The path
Returns
  • A string of the file extension.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 1913

Signaturecp.tools.getFilenameFromPath(input[, removeExtension]) -> string
TypeFunction
DescriptionGets the filename component of a path.
Parameters
  • input - The path
  • removeExtension - (optional) set to true if the file extension should be removed
Returns
  • A string of the filename.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 1890

Signaturecp.tools.getFullname() -> string
TypeFunction
DescriptionReturns the current users Full Name, otherwise an empty string.
Parameters
  • None
Returns
  • String
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 1295

Signaturecp.tools.getKeysSortedByValue(tbl, sortFunction) -> table
TypeFunction
DescriptionSorts table keys by a value
Parameters
  • tbl - the table you want to sort
  • sortFunction - the function you want to use to sort the table
Returns
  • A sorted table
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 501

Signaturecp.tools.getmacOSVersion() -> string
TypeFunction
DescriptionReturns the macOS Version in the format that Apple's Feedback Form expects.
Parameters
  • None
Returns
  • The macOS version as a string or "" if unknown.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 950

Signaturecp.tools.getModelName() -> string
TypeFunction
DescriptionReturns Model Name of Hardware.
Parameters
  • None
Returns
  • String
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 743

Signaturecp.tools.getRAMSize() -> string
TypeFunction
DescriptionReturns RAM Size in a format Apple's Feedback form expects.
Parameters
  • None
Returns
  • The RAM size as a string, or "" if unknown.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 710

Signaturecp.tools.getScreenshotsAsBase64() -> table
TypeFunction
DescriptionCaptures all available screens and saves them as base64 encodes in a table.
Parameters
  • None
Returns
  • A table containing base64 images of all available screens.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 1361

Signaturecp.tools.getThunderboltDevices() -> string
TypeFunction
DescriptionReturns a string of Thunderbolt Devices.
Parameters
  • None
Returns
  • String
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 1235

Signaturecp.tools.getUSBDevices() -> string
TypeFunction
DescriptionReturns a string of USB Devices.
Parameters
  • None
Returns
  • String
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 1206

Signaturecp.tools.getVRAMSize() -> string
TypeFunction
DescriptionReturns the VRAM size in format suitable for Apple's Final Cut Pro feedback form or "" if unknown.
Parameters
  • None
Returns
  • String
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 881

Signaturecp.tools.hexStringToString(value) -> string
TypeFunction
DescriptionConverts a hex string to a string.
Parameters
  • value - The string to convert
Returns
  • A string
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 2407

Signaturecp.tools.iconFallback(paths) -> string
TypeFunction
DescriptionExcepts one or more paths to an icon, checks to see if they exist (in the order that they're given), and if none exist, returns the CommandPost icon path.
Parameters
  • paths - One or more paths to an icon
Returns
  • A string
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 2195

Signaturecp.tools.incrementFilename(value) -> string
TypeFunction
DescriptionIncrements the filename.
Parameters
  • value - A string
Returns
  • A string
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 1996

Signaturecp.tools.incrementFilenameInPath(path) -> string
TypeFunction
DescriptionIncrements the filename as it appears in a path.
Parameters
  • path - A path to a file.
Returns
  • A string
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 2015

Signaturecp.tools.isColor(object) -> boolean
TypeFunction
DescriptionIs the supplied object an hs.drawing.color?
Parameters
  • object - An object to check
Returns
  • A boolean
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 2492

Signaturecp.tools.isImage(object) -> boolean
TypeFunction
DescriptionIs the supplied object an hs.image?
Parameters
  • object - An object to check
Returns
  • A boolean
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 2479

Signaturecp.tools.isNumberString(value) -> boolean
TypeFunction
DescriptionReturns whether or not value is a number string.
Parameters
  • value - the string you want to check
Returns
  • true if value is a number string, otherwise false.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 683

Signaturecp.tools.isOffScreen(rect) -> boolean
TypeFunction
DescriptionDetermines if the given rect is off screen or not.
Parameters
  • rect - the rect you want to check
Returns
  • true if offscreen otherwise false
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 1401

Signaturecp.tools.keyStroke(modifiers, character, app, proper) -> none
TypeFunction
DescriptionGenerates and emits a single keystroke event pair for the supplied keyboard modifiers and character to the application.
Parameters
  • modifiers - A table containing the keyboard modifiers to apply ("fn", "ctrl", "alt", "cmd" or "shift")
  • character - A string containing a character to be emitted
  • app - The optional hs.application you want to target
  • proper - Use the "proper" method as per Apple's documentation (defaults to false)
Returns
  • None
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 268

Signaturecp.tools.leftClick(point[, delay, clickNumber]) -> none
TypeFunction
DescriptionPerforms a Left Mouse Click.
Parameters
  • point - A point-table containing the absolute x and y co-ordinates to move the mouse pointer to
  • delay - The optional delay between multiple mouse clicks
  • clickNumber - The optional number of times you want to perform the click.
Returns
  • None
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 1668

Signaturecp.tools.lines(string) -> table | nil
TypeFunction
DescriptionSplits a string containing multiple lines of text into a table.
Parameters
  • string - the string you want to process
Returns
  • A table or nil if the parameter is not a string.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 1538

Signaturecp.tools.lower(str) -> string
TypeFunction
DescriptionConverts the supplied string to lowercase.
Parameters
  • str - The string you want to manipulate
Returns
  • A string
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 2147

Signaturecp.tools.macOSVersion() -> string
TypeFunction
DescriptionReturns a the macOS Version as a single string.
Parameters
  • None
Returns
  • A string containing the macOS version
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 1479

Signaturecp.tools.mergeTable(target, ...) -> table
TypeFunction
DescriptionMerges multiple tables into a target table.
Parameters
  • target - The target table
  • ... - Any other tables you want to merge into target
Returns
  • Table
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 570

Signaturecp.tools.ninjaDoubleClick(point[, delay]) -> none
TypeFunction
DescriptionPerforms a mouse double click, but returns the mouse to the original position without the users knowledge.
Parameters
  • point - A point-table containing the absolute x and y co-ordinates to move the mouse pointer to
  • delay - The optional delay between multiple mouse clicks
Returns
  • None
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 1758

Signaturecp.tools.ninjaMouseAction(point, fn) -> none
TypeFunction
DescriptionMoves the mouse to a point, performs a function, then returns the mouse to the original point.
Parameters
  • point - A point-table containing the absolute x and y co-ordinates to move the mouse pointer to
  • fn - A function you want to perform
Returns
  • None
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 1776

Signaturecp.tools.ninjaMouseClick(point[, delay]) -> none
TypeFunction
DescriptionPerforms a mouse click, but returns the mouse to the original position without the users knowledge.
Parameters
  • point - A point-table containing the absolute x and y co-ordinates to move the mouse pointer to
  • delay - The optional delay between multiple mouse clicks
Returns
  • None
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 1722

Signaturecp.tools.ninjaRightMouseClick(point[, delay]) -> none
TypeFunction
DescriptionPerforms a right mouse click, but returns the mouse to the original position without the users knowledge.
Parameters
  • point - A point-table containing the absolute x and y co-ordinates to move the mouse pointer to
  • delay - The optional delay between multiple mouse clicks
Returns
  • None
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 1740

Signaturecp.tools.numberToWord(number) -> string
TypeFunction
DescriptionConverts a number to a string (i.e. 1 becomes "One").
Parameters
  • number - A whole number between 0 and 10
Returns
  • A string
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 2108

Signaturecp.tools.optionPressed() -> boolean
TypeFunction
DescriptionIs the Option Key being pressed?
Parameters
  • None
Returns
  • true if the option key is being pressed, otherwise false.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 389

Signaturecp.tools.playErrorSound() -> none
TypeFunction
DescriptionPlays the "Funk" error sound.
Parameters
  • None
Returns
  • None
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 2261

Signaturecp.tools.pressSystemKey(key) -> none
TypeFunction
DescriptionVirtually presses a system key.
Parameters
  • key - The key to use.
Returns
  • Supported key values are:
  • SOUND_UP
  • SOUND_DOWN
  • MUTE
  • BRIGHTNESS_UP
  • BRIGHTNESS_DOWN
  • CONTRAST_UP
  • CONTRAST_DOWN
  • POWER
  • LAUNCH_PANEL
  • VIDMIRROR
  • PLAY
  • EJECT
  • NEXT
  • PREVIOUS
  • FAST
  • REWIND
  • ILLUMINATION_UP
  • ILLUMINATION_DOWN
  • ILLUMINATION_TOGGLE
  • CAPS_LOCK
  • HELP
  • NUM_LOCK
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 335

Signaturecp.tools.readFromFile(path) -> string
TypeFunction
DescriptionRead data from file.
Parameters
  • path - The path of where you want to load the file.
Returns
  • None
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 423

Signaturecp.tools.removeFilenameFromPath(string) -> string
TypeFunction
DescriptionRemoves the filename from a path.
Parameters
  • string - The path
Returns
  • A string of the path without the filename.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 1929

Signaturecp.tools.removeFromTable(table, element) -> table
TypeFunction
DescriptionRemoves a string from a table of strings
Parameters
  • table - the table you want to check
  • element - the string you want to remove
Returns
  • A table
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 1870

Signaturecp.tools.replace(textValue, old, new) -> string
TypeFunction
DescriptionA find and replace feature that doesn't use patterns.
Parameters
  • textValue - The string you want to process
  • old - The string you want to find
  • new - The new string you want to replace the old string with
Returns
  • A new string
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 2445

Signaturecp.tools.rescale(value, inMin, inMax, outMin, outMax) -> number | nil
TypeFunction
DescriptionTakes an input, rescales it, and provides a new output.
Parameters
  • value - The value you want to process as a number
  • inMin - The minimum value of the input as a number
  • inMax - The maximum value of the input as a number
  • outMin - The minimum value of the output as a number
  • outMax - The maximum value of the output as a number
Returns
  • The rescaled value as a number or nil.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 479

Signaturecp.tools.rightClick(point[, delay, clickNumber]) -> none
TypeFunction
DescriptionPerforms a Right Mouse Click.
Parameters
  • point - A point-table containing the absolute x and y co-ordinates to move the mouse pointer to
  • delay - The optional delay between multiple mouse clicks
  • clickNumber - The optional number of times you want to perform the click.
Returns
  • None
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 1687

Signaturecp.tools.rmdir(path[, recursive]) -> true | nil, err
TypeFunction
DescriptionAttempts to remove the directory at the specified path, optionally removing any contents recursively.
Parameters
  • path - The absolute path to remove
  • recursive - If true, the contents of the directory will be removed first.
Returns
  • true if successful, or nil, err if there was a problem.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 2069

Signaturecp.tools.round(num, numDecimalPlaces) -> number
TypeFunction
DescriptionRounds a number to a set number of decimal places
Parameters
  • num - The number you want to round
  • numDecimalPlaces - How many numbers of decimal places (defaults to 0)
Returns
  • A rounded number
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 1386

Signaturecp.tools.safeFilename(value[, defaultValue]) -> string
TypeFunction
DescriptionReturns a Safe Filename.
Parameters
  • value - a string you want to make safe
  • defaultValue - the optional default filename to use if the value is not valid
Returns
  • A string of the safe filename
Notes
  • Returns "filename" is both value and defaultValue are nil.
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 1425

Signaturecp.tools.secureInputApplicationTitle() -> string
TypeFunction
DescriptionGets the title of the first application that has 'Secure Input' enabled.
Parameters
  • None
Returns
  • The application title or nil if secure input is not enabled or failed to get a title.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 221

Signaturecp.tools.shiftPressed() -> boolean
TypeFunction
DescriptionIs the Shift Key being pressed?
Parameters
  • None
Returns
  • true if the shift key is being pressed, otherwise false.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 371

Signaturecp.tools.spairs(t, order) -> function
TypeFunction
DescriptionA customised version of pairs, called spairs because it iterates over the table in a sorted order.
Parameters
  • t - The table to process
  • order - The function of how to sort the table.
Returns
  • A iterator function.
Notes
  • Author: Michal Kottman
  • Example Usage:
  • lua</li><li> for k,v in cp.tools.spairs(theTableToSort, function(t,a,b) return t[b] < t[a] end) do</li><li> print(k,v)</li><li> end</li><li>
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 522

Signaturecp.tools.split(str, pat) -> table
TypeFunction
DescriptionSplits a string with a pattern.
Parameters
  • str - The string to split
  • pat - The pattern
Returns
  • Table
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 632

Signaturecp.tools.splitOnColumn() -> string
TypeFunction
DescriptionSplits a string on a column.
Parameters
  • Input
Returns
  • String
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 696

Signaturecp.tools.startsWith(value, startValue) -> boolean
TypeFunction
DescriptionChecks to see if a string starts with a value.
Parameters
  • value - The value to check
  • startValue - The value to look for
Returns
  • true if value starts with the startValue, otherwise false
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 2345

Signaturecp.tools.stringMaxLength(string, maxLength[, optionalEnd]) -> string
TypeFunction
DescriptionTrims a string based on a maximum length.
Parameters
  • string - The string
  • maxLength - The length of the string as a number
  • optionalEnd - A string that is applied to the end of the input string if the input string is larger than the maximum length.
Returns
  • A string
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 1942

Signaturecp.tools.stringToHexString(value) -> string
TypeFunction
DescriptionConverts a string to a hex string.
Parameters
  • value - The string to convert
Returns
  • A hex string
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 2390

Signaturecp.tools.tableContains(table, element) -> boolean
TypeFunction
DescriptionDoes a element exist in a table?
Parameters
  • table - the table you want to check
  • element - the element you want to check for
Returns
  • Boolean
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 1815

Signaturecp.tools.tableCount(table) -> number
TypeFunction
DescriptionReturns how many items are in a table.
Parameters
  • table - The table you want to count.
Returns
  • The number of items in the table.
Notes
  • If something other than a table is supplied, this function will return 0.
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 1793

Signaturecp.tools.tableFilter(t, matchFn) -> table
TypeFunction
DescriptionEfficiently filters out all elements from the table t which to not match the matchFn.
Parameters
  • t - The table to filter.
  • matchFn - A function which will receive the table, the current index, and the target index.
Returns
  • The same table, updated.
Notes
  • This will modify the original table.
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 1838

Signaturecp.tools.tableMatch(t1, t2[, ignoreMetatable]) -> boolean
TypeFunction
DescriptionCompares two tables.
Parameters
  • t1 - The first table.
  • t2 - The second table.
  • ignoreMetatable - A boolean that determines whether or not we should ignore the metatable.
Returns
  • true if t1 and t2 are identical, otherwise false.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 2274

Signaturecp.tools.toRegionalNumber(value) -> number | nil
TypeFunction
DescriptionTakes a string and converts it into a number, with the correct regional decimal separator.
Parameters
  • value - The value you want to process as a string.
Returns
  • The value as a number or nil.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 441

Signaturecp.tools.toRegionalNumberString(value) -> string | nil
TypeFunction
DescriptionTakes a number and converts it into a string, with the correct regional decimal separator.
Parameters
  • value - The value you want to process as a number.
Returns
  • The value as a number or nil.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 460

Signaturecp.tools.trim(string) -> string
TypeFunction
DescriptionTrims the whitespaces from a string
Parameters
  • string - the string you want to trim
Returns
  • A trimmed string
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 1525

Signaturecp.tools.unescape(str) -> string
TypeFunction
DescriptionRemoves any URL encoding in the provided string.
Parameters
  • str - the string to decode
Returns
  • A string with all "+" characters converted to spaces and all percent encoded sequences converted to their ASCII equivalents.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 619

Signaturecp.tools.upper(str) -> string
TypeFunction
DescriptionConverts the supplied string to uppercase.
Parameters
  • str - The string you want to manipulate
Returns
  • A string
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 2132

Signaturecp.tools.urlQueryStringDecode() -> string
TypeFunction
DescriptionDecodes a URL Query String
Parameters
  • None
Returns
  • Decoded URL Query String as string
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 1346

Signaturecp.tools.urlToFilename(url) -> string
TypeFunction
DescriptionConverts a URL to a filename.
Parameters
  • url - The URL.
Returns
  • The filename.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 125

Signaturecp.tools.volumeFormat(path) -> string
TypeFunction
DescriptionGives you the file system volume format of a path.
Parameters
  • path - the path you want to check as a string
Returns
  • The NSURLVolumeLocalizedFormatDescriptionKey as a string, otherwise nil.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 600

Signaturecp.tools.writeToFile(path, data) -> none
TypeFunction
DescriptionWrite data to a file at a given path.
Parameters
  • path - The path to the file you want to write to.
  • data - The data to write to the file.
Returns
  • None
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/tools/init.lua line 407