Split Text
by Ian Kirkland
Description
This plugin action takes input text and splits it into multiple strings based on a user-defined delimiter or 'split point' and is useful for getting different parts of a URL, IP address, filename, extension, email address, phone number, you name it. The split point can be a character, a string, or even a Keyboard Maestro token; anything you want to use to chop text into individual parts. Each of these parts are then saved to their own dynamically-generated Keyboard Maestro variable using a user pre-defined name-prefix and an automatic 2-digit serialization. To keep things within reason, the limit is 99 per series. The naming convention uses the following scheme:
Naming Pattern
[variable name-prefix]_##
Example
"My Variable_03"
Note that this action includes three different results:
- Dynamically-generated, serialized Keyboard Maestro variables, one for each resulting 'piece' of text (limit: 99)
- Dynamically-generated Keyboard Maestro 'array' variable with named suffixed by "_all"
- Built-in results option (save to variable, save to clipboard, display in a window, etc.) that returns a Keyboard Maestro flavored 'array' (i.e. a return-delimited list) of all the resulting pieces
Parameters & Options
Input text
Your input text. This can include tokens like %CurrentClipboard%, %Variable%Foo%, %MacIPAddress%, etc.
Split text at
This is the character or string of characters (including tokens) the action will use to split your input text. For instance, splitting the word "yes" using a 'Split text at' of "e" will yield two resulting substrings: "y" and "s". Likewise, splitting the text "I-Love-Automation" using a split point of "-Love-" will give you "I" and "Automation".
Variable series prefix
As mentioned in the description section above, this field is used to define a common prefix-name for your series of result variables. Serial numbers, or 'counters' ranging from "_01" to "_99" will be automatically appended to the end of each variable name as a suffix. (e.g. "My Variable-03").
For example, if you split an IP address (e.g. 192.168.0.1) using "." as a split point and "IP_Segment" for your 'Variable series prefix', you'll end up with four appropriately-named and serialized variables; one for each of the four resulting pieces of the IP address:
Variable Name = Value
IP_Segment_01 = "192"
IP_Segment_02 = "168"
IP_Segment_03 = "0"
IP_Segment_04 = "1"
figure 1 )

figure 2 )

Although you won't see immediate feedback on the validity of your variable name, the action will parse it so that your variable names are kosher. The action also generates an 'array' variable (suffixed by "_all") that is also available through the action's built-in results dropdown menu option which is described below. Immediately below are a couple screenshots that will help explain some of this option's (and this action's) functionality.
Results
The results dropdown (located at the bottom of the action) should be familiar to most Keyboard Maestro users. It is a built-in feature for 'piping' the action's output into something else such as the clipboard, a variable, a window, etc. Rather than returning an individual substring, however, the results dropdown returns the action output as an 'array'. I use quotes here because it's not really a true array but rather a return-delimited list in string format (similar to the one you get when copying multiple objects and viewing the results in plain text). It pairs nicely with a "For Each" action that operates on lines / paragraphs.
Additional Notes
- If you come up with any creative uses for the action, please share them here in the comments
- Please report any bugs at: ianthekirkland@me.com
Download
Download Action: KM-Split_Text.zip (866.2 KB)