Last active
January 10, 2022 16:32
-
-
Save benwaldie/6227266 to your computer and use it in GitHub Desktop.
Find and replace text in an opened TextEdit document using AppleScript.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Find and replace a single word in an opened TextEdit document | |
tell application "TextEdit" | |
make new document | |
-- Add some text to the document | |
set text of front document to "The quick fox jumped over the lazy dog." | |
-- Find and replace | |
set every word of front document where it = "fox" to "elephant" | |
end tell | |
-- Find and replace a phrase in a TextEdit document | |
tell application "TextEdit" | |
make new document | |
-- Add some text to the document | |
set text of front document to "The quick fox jumped over the lazy dog." | |
-- Find and replace | |
set text of front document to replace_chars(text of front document, "quick fox", "slow elephant") of me | |
end tell | |
on replace_chars(this_text, search_string, replacement_string) | |
set AppleScript's text item delimiters to the search_string | |
set the item_list to every text item of this_text | |
set AppleScript's text item delimiters to the replacement_string | |
set this_text to the item_list as string | |
set AppleScript's text item delimiters to "" | |
return this_text | |
end replace_chars |
First, you can probably do this in Finder without writing a script. Select the files and choose File > Rename.
If you do want to do this with a script, I suggest taking a look at some of the chapters about working with files/folders and text in the Mac Automation Scripting Guide.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you, can you tell me, but how to add a word at the end of the name, wherever there is a .bin format
eg red_1.bin but need red_1_low.bin