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

  • 4 months later...

Hello Stephen.

First, I entered a word to be replaced, and pressed return. After which, I waited for the prompt to enter the replacement word, but it never shows up. Can you have a look?

Find & Replace Text v2.2
Alfred 5.1.1
Ventura 13.4.1

 

Screenshot 2023-07-09 at 4.17.56 PM.png

Edited by nartxela
Link to comment
Share on other sites

@nartxela the first thing I'd do is to check that your Automation Tasks are up to date (double click on an Automation Task in the workflow to do that—and, while you are at it, check you've set the relevant Options).

 

At present I'm not quite sure what's happening because I can't see the full debug. Maybe you could use the workflow on a shorter piece of text and then copy and paste the debug log here (rather than including the screen shot which doesn't appear to show the whole log).

 

I've just checked my own copy of the workflow (using the same versions of macOS, Alfred and the workflow as you) and it works for me.

 

Stephen

Link to comment
Share on other sites

Automation tasks are up to date with 2023.2, I have auto update checkmarked. Also, I reinstalled tasks. Then, ran the workflow once again. Here's what I have:

 

[17:42:58.439] Find and replace text[Universal Action] Processing complete
[17:42:58.443] Find and replace text[Universal Action] Passing output 'This workflow takes selected text and enables a single find and replace on elements of that text. You have the option of replacing the selected text with the revised text or simply copying the revised text to the clipboard.' to Arg and Vars
[17:42:58.443] Find and replace text[Arg and Vars] Processing complete
[17:42:58.444] Find and replace text[Arg and Vars] Passing output '' to Automation Task
[17:42:58.445] Find and replace text[Automation Task] Running task 'Identify Frontmost App' with no arguments
[17:42:58.639] Find and replace text[Automation Task] Processing complete
[17:42:58.643] Find and replace text[Automation Task] Passing output 'Safari' to Arg and Vars
[17:42:58.644] Find and replace text[Arg and Vars] Processing complete
[17:42:58.644] Find and replace text[Arg and Vars] Passing output '' to Keyword
[17:43:01.697] Find and replace text[Keyword] Processing complete
[17:43:01.701] Find and replace text[Keyword] Passing output 'option' to Arg and Vars
[17:43:01.703] Find and replace text[Arg and Vars] Processing complete
[17:43:01.705] Find and replace text[Arg and Vars] Passing output '' to Keyword

Link to comment
Share on other sites

I'm a little puzzled about what is happening, and why! The workflow seems to fail at the point it's meant to feed the original text to the Conditional ("Check for failed find”) but I don't know why (it doesn't do that for me). However, it seems a little odd that identification of the fronmost app is returning Safari (because I'd imagine it unlikely you're trying to change text in Safari—which won't work on a website, of course).

 

Please try this:

  • Open the TextEdit app and type The cat sat on the mat and ⏎.
  • Highlight the text, use your Universal Action hotkey and run the workflow.
  • At the first prompt type cat.
  • At the second prompt type elephant and ⏎.

What happens?

 

Stephen

Link to comment
Share on other sites

Hello Stephen:

I was using an app that can't be seen as a frontmost app by Alfred. However, I did have Safari opened in the background. On a different note, I'll reply sooner next time as I was expecting an email notification for any replies to the thread. As you suggested, I opened TextEdit and here's what I have:
 

[06:13:48.950] Find and replace text[Universal Action] Processing complete

[06:13:48.957] Find and replace text[Universal Action] Passing output 'The cat sat on the mat' to Arg and Vars

[06:13:48.959] Find and replace text[Arg and Vars] Processing complete

[06:13:48.960] Find and replace text[Arg and Vars] Passing output '' to Automation Task

[06:13:48.961] Find and replace text[Automation Task] Running task 'Identify Frontmost App' with no arguments

[06:13:49.151] Find and replace text[Automation Task] Processing complete

[06:13:49.154] Find and replace text[Automation Task] Passing output 'TextEdit' to Arg and Vars

[06:13:49.155] Find and replace text[Arg and Vars] Processing complete

[06:13:49.156] Find and replace text[Arg and Vars] Passing output '' to Keyword

[06:13:50.821] Find and replace text[Keyword] Processing complete

[06:13:50.826] Find and replace text[Keyword] Passing output 'cat' to Arg and Vars

[06:13:50.827] Find and replace text[Arg and Vars] Processing complete

[06:13:50.828] Find and replace text[Arg and Vars] Passing output '' to Keyword

Link to comment
Share on other sites

51 minutes ago, nartxela said:

As you suggested, I opened TextEdit and here's what I have:

I need to know exactly what happened in the TextEdit app when you followed the instructions in my previous post. Sorry, but I don't understand your response. I wasn't initially asking for the debug report (if that is indeed what you tried to give). I just wanted to know what happened in TextEdit when you ran the workflow following the exact steps I suggested.

 

Sorry if I wasn't clear in my post. What you should see in TextEdit after running the workflow is The elephant sat on the mat. What do you see?

 

Stephen

Link to comment
Share on other sites

OK - thanks. Now run that TextEdit workflow again and please copy the result of the workflow debug and paste it into a post here.

 

I'm really sorry that it's taking so long to sort this for you but I have no idea, at present, why the workflow isn't working for you. It's been quite a popular download and nobody else has reported the problem. (That's not any criticism of you but merely an indication of why I'm working in the dark! 😀)

 

Don't give up—we'll get there…eventually!

 

Edit: You might try downloading and installing the workflow again from the gallery just in case there's some problem with the one you're using now.

 

Stephen

Edited by Stephen_C
Further idea
Link to comment
Share on other sites

Stephen, no worries. I have patience for what we're doing. It's a mystery and we're hoping to resolve it. Besides, I find the workflow you've made quite useful.

I reinstalled the workflow. Ran it again in TextEdit. Entered "Elephant" and nothing happens. Here's what I have:

 

[09:58:59.531] Logging Started...

[09:59:06.297] Find and replace text[Universal Action] Processing complete

[09:59:06.304] Find and replace text[Universal Action] Passing output 'The elephant sat on the mat.' to Arg and Vars

[09:59:06.305] Find and replace text[Arg and Vars] Processing complete

[09:59:06.306] Find and replace text[Arg and Vars] Passing output '' to Automation Task

[09:59:06.306] Find and replace text[Automation Task] Running task 'Identify Frontmost App' with no arguments

[09:59:06.502] Find and replace text[Automation Task] Processing complete

[09:59:06.505] Find and replace text[Automation Task] Passing output 'TextEdit' to Arg and Vars

[09:59:06.507] Find and replace text[Arg and Vars] Processing complete

[09:59:06.507] Find and replace text[Arg and Vars] Passing output '' to Keyword

[09:59:15.166] Find and replace text[Keyword] Processing complete

[09:59:15.171] Find and replace text[Keyword] Passing output 'elephant' to Arg and Vars

[09:59:15.172] Find and replace text[Arg and Vars] Processing complete

[09:59:15.174] Find and replace text[Arg and Vars] Passing output '' to Keyword

Link to comment
Share on other sites

For some reason, it looks right on my end. Let me know if this works: plain text.

 

[10:09:14.706] Find and replace text[Universal Action] Processing complete
[10:09:14.711] Find and replace text[Universal Action] Passing output 'The elephant sat on the mat.' to Arg and Vars
[10:09:14.713] Find and replace text[Arg and Vars] Processing complete
[10:09:14.713] Find and replace text[Arg and Vars] Passing output '' to Automation Task
[10:09:14.714] Find and replace text[Automation Task] Running task 'Identify Frontmost App' with no arguments
[10:09:14.911] Find and replace text[Automation Task] Processing complete
[10:09:14.914] Find and replace text[Automation Task] Passing output 'TextEdit' to Arg and Vars
[10:09:14.915] Find and replace text[Arg and Vars] Processing complete
[10:09:14.916] Find and replace text[Arg and Vars] Passing output '' to Keyword
[10:09:18.614] Find and replace text[Keyword] Processing complete
[10:09:18.619] Find and replace text[Keyword] Passing output 'elephant' to Arg and Vars
[10:09:18.621] Find and replace text[Arg and Vars] Processing complete
[10:09:18.622] Find and replace text[Arg and Vars] Passing output '' to Keyword

Link to comment
Share on other sites

3 minutes ago, Stephen_C said:

I can't make any sense of what you have posted in your previous post, I'm afraid.

 

The text is white. If you select it, you can read it. Just barely.

 

@nartxela Tip: see the <> at the top of the text box? Click that and paste your debugger output in there. It will make it easier to read in the post. Alternatively, paste without formatting (as you just did in the previous reply).

Link to comment
Share on other sites

3 minutes ago, vitor said:

The text is white. If you select it, you can read it. Just barely.

Thank you…I'll give it a try!

 

Edit: seen the new post now.

 

Stephen

Edited by Stephen_C
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...