Hi,
I have a "cleaner" defined in TextSoap. It operates five regex search-and-replace actions at once.
Then I can invoke that cleaner using a simple AppleScript:
tell application "TextSoap"
cleanClipboard with "Apostrofa"
end tell
Note that I invoke "TextSoap" and not "TextSoap8", because that what's one does when using the Setapp version of the app.
My sequence of actions in KM is:
Type the ⌘C Keystroke
Pause for 0.2 Seconds
Execute AppleScript (and "save to system clipboard")
Pause for 0.2 Seconds
Delete Past Clipboard 0
I think your problem is the delete past clipboard action.
If you're doing that before you do anything with the clipboard, then you'll never see the results of the AppleScript.
So remove the last command and the results of the AppleScript will be on the clipboard.
Do you need the delete past clipboard action? Are you trying to clean the clipboard history in some way? If not, then you could just delete that action.
If you want to revert the state of the clipboard to the way it was before you ran this macro, then you need to (1) do something with the text and only then (2) delete the most recent two items on the clipboard:
i. the most recent is the result of the AppleScript which gets copied to the System Clipboard in your Execute AppleScript action;
Ii. the one before that is the text that is copied in your first action when you type the Command-C keystroke)
You could do this by adding in a paste action after the second pause, then add a second delete past clipboard 0 action.
Well, that was quick, but thank God, I figured it out.
In my case, I'm programming a Stream Deck button to automatically paste the Textsoap-cleaned text at the cursor. I think the problem was in the AppleScript syntax, because this works well.
I have no idea why the option to "Display trimmed results without errors in a window" works whereas the more intuitive "Save to System Clipboard" does not. Perhaps a bug with Keyboard Maestro? No window is being opened at this action.
I would've never been able to find such a solution. I will try to implement it in my macros involving TextSoap.
By the way, a palette in KM is just a set of macros. When you create a group of macros, you can invoke that group with a keystroke, and the result is a palette where you can have other keystrokes configured.
I am getting exactly the same result. For some reason, KM is clearing out the system clipboard after running the Applescript. That is why pasting is doing nothing.
@pereelmagne's macro has the AppleScript action explicitly set to send the result to the clipboard. The result of the script is NOT the cleaned clipboard – it is the result of the command.
TextSoap's AppleScript command cleanClipboard operates directly on the clipboard and itself returns NO RESULT. Setting the clipboard to this destroys the useful work TextSoap has already done.
Set the AppleScript action to “ignore results”.
It would also be smart to use the CLIPBOARDSEED function and pause until the clipboard changes before trying to paste.
However – a better method would be use the cleanText command and operate directly on your data source.
tell application "textsoap8"
set cleanedDataStr to cleanText dataStr with "Remove Extra Spaces"
return cleanedDataStr
end tell
With this you can use the clipboard as your data source OR a Keyboard Maestro variable and then paste the result directly from the Execute an AppleScript action.
I used to use it a lot @ronald, but never now so I was interested in your "discovery" should I need to do stuff in future. (In fact I just checked and I no longer have it installed on my Mac!)