Another of my scripts, one that renames podcast downloads for me, had got to a fair old length and as I'd originally intended my most used to be at the top of the list, it'd grown a bit anarchically. So I thought I should sort it alphabetically, did, and the whole thing's easier to use.
But my sort was via an external editor, and I found myself wondering if I should write a script that I could use to re-sort the text of my list without having to leave the Toolbox's internal editor.
I'm not sure that it's the most elegant script in the world -- that's Paul's domain -- but this seems to do the job, tied to a hotkey, and I've used it in a couple of other places too and
(Start)
HOW TO USE: Copy from Start to End, and then paste into an action.
REFERENCE : See an example of pasting at alomware.com/paste.png
0001 Clipboard: Clear all content ""
0002 Keyboard: Cut ""
0003 Action: Abort if no clipboard text ""
0004 String: Assign from clipboard text ""
0005 String: Make alphabetical ""
0006 Clipboard: Assign text "string$"
0007 Keyboard: Type to active window "{z250}"
0008 Keyboard: Paste ""
(End)
Line 7 is the main tweak, dealt with a problem that not having it caused for one of the editors I tested in.
Use it by highlighting the lines of text you want to sort, then invoking it via whatever hotkey you've chosen.
Line 1 empties the clipboard; line 2 issues a Cut command for the current highlighted text, line 3 throws an error if there's no text in the clipboard, line 4 assigns the clipboard to a string variable that line 5 sorts alphabetically, line 6 plugs the result back into the clipboard, line 7 just waits a quarter of a second, and line 8 pastes the newly sorted clipboard back into your application.
I have a suspicion that different use cases might need different tweaks but this seems to work fairly well. Although I think I've discovered that if there's no enter at the end of the final line, that line will be lost...
Hi oblivion,
The only real optimisation for this is just combining steps 7 and 8 into one line, like this:
(Start)
HOW TO USE: Copy from Start to End, and then paste into an action.
REFERENCE : See an example of pasting at alomware.com/paste.png
0001 Clipboard: Clear all content ""
0002 Keyboard: Cut ""
0003 Action: Abort if no clipboard text ""
0004 String: Assign from clipboard text ""
0005 String: Make alphabetical ""
0006 Clipboard: Assign text "string$"
0007 Keyboard: Type to active window "{z250}{ctrldown}v"
(End)
I see what you mean by the missing "Enter" at the end of the final line. Seems to be a bug. I'm onto it.
The bug for the missing final line with "String: Make alphabetical" is now fixed for today's forthcoming v7.0.0.5 release. :)
Fix confirmed here. BTW, the update check is much better now, too. It doesn't get in the way too much and I'm not getting any errors like it used to. Just thought you might like to know.