Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

larrytate

macrumors newbie
Original poster
Feb 2, 2019
1
2
California
Hello All.

I'm very new to scripting in macOS. I was wondering if there is any way, either within automator or with AppleScript, to check if there is any text inside an open TextEdit document? Any ideas? It's part of a larger automation but the only aspect of it I can't seem to find. Thanks
 

superscape

macrumors 6502a
Feb 12, 2008
937
223
East Riding of Yorkshire, UK
Sure. Assuming you have a TextEdit document then:

Code:
--define the text to find
set theTextToFind to "foo"

tell application "TextEdit"
 
   --grab the contents of the frontmost document
   set theDocText to (every paragraph of front document) as text
 
   --set our dialog accoordingly
   if theDocText contains theTextToFind then
       set theDialogText to "Found it!"
   else
       set theDialogText to "Didn't find it!"
   end if

end tell

--display the dialog
display dialog theDialogText
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.