User Tools

Site Tools


token:Variable

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revision Both sides next revision
token:Variable [2015/12/13 05:43]
JMichaelTX Add link to Insert Text action
token:Variable [2023/07/10 02:36]
peternlewis
Line 1: Line 1:
-{{:​token:​variable-icon.png |}}===== Keyboard Maestro Variables ===== +{{:​token:​variable-icon.png |}} 
-==== Variable ​Tokens ====+The //%Variable%//​`<​VariableName>​`% token allows you to include a [[manual:​Variables|variable]] in a [[:Text Fields |token text field]], where `<​VariableName>​` is the name of the variable.  ​
  
-The //​%Variable%//​ token allows you to include a variable in a token text field. ​ For Example, 
  
-[[action:​Insert_Text|Insert Text]]: ​Sally said “Hello” to %Variable%First Name%.+For Example, using the [[action:​Insert_Text|Insert Text]] ​Action:
  
-You can also use a short form of just //%Variable Name%// to include variables as long as the variable exists and has a value and there is no corresponding text token, although generally it is better and clearer to use the longer form //​%Variable%Variable Name%//.+{{ :token:​km-wiki-insert-text-action.png?nolink |}}
  
-==== Variable Arrays ​====+You can (v7.2+) access a variable as if it is a comma separated array of text using the notation //%Variable%//​`<​VariableName>​[3]`% where 3 can be any [[manual:​Calculations|Calculation]]. ​ You can use a different item separator by putting the text between the ] and % characters, eg //​%Variable%//​`<​VariableName>​[3]:​`%.  ​Arrays ​are indexed starting from 1, and index 0 will give the count of the number of items, negative indices will index from the end of the array.
  
-Variables ​can contain an array of comma separated **numbers**,​ like the image size (123,456) or window frame (100,​120,​600,​550). In calculation fieldyou can refer to these using a normal (1-based) index notation, like Variable[2]. So you can use ClipboardImageSize[1] ​and ClipboardImageSize[2]. +You can also use a short form of just //%Variable Name%// to include variables as long as the variable exists and has value and there is no corresponding text tokenalthough generally it is better ​and clearer ​to use the longer form //%Variable%Variable Name%//.
- +
-**It is important ​to note that variable arrays can contain only numeric values**. ​ When you use the [[token:​Calculate|%Calculate%]] function to reference a variable array element, it will convert the element to a number. ​ So, in effect, you can only use variable arrays to store/reference numbers.+
  
-For example, suppose the variable `MyArray` has this value: ​ `10,​05,​00,​12` +===== See Also =====
-In any Keyboard Maestro Action where you would like to use the array element `%Calculate%MyArray[2]`,​ it will return "​5"​ because it has evaluated it as number, not the actual string of the element "​05"​.+
  
 +- [[:Text Fields]]
 +- [[:Tokens]]
 +- [[manual:​Variables]]
token/Variable.txt · Last modified: 2023/09/12 23:50 by peternlewis