Stephen_C Posted August 31, 2022 Share Posted August 31, 2022 With acknowledgments to @Andrew (because I used his find and replace workflow) and to @vitor (without whom there would have been no working error trapping) this is a workflow that will allow you to find and replace a word or phrase in text already on the clipboard and, optionally, copy the revised text to a text file for spellchecking. I'm unsure how useful it will be but It was created to while away a few idle hours and as a partial response to this post. Read Me Download Stephen vitor and cands 2 Link to comment
vitor Posted August 31, 2022 Share Posted August 31, 2022 You can remove the 2fr Keyword (the text, not the object), since it shouldn’t be called on its own. As for the user-configurable Keyword, a few changes are needed for it to work (right now it won’t do anything):Add a Variable name (e.g. startKeyword) under the User Configuration, as well as a Default Value (fr).In the fr Keyword object, replace the Keyword text with {var:startKeyword}.Finally—and I suggest this as an exercise if you’re interested in exploring the solution—with a Universal Action Trigger you can make this work on any text (not just the current one in the clipboard). Link to comment
Stephen_C Posted August 31, 2022 Author Share Posted August 31, 2022 Thanks: so annoyed with myself for not making the keyword configuration work properly. However, it now does and this and a couple of other workflows also containing the same aberration have all been updated on Github. Other comment (about 2fr keyword) taken on board and changed. Will look at adding a Universal Action trigger tomorrow after some sleep. In passing, how the dickens do you get in-line code highlighting in this board's editor? I have grappled and failed miserably. Stephen Link to comment
vitor Posted August 31, 2022 Share Posted August 31, 2022 (edited) 2 hours ago, Stephen_C said: so annoyed with myself for not making the keyword configuration work properly. Don’t be! It’s part of the process and you’re doing great! I like seeing what you come up with and how each Workflow gives you something else to tackle. I hope the progress is fun for you, even if sometimes it can feel frustrating. As the joke goes: “I hate programming I hate programming I hate programming It works! I love programming” 2 hours ago, Stephen_C said: how the dickens do you get in-line code highlighting in this board's editor? It’s my own configuration with MarkdownTransform. Edited August 31, 2022 by vitor Stephen_C 1 Link to comment
Stephen_C Posted September 1, 2022 Author Share Posted September 1, 2022 Updated to version 1.2: Added ability to use as Universal Action, corrected erroneous variable in temp folder configuration and updated About this workflow. Stephen cands 1 Link to comment
sepulchra Posted October 15, 2022 Share Posted October 15, 2022 (edited) hey @Stephen_C this workflow is great. I ran into one thing that might be considered an edge case. I had a ton of text where I wanted to remove a bunch of en dashes but i couldn't initially replace them with nothing because the "replace" keyword required an argument. I changed it to optional and it did the trick. I don't know if that is something you might want to update as most find and replace functions allow for the replace field to be blank. Edited October 15, 2022 by sepulchra Link to comment
Stephen_C Posted October 15, 2022 Author Share Posted October 15, 2022 @sepulchra thanks for that idea and the very clear explanation. I'll take a look at that over the next day or so. Stephen Link to comment
Stephen_C Posted October 15, 2022 Author Share Posted October 15, 2022 Done—and thanks again for the suggestion. Stephen Link to comment
sepulchra Posted October 15, 2022 Share Posted October 15, 2022 my pleasure. it is a really handy workflow! Stephen_C 1 Link to comment
TomBenz Posted October 17, 2022 Share Posted October 17, 2022 This is good. Two questions related to it: 1. Is it possible to find text using regex? 2. And also instead of replacing text, mark it in red font as an additional option? Link to comment
Stephen_C Posted October 17, 2022 Author Share Posted October 17, 2022 (edited) 18 hours ago, TomBenz said: Two questions related to it: Sorry, neither of those are possible currently and I can't at the moment envisage having the time to experiment and try to add them (even if that were a simple exercise—which I suspect it is not). Edit: do bear in mind we are dealing with plain text here so I suspect the second request is impractical. The first is probably feasible but requires more work than I currently have time to devote: sorry. Stephen Edited October 17, 2022 by Stephen_C Clarification + typo vitor 1 Link to comment
TomBenz Posted October 17, 2022 Share Posted October 17, 2022 4 hours ago, Stephen_C said: Sorry, neither of those are possible currently and I can't at the moment enviage having the time to experiment and try to add them (even if that were a simple exercise—which I suspect it is not). Edit: do bear in mind we are dealing with plain text here so I suspect the second request is impractical. The first is probably feasible but requires more work than I currently have time to devote: sorry. Stephen Ok Stephen. Thanks for your input. See the code below on item 1 and 2 and see if these make any sense. Item 1 -- this regex works but I still need to understand and test it more. I don't understand scripting additions syntax yet. use framework "Foundation" use scripting additions -------------------------------------------------------------------------------- tell application "TextEdit" set workingWin to document 1 set this_text to the text of the workingWin set input to this_text -- "The crow flies over the house." set regex to ".*-.*-.*-.*-.*" set uptext to re_match of me from the input against regex given replacement:"" set the text of the workingWin to uptext end tell -------------------------------------------------------------------------------- on re_match against pattern from str given replacement:fmt try set regex to current application's NSRegularExpression's ¬ regularExpressionWithPattern:pattern ¬ optionscurrent application's ¬ NSRegularExpressionCaseInsensitive) ¬ |error|missing value) log pattern set updatedtext to (regex's stringByReplacingMatchesInString:str ¬ options:0 range:{0, length of str} ¬ withTemplate:fmt) ¬ as text on error set updatedtext to str end try return updatedtext end re_match Item 2 -- this find specific text and mark it in red colour. tell application "TextEdit" set xword to "yep" set aRef to a reference to (every word of document 1 where it is xword) set aRef's color to {65535, 0, 0} --set aRef's contents to "" end tell Link to comment
Stephen_C Posted October 17, 2022 Author Share Posted October 17, 2022 Thanks for the ideas. However, my workflow is a fairly basic, simple workflow and I am rather inclined to keep it that way. I don't really wish to include in it some rather impenetrable AppleScript 😀 (even if I'm relatively happy with AppleScript). I also suspect there is a rather easier method of incorporating RegEx (see, for example, my Double space to single space workflow). However, that would involve creating an option at the start of this workflow (e.g., Do you wish to use RegEx?) which, to my mind, would be an irritating distraction from the simplicity of the existing workflow. Nevertheless you are, of course, most welcome to take my workflow and develop it to suit your own needs. Stephen Link to comment
TomBenz Posted October 17, 2022 Share Posted October 17, 2022 Thank you. I see if I can modify the double-space workflow and adapt it to my use case. Link to comment
Stephen_C Posted October 17, 2022 Author Share Posted October 17, 2022 3 hours ago, TomBenz said: I see if I can modify the double-space workflow and adapt it to my use case. I'd be inclined to do it the other way around: copy the Find and replace in clipboard text workflow and then pretty much all you will have to do is to the change the Replace action (annotated as Run find & replace on clipboard text in the workflow) to use RegEx replace rather than string. That, at least, is the basic alteration I think is needed. Stephen Link to comment
Stephen_C Posted November 29, 2022 Author Share Posted November 29, 2022 A minor update to the Find and replace in clipboard text workflow: a change to using the file picker in the User Configuration to select the folder for the temporary file. Stephen Link to comment
Floating.Point Posted August 28, 2023 Share Posted August 28, 2023 Hey Stephen, just FYI the links to this workflow 404 on GitHub (but I was able to find it through the link in your signature) Link to comment
Stephen_C Posted August 28, 2023 Author Share Posted August 28, 2023 Thanks for letting me know and apologies for the inconvenience. For anybody coming across this thread this is the correct link to the workflow (which is now called Find and replace text). However, it's also available on the Alfred gallery and if you download it from there you'll get the benefit of curated updates. Stephen Link to comment
Floating.Point Posted August 28, 2023 Share Posted August 28, 2023 No worries at all, thank you for the handy workflow! Stephen_C 1 Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now