Use Case
- You have a list of items, one per line, that contain duplicate items
- You need a unique list of items
As I mentioned in the Replacing Duplicates Using RegEx topic, this can easily be done using JavaScript. I said it could be done in one line, but actually it takes 4 lines of code unique to this script:
//--- YOUR CODE HERE ---
var sourceStr = kmeApp.getvariable("Local__SourceStr", {instance: kmInst});
var sourceList = sourceStr.split('\n');
var uniqueList = [... new Set(sourceList)];
scriptResults = uniqueList.join('\n');
All I had to do is enter those 4 lines in my JXA script template (which you should have if you write even a little bit of JXA scripts).
I hope you find this helpful.
MACRO: Remove Dup Items in List [Example]
-~~~ VER: 1.0 2021-06-11 ~~~
Requires: KM 8.2.4+ macOS 10.11 (El Capitan)+
(Macro was written & tested using KM 9.0+ on macOS 10.14.5 (Mojave))
DOWNLOAD Macro File:
Remove Dup Items in List [Example].kmmacros
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.
ReleaseNotes
Author.@JMichaelTX
PURPOSE:
-
Remove Dup Items in List [Example]
- Make use of the JavaScript Set function
HOW TO USE
- First, make sure you have followed instructions in the Macro Setup below.
- See the below "How to Use" Comment Action
- This macro is just an example written in response to a user's request. You will need to use as an example and/or change to meet your workflow automation needs.
MACRO SETUP
-
Carefully review the Release Notes and the Macro Actions
- Make sure you understand what the Macro will do.
- You are responsible for running the Macro, not me. ??
.
Make These Changes to this Macro
- Assign a Trigger to this Macro .
- Move this macro to a Macro Group that is only Active when you need this Macro.
- ENABLE this Macro, and the Macro Group it is in.
- For more info, see KM Wiki article on Macro Activation
.
- For more info, see KM Wiki article on Macro Activation
-
REVIEW/CHANGE THE FOLLOWING MACRO ACTIONS:
(all shown in the magenta color)- SET Source String
- List of Items (one per line) thata contains dups
- SET Source String
REQUIRES:
- KM 9.0+ (may work in KM 8.2+ in some cases)
- macOS 10.12.6 (Sierra)+
TAGS: @Example @JavaScript @JXA @Dups @Lists @Set