Readonly constantThe constant property is a container for pre-defined constants.
Readonly KEY_Key code for the Delete (⌫) key.
Readonly KEY_Key code for the Down Arrow key.
Readonly KEY_Key code for the Escape key.
Readonly KEY_Key code for the Left Arrow key.
Readonly KEY_Key code for the Return (↵) key.
Readonly KEY_Key code for the Right Arrow key.
Readonly KEY_Key code for the space bar.
Readonly KEY_Key code for the Tab (⇥) key.
Readonly KEY_Key code for the Up Arrow key.
Readonly MODIFIER_Bit mask for the Command (⌘) key.
Readonly MODIFIER_Bit mask for the Control (⌃) key.
Readonly MODIFIER_Bit mask for the Option (⌥) key.
Readonly MODIFIER_Bit mask for the Shift (⇧) key.
Get information about the current locale as configures in macOS settings.
Get information about the current time zone as configured in macOS settings.
Decode a Base-64 string and interpret the result as a UTF-8 string.
Accepts both standard and URL-safe variants as input. Also accepts input with or without the =/== end padding.
Throws an error if the input cannot be decoded as a UTF-8 string.
The decoded string
Encode a string as UTF-8 then Base-64 encode the result.
The string to encode.
Optional options: { Optional trimmed?: booleanWhether to trim the =/== padding from the string. Default is no.
Optional urlWhether to encode using the URL-safe variant, with - and _ substituted for + and /. Default is no.
Whether the text contains no misspellings, checked in the given language.
The language must be a code from getSpellingLanguages; any other value throws, so intersect a saved option value with the available list before passing it — a saved language can go stale.
The text to check.
language: the spell checker language code to check in.
Decipher a JSON object that has been lightly obscured to prevent constants such as API client identifiers appearing in plaintext in the source files.
This function will ROT13 decipher the text, apply Base64 decoding, and parse the result as JSON.
The definition of this text from macOS's Dictionary Services, as plain text, or
undefined if the text has no definition.
To open the text in the Dictionary app instead of reading its definition, use
popclip.openUrl with a dict:// URL.
The text to define.
Fill the provided TypedArray with cryptographically secure random values.
This aims work like crypto.getRandomValues() from Web Crypto API.
Internally, it is implemented using Apple's SecRandomCopyBytes.
The array to fill with random values. This will be modified in place.
const array = new Uint8Array(16); // array of 16 bytes
util.getRandomValues(array); // array is now filled with random bytes
Replacement guesses for a misspelled word, in the given language. Guesses are returned only when the whole text is a single misspelled word — a sentence containing a misspelling is not a candidate for replacement, so it yields an empty array, as do correctly-spelled words and misspellings or non-words that the checker has no suggestions for.
The same language rule as checkSpelling applies.
The text to get guesses for.
language: the spell checker language code; limit: cap the number of
guesses returned (omit for all).
Optional limit?: numberThe languages the system spell checker can check on this Mac, as objects pairing the spell
checker's language code (for example "en", "de", "pt_BR") with a display name
localized for the user's locale. Suitable for building a language option's values and
valueLabels.
Whether macOS's Dictionary Services has a definition for this text — that is, whether the text as a whole is a term in one of the dictionaries the user has enabled.
The text to look up.
if (util.hasDictionaryDefinition(popclip.input.text)) { ... }
Generate hash-based message authentication code (HMAC) using the supplied data, key and algorithm. Implemented internally by Apple's CommonCrypto.
Localize an English string into the current user interface language, if possible. This will work for strings which match the name of a built-in action.
The string to localize.
The localized string, or the original string if no localized version was avaiable.
This is only used by the Paste and Enter and Paste and Match Style extensions to localise their displayed action titles and is not recommended for general use.
Generate a random integer in range [0, max] with uniform distribution using a cryptographically secure random source.
Maximum value to generate. Supplied value will be coerced to a 32-bit unsigned integer.
const coinFlip = util.randomUniform(1); // coinFlip has value 0 or 1
const dieRoll = util.randomUniform(5) + 1; // dieRoll has value from 1 to 6
A container for various utility functions and constants util object.