Jump to content

Find and replace in clipboard text


Stephen_C

Recommended Posts

I am the author of this workflow and the forum link is here. This is the link to the Github main page for the workflow.

 

The workflow has no dependencies. It may be used either as a Universal Action on selected text:

 

2018298971_Screenshot2022-10-13at11_08_25.thumb.png.f1be14fcde6ad8b7650ab357a2884eb8.png

or, with a user configurable keyword, on text already on the clipboard:

 

1915701921_Screenshot2022-10-13at11_08_46.thumb.png.eaa1c24a649bc1e900ea99ecd7ada2c2.png

The amended text is copied to the clipboard and may optionally be saved to a temporary file (in a user configurable location).

 

Stephen

Link to comment
Share on other sites

  • 3 months later...

I’m working on adding this, but bumped into an issue: the Universal Action does not work. You’re discarding its input in the second object (Arg & Vars) and later on always use the most recent clipboard text, so while it is possible to trigger with an Universal Action, the result is unexpected.


There are a few ways to fix that if you want to keep all functionality, but I’ll leave the choice to you. Though do ask if you need specific guidance. Personally I’d do away with the clipboard method altogether and keep just the Universal Action, because it can also act on Clipboard History. I’d also have it paste directly to the frontmost app (perhaps with a dialog asking first, since you seem to be partial to those), because it’s a great way to replace the selected text. For reference, that’s how MarkdownTransform works (it replaces the text directly) and I don’t recall anyone ever asking for it to work differently.

 

But again, specific functionality is up to you and your needs.

Link to comment
Share on other sites

Thanks for the comments, Vitor. I'll work on this over the next 24 hours or so taking account of your comments. I already have a simplified working version which uses only the Universal Action and pastes to the frontmost app but I'd like to look at it again tomorrow to see if there are any improvements I can make.

 

Stephen

Link to comment
Share on other sites

I have released version 2.0 on GitHub.

 

I have changed the name of the workflow and made substantial revisions removing the keyword and providing the ability to replace the selected text with the revised text. The Readme has been updated.

 

Note:

  1. I did include at the end an option to copy the revised text to the clipboard (in addition to the default option to overwrite the selected text). That is because I sometimes need to work with documents that are not writeable—but I still need to amend the copied text.
  2. Because of the introduction of the dialog at the end of the workflow it was necessary to ensure that the original app containing the selected text was the active app when pasting to the frontmost app (the dialog removes the focus)—hence a couple of new Automation Tasks.

Stephen

Link to comment
Share on other sites

5 hours ago, Stephen_C said:

That is because I sometimes need to work with documents that are not writeable—but I still need to amend the copied text.

 

Note that even if you can’t overwrite the text in the document, it will still be copied to your clipboard. So you may not need the extra steps. I do enjoy seeing how you’re solving problems, though. I imagine you’re significantly faster than you were in your first workflows.


I think it’s working better, but it’s still working only on the current clipboard text, instead of on the text retrieved by the Universal Action. To solve that you’d save it to a variable right after the Universal Action, then use that variable instead of {clipboard} later on.

Link to comment
Share on other sites

1 minute ago, vitor said:

I think it’s working better, but it’s still working only on the current clipboard text, instead of on the text retrieved by the Universal Action. To solve that you’d save it to a variable right after the Universal Action, then use that variable instead of {clipboard} later on.

Yes, it was silly of me to overlook that. I did notice it at one stage when developing the new workflow but then completely overlooked it <sigh>. Urgent rectification under way.

 

(Yes, things are quicker now but still making silly mistakes.)

 

Stephen

Link to comment
Share on other sites

Just now, Stephen_C said:

(Yes, things are quicker now but still making silly mistakes.)

 

The fact that you consider the mistake silly speaks volumes! I even considered not adding the longer explanation because I’m pretty sure you know what the fix is (but it may still be beneficial to spell it out for others bumping into the thread).

Link to comment
Share on other sites

One further attempt: version 2.1.

 

30 minutes ago, vitor said:

Note that even if you can’t overwrite the text in the document, it will still be copied to your clipboard. So you may not need the extra steps.

The only reasons I have retained the additional steps are:

  1. When the revised text is pasted over the original text it's marked as transient in the clipboard—simply because it didn't seem to make sense to have it in two places.
  2. You know how I like those Dialogs Conditional—and I have placed your favoured option as the default in the dialog. 😀

Stephen

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...