Actions
An action takes text in, runs a script, and puts text back. Here is the contract, the input sources, and the whole language.
Clink for iOSThe contract
An action defines transform(text). Whatever it returns is turned into text and inserted where you are writing.
def transform(text):
return text.upper()Where the text comes from
| Input | What the action gets |
|---|---|
| Nothing | Generates text from scratch. transform(""). |
| Current word | Passes the word you're typing into transform(text). |
| Selection | Passes the text you have selected, or nothing when there is no selection. |
| Current line | Passes the line the cursor is on. |
| Current sentence | Passes the sentence the cursor is in. |
| Text before cursor | Passes everything before the cursor in. |
| Text after cursor | Passes everything after the cursor in. |
| Whole field | Passes the whole field in, on both sides of the cursor. |
| Clipboard | Passes the clipboard text in. Needs Full Access. |
Replace input decides whether the output takes the place of what went in. It applies to every source that reads the field. Nothing and Clipboard have nothing in the document to replace, so their output is always inserted.
def transform(text):
words = len(text.split())
return f"{words} words"Asking the keyboard
An action can use the same commands a panel does, instead of returning one string. That is how an action makes more than one edit, or leaves the cursor somewhere particular.
def transform(text):
replace(len(text), "(" + text + ")")
move_cursor(-1)The language
Scripts use PyMini, a subset of Python with comprehensions, lambdas, tuples, sets, f-string formats, try and except. Unsupported syntax produces an error that names the line.
Types
intfloatstrboolNonelisttupledictset
Keywords
ifelifelsewhileforindefreturnbreakcontinuepassTrueFalseNoneandornotlambdatryexceptfinallyraiseimportfromasisdelglobal
Builtins
lenstrreprprintintfloatboolabsroundminmaxsumrangesortedreversedlistdictsettupleenumeratezipordchranyalltypemapfilterdivmodpowhexbinoctformatisinstancecallable
String methods
upperlowercasefoldtitlecapitalizeswapcasestriplstriprstripreplacesplitrsplitsplitlinesjoinstartswithendswithfindrfindindexrindexcountpartitionrpartitionzfillljustrjustcenterisdigitisnumericisalphaisalnumisspaceisupperisloweristitleremoveprefixremovesuffixformat
List methods
appendextendpopinsertremoveindexcountsortreverseclearcopy
Dictionary methods
keysvaluesitemsgetpoppopitemsetdefaultupdateclearcopy
Set methods
adddiscardremovepopclearcopyupdateunionintersectiondifferencesymmetric_differenceissubsetissupersetisdisjoint
Tuple methods
countindex
Regex match methods
groupgroupsgroupdictstartendspan
Exceptions
ExceptionValueErrorTypeErrorKeyErrorIndexErrorNameErrorZeroDivisionErrorAttributeErrorRuntimeErrorStopIteration
Refused
classwithnonlocalassertyieldasyncawaitmatch
Namespaces
These namespaces can be imported, and nothing else. Each one only computes: there is no filesystem, no network and no process for a script to reach.
import json
dumpsloads
import math
acosasinatanatan2ceilcombcopysigncosdegreeseexpfabsfactorialfloorfmodgcdhypotinfisfiniteisinfisnanlcmloglog10log2nanpipowprodradianssinsqrttantautrunc
import random
choicechoicesrandintrandomrandrangesampleseedshuffleuniform
import re
DOTALLIIGNORECASEMMULTILINESescapefindallfinditerfullmatchmatchsearchsplitsubsubn
import sys
version
import time
formatmonotonicpartstime
import re
def transform(text):
return re.sub(r"\s+", " ", text).strip()