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






Anycount & Translation Office 3000
Translation Office 3000

Translation Office 3000 is an advanced accounting tool for freelance translators and small agencies. TO3000 easily and seamlessly integrates with the business life of professional freelance translators.

More info »
Trados Studio 2022 Freelance
The leading translation software used by over 270,000 translators.

Designed with your feedback in mind, Trados Studio 2022 delivers an unrivalled, powerful desktop and cloud solution, empowering you to work in the most efficient and cost-effective way.

More info »