How to Apply a TextSoap Cleaner

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

TextSoap-KM

It doesn't work.
Please, what's missing?

Two quick suggestions for now:

  1. Try using the Copy action instead of "Type ⌘C" for the first action

  2. Don't delete the clipboard at the end; that's probably erasing the script's results

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.

1 Like

Thanks to both of you.

I refactored my macro. Now it does anything. It doesn't even copy my text.

TS-KM

I changed the last action to "Insert System clipboard by pasting".
Now it deletes my text and the clipboard ends up empty.
So discouraging!

1 Like

In the end I have created a palette with all the search-and-replace macros using the built-in regex action.
This works smoothly.

Hello,

Can you elaborate on what you mean by creating a palette? I'm trying to get Text Soap and Keyboard Maestro to work together, as well.

Thanks!

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.

33%20PM

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.

1 Like

Great!

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.

I think this is a bug in KM.

Hey @Desalegn,

@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.

The clipboard management is mostly done for you.

-Chris

1 Like

Thank you Chris for explaining.

1 Like

Hi @ccstone @gglick @pereelmagne @Ibnabouna @KevinCoates

The AppleScript syntax for TextSoap 9 has changed and the following works:

tell application "textsoapAgent"
   cleanClipboard with "Cleaner Name"
end tell

From the TextSoap web site

  • AppleScript

Previously, ApplesScripts had to specifically target each edition of the TextSoap app. With the new textsoapAgent, you just use:

tell application "textsoapAgent"
…
end tell

and drive all your text cleaning commands without worrying about which version of TextSoap 9 is doing the work.

2 Likes

Hello @tiffle
do you use TextSoap ?

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!)

1 Like

I don't know if it was like that before, but with I like the textsoapagent function a lot.

With textsoap, I can import cleaners. Would you know where is can find a library I could import.

thanks very much

Sorry @ronald no I don’t.

1 Like

OK thank you

Hey Ronald,

I'm not aware of any TextSoap community that has posted libraries.

If you haven't already ask the developer.

-Chris

1 Like

thank you Chris

1 Like