Apply applescript to any open text document

I have created an applescript recording it from BBEDIT with this line I would like to use for other similar files:


replace "\";" using "" searching in text 1 of text document "Untitled.mer" options {starting at top:true}


instead I'd like to change it in a way I can use the whole script for any txt document I have open in BBEDIT without specifying the name of the file I work with


Maybe changing the "in text 1 of text document "Untitled.mer" with

"all open text documents" in BBEDIT


thanks kindly

Mac Pro

Posted on Mar 3, 2025 6:35 AM

Reply
4 replies
Sort By: 

Mar 3, 2025 10:14 AM in response to DanWan

Use:


tell application "BBEdit"

replace "\"\"\\n\"" using "\\n" searching in every document

replace "\";\"" using "" searching in every document options {starting at top:true}

replace "/" using "" searching in every document options {starting at top:true}

zap gremlins selection of project window 1 zap action delete_gremlin with non ASCII characters and controls

replace "\"\\n\"" using "\\n" searching in every document options {starting at top:true}

replace "." using "" searching in text 1 of every document options {starting at top:true}

replace "*" using "" searching in text 1 of every document options {starting at top:true

replace ",\"\"" using "" searching in text 1 of every document options {starting at top:true}

replace "\";" using "" searching in text 1 of every document options {starting at top:true}

replace " " using "" searching in text 1 of every document options {starting at top:true}

replace "-" using "" searching in text 1 of every document options {starting at top:true}

replace "," using "" searching in text 1 of every document options {starting at top:true}

replace "\"\"" using "" searching in text 1 of every document options {starting at top:true}

replace ":" using "" searching in text 1 of every document options {starting at top:true}

replace "\"\\n" using "\\n" searching in text 1 of every document options {starting at top:true}

replace "\"" using "" searching in text 1 of every document options {starting at top:true}

save every document

end tell


(259107)

Reply

Mar 3, 2025 8:20 AM in response to Niel

Thank you very much but, i am quite old and a real novie in Applescipt

Shall I then cgange the script as such? or I am still missing someting?

I use the "untitled.tab" code for all documents as I export them from filemaker as "untiltled.tab" then import them back into the file where I add a "serial" field I need to confront various diffeerent filemaker files.


So this will be the the proper script?


tell application "BBEdit"

activate

repeat with this_document in text documents

copy selection

open find window

paste

replace "\"\"\\n\"" using "\\n" searching in text 1 of text document "Untitled.tab" options {starting at top:true}

close find window saving no

copy selection

open find window

paste

replace "\";\"" using "" searching in text 1 of text document "Untitled.tab" options {starting at top:true}

copy selection

open find window

paste

replace "/" using "" searching in text 1 of text document "Untitled.tab" options {starting at top:true}

close find window saving no

select text 1 of project window 1

select text 1 of project window 1

zap gremlins selection of project window 1 zap action delete_gremlin with non ASCII characters and controls

select text 1 of project window 1

copy selection

open find window

paste

paste

replace "\"\\n\"" using "\\n" searching in text 1 of text document "Untitled.tab" options {starting at top:true}

replace "." using "" searching in text 1 of text document "Untitled.tab" options {starting at top:true}

replace "*" using "" searching in text 1 of text document "Untitled.tab" options {starting at top:true}

close find window saving no

open find window

close find window saving no

copy selection

find "," searching in text 1 of text document 1 with selecting match

open find window

paste

replace ",\"\"" using "" searching in text 1 of text document "Untitled.tab" options {starting at top:true}

copy selection

open find window

paste

replace "\";" using "" searching in text 1 of text document "Untitled.tab" options {starting at top:true}

replace " " using "" searching in text 1 of text document "Untitled.tab" options {starting at top:true}

replace "-" using "" searching in text 1 of text document "Untitled.tab" options {starting at top:true}

replace "," using "" searching in text 1 of text document "Untitled.tab" options {starting at top:true}

copy selection

open find window

paste

replace "\"\"" using "" searching in text 1 of text document "Untitled.tab" options {starting at top:true}

close find window saving no

open find window

replace ":" using "" searching in text 1 of text document "Untitled.tab" options {starting at top:true}

close find window saving no

copy selection

open find window

paste

replace "\"\\n" using "\\n" searching in text 1 of text document "Untitled.tab" options {starting at top:true}

close find window saving no

copy selection

open find window

paste

replace "\"" using "" searching in text 1 of text document "Untitled.tab" options {starting at top:true}

close find window saving no

save text document 1

quit

end tell

Reply

Apply applescript to any open text document

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.