It's great to be able to record AppleScript, but it often produces semi-useless results – unless you savvy AppleScript enough to be able to rewrite the recording and pick out the good bits.
- Copy the selected text in Safari.
- Create a new BBEdit document with said text.
- Reset the size and position of the new document.
- Do one regex-based find/replace on the document.
- You can add more replace statements as needed.
Enjoy.
--------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2021/05/24 21:24
# dMod: 2021/05/24 21:29
# Appl: BBEdit
# Task: Copy Safari Table to New BBEdit Document and Find-Replace.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @BBEdit, @Table, @RegEx, @Massage, @Data
--------------------------------------------------------
set jsCmdStr to "
(() => {
return window.getSelection().toString()
})();
"
set tableContent to doJavaScriptInSafari(jsCmdStr)
tell application "BBEdit"
activate
make new text document with properties {text:tableContent}
# Resize and reposition the new document.
# {x1, y1, x2, y2} Upper-Left-Corner, Lower-Right-Corner.
set bounds of front window to {0, 45, 1314, 1196}
tell front text window's text
replace "Carbon|Helium" using "••••••" options {search mode:grep, case sensitive:false, starting at top:true}
end tell
end tell
--------------------------------------------------------
--» HANDLERS
--------------------------------------------------------
on doJavaScriptInSafari(jsCmdStr)
try
tell application "Safari" to do JavaScript jsCmdStr in front document
on error e
error "Error in handler doJavaScriptInSafari() of library NLb!" & return & return & e
end try
end doJavaScriptInSafari
--------------------------------------------------------