Pages/AppleScript: Delete (keep) paragraphs with a specific language
Thread poster: Hans Lenting
Hans Lenting
Hans Lenting
Netherlands
Member (2006)
German to Dutch
Jun 1, 2021

Task: Delete paragraphs with a specific language (in this case English paragraphs) via an AppleScript.

Demo: https://youtu.be/B1hhVJGuYNE

AppleScript:


-- https://macscripter.net/viewtopic.php?pid=206979#p206979

use AppleScr... See more
Task: Delete paragraphs with a specific language (in this case English paragraphs) via an AppleScript.

Demo: https://youtu.be/B1hhVJGuYNE

AppleScript:


-- https://macscripter.net/viewtopic.php?pid=206979#p206979

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

set theLangs to {}
tell application id "com.apple.iWork.Pages" -- Pages
tell document 1
set theParagraphs to paragraphs of body text
repeat with i from (count of theParagraphs) to 1 by -1
if length of item i of theParagraphs > 1 then
set theLanguage to (my guessLanguageOf:(item i of theParagraphs))
-- will be "en", "de", etc
if theLanguage = "en" then
delete paragraph i of body text
end if
end if
end repeat
end tell
end tell

on guessLanguageOf:theString
set theTagger to current application's NSLinguisticTagger's alloc()'s initWithTagSchemes:{current application's NSLinguisticTagSchemeLanguage} options:0
theTagger's setString:theString
set languageID to theTagger's tagAtIndex:0 |scheme|:(current application's NSLinguisticTagSchemeLanguage) tokenRange:(missing value) sentenceRange:(missing value)
return languageID as text
end guessLanguageOf:



BTW: Sometimes you want to KEEP paragraphs in a certain language, e.g. German.

Change the equals sign to the ≠ (not equal to) in:

Screenshot 2021-06-01 at 14.50.49

to filter out the German text in:

Screenshot 2021-06-01 at 14.50.26



[Edited at 2021-06-01 12:58 GMT]
Collapse


 
Hans Lenting
Hans Lenting
Netherlands
Member (2006)
German to Dutch
TOPIC STARTER
Preparing a Studio bilingual review table Jun 2, 2021

In MS Word, copy the source text column:

1

Copy the source text column to BBEdit (or any other plain text editor):

2

From BBEdit, copy to a new Pages document:

3

For best results, replace tabs with line breaks.


 


To report site rules violations or get help, contact a site moderator:


You can also contact site staff by submitting a support request »

Pages/AppleScript: Delete (keep) paragraphs with a specific language






Wordfast Pro
Translation Memory Software for Any Platform

Exclusive discount for ProZ.com users! Save over 13% when purchasing Wordfast Pro through ProZ.com. Wordfast is the world's #1 provider of platform-independent Translation Memory software. Consistently ranked the most user-friendly and highest value

Buy now! »
CafeTran Espresso
You've never met a CAT tool this clever!

Translate faster & easier, using a sophisticated CAT tool built by a translator / developer. Accept jobs from clients who use Trados, MemoQ, Wordfast & major CAT tools. Download and start using CafeTran Espresso -- for free

Buy now! »