Trying to use AppleScript to find and replace text in TextEdit...
Hi all...
AppleScript newb here....
Trying to setup an applescript that will replace a few lines of code from and .htm file
This is ugly, but works:
tell application "Finder"
activate
tell application "System Events"
key down {command}
keystroke "a"
key up {command}
end tell
end tell
tell application "Finder"
activate
set fileCount to count files in front window
set fileCountAlert to fileCount
end tell
tell application "System Events"
tell process "Finder"
tell menu bar 1
tell menu bar item "File"
tell menu "File"
tell menu item "Open With"
tell menu "Open With"
click menu item "TextEdit"
end tell
end tell
end tell
end tell
end tell
end tell
delay 3
end tell
repeat until fileCount = 0
tell application "TextEdit"
activate
tell application "System Events"
key down {command}
keystroke "f"
key up {command}
--delay 1
keystroke "BORDER=1"
delay 0.5
keystroketab
keystroketab
keystroke "BORDER=0"
delay 0.5
key down {command}
keystroke "w"
key up {command}
delay 0.5
end tell
end tell
set fileCount to (fileCount - 1)
end repeat
tell application "Finder"
display dialog "Completed Adjusting " & fileCountAlert & " files."
end tell
I also tried using something like this.... but this thing didn't work at all....
set the search_document to (choose file)
replaceText("BORDER=1", "BORDER=0", search_document)
on replaceText(search_string, replacement_text, this_document)
tell application "TextEdit"
openthis_document
set AppleScript's text item delimiters to the search_string
set this_text to the text of the front document as list
set AppleScript's text item delimiters to the replacement_text
set the text of the front document to (this_text as string)
closethis_documentsavingyes
end tell
end replaceText
Lastly... I tried figuring out how to click buttons in applescript using something like this:
tell application "System Events"
tell process "TextEdit"
clickbutton "All" of scroll area of window "3.htm"
end tell
end tell
BUT - I keep getting errors here. I'm using a UIElementInspector app but no luck.
Wondering if anyone has anny quick help suggestions?