Ya Zhuang
Ya Zhuang

Reputation: 4660

AppleScript: how to remove all the English paragraph in the Microsoft Word for Mac?

i have a document like this:

English English English English

中文中文中文中文中文

English English English English

中文中文中文中文

the English paragraph and Chinese paragraph show up in this order one by one.

so, is there a way for me to remvoe all the English paragraphs?

i know grep and i know how to use regex and things like awk sed.. but i want to do it inside the Microsoft Word, so:

How to solve this problem by AppleScript ?

Thanks Guys!

Upvotes: 0

Views: 424

Answers (1)

adayzdone
adayzdone

Reputation: 11238

This is not very pretty, but it should get the job done.

property english : "abcdefghijklmnopqrstuvwxyz"
set deleteMe to {}

tell application "Microsoft Word"
    tell active document
        set pCount to count of paragraphs
        repeat with i from 1 to pCount
            set cCount to count of characters in characters of paragraph i
            repeat with j from 1 to cCount
                tell paragraph i
                    if content of character j is in english then
                        set end of deleteMe to i
                        exit repeat
                    end if
                end tell
            end repeat
        end repeat

        set dCount to -(count of deleteMe)
        repeat with k from -1 to dCount by -1
            set content of text object of paragraph (item k of deleteMe) to "" -- delete paragraph
        end repeat
    end tell
end tell

Upvotes: 1

Related Questions