Re-save file with last selected item using Prompt with List moved to the top

Hello,

Supposed I have a file Fruits.txt that contains:
Apple
Banana
Cherry
Durian
Elderberry

I would like to use Prompt with List action with Fruits.txt. So if I select Elderberry, then Fruits.txt would be re-saved to become:
Elderberry
Apple
Banana
Cherry
Durian

If I run the macro again and selects Cherry, then the Fruits.txt would be re-saved again to become:
Cherry
Elderberry
Apple
Banana
Durian

Any help is much appreciated,
ChrisQ

There are no doubt many ways to do this. Here is a way that uses Keyboard Maestro native Actions. It works with the list you provided. The example has the list in a local variable. To adapt it to a saved file you would need to read and write the local variable to a file.

The logic is to search the list for the chosen line and remove it from the list, then to put the chosen line at the head of the list.

EXAMPLE Reorder List.kmmacros (4.2 KB)

Click to Show Image of Macro

1 Like

Thank you so much @Zabobon. You made it look so easy. :slight_smile: