This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
action:Switch_or_Case [2016/03/28 08:37] AlainLifchitz add internal links + forum Google search |
action:Switch_or_Case [2016/11/27 18:15] JMichaelTX ADD example screenshot, icon, rewrite description |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | The //Switch or Case action// lets you read a string from the System Clipboard, from a Named Clipboard, from a variable, or from a file and then match it against various other strings to choose which set of actions to do. | + | {{:action:switch-icon.png?nolink|}} |
+ | ====== Switch or Case Action ====== | ||
- | The action contains a sequence of conditional segments, each of which tests the source string and then conditionally executes the corresponding set of actions. | + | **The //Switch or Case action// is used to perform different actions based on different values of a common _parameter_.** It is very similar to the [[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/switch|JavaScript Switch]] statement. |
- | The condition can test the source and see if: | + | The _Switch_ Action is a good alternative to using multiple, nested, [[action:If_Then_Else|If/Then]] Actions. |
+ | |||
+ | ---- | ||
+ | |||
+ | ===== Parameters ===== | ||
+ | |||
+ | **The Switch _parameter_ may be any of the following:** | ||
+ | * [[:Clipboards|System Clipboard]] | ||
+ | * [[:Clipboards#Named_Clipboards|Named Clipboard]] | ||
+ | * [[:Variables|Keyboard Maestro Variable]] | ||
+ | * Text (which can use [[:Tokens|Tokens]]) | ||
+ | |||
+ | ---- | ||
+ | |||
+ | |||
+ | ===== Default Configuration ===== | ||
+ | |||
+ | When you insert the _Switch_ Action, it is configured to switch based on the _System Clipboard_, but can be easily changed to other parameters. It initially looks like this: | ||
+ | |||
+ | {{:action:km-7.3-switch.png?nolink|}} | ||
+ | |||
+ | For each _Condition_ that you add, you can enter zero or more _Actions_ that will be executed when that _Condition_ is met. After those _Action(s)_ are executed, or if no _Conditions_ are met, the _Switch_ Action is exited. | ||
+ | |||
+ | ---- | ||
+ | |||
+ | |||
+ | ===== Conditions ===== | ||
+ | |||
+ | |||
+ | The _Condition_ can be and of the following: | ||
* has text of some sort. | * has text of some sort. | ||
Line 11: | Line 41: | ||
* is exactly (case insensitively) a specified string. | * is exactly (case insensitively) a specified string. | ||
* is not exactly (case insensitively) a specified string. | * is not exactly (case insensitively) a specified string. | ||
+ | * is alphabetically before a specified string. (v7.2+) | ||
+ | * is alphabetically after a specified string. (v7.2+) | ||
* contains (case insensitively) a specified string. | * contains (case insensitively) a specified string. | ||
* does not contain (case insensitively) a specified string. | * does not contain (case insensitively) a specified string. | ||
Line 19: | Line 51: | ||
* otherwise (aka always). | * otherwise (aka always). | ||
- | In all cases at most one sequence will execute, and the conditions are evaluated in order - the first one that matches will execute. So don't put an "otherwise" clause in the middle of your switch statement. | + | The _Otherwise_ _Condition_ will execute if none of the above _Conditions_ are met. The _Switch_ Action will then exit. So, the _Otherwise_ _Condition_ should always be placed as the last _Condition_ in the _Switch_ Action. |
+ | |||
+ | ---- | ||
===== See Also ===== | ===== See Also ===== |