• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Sorting characters of the text - script doesn't work as expected
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sorting characters of the text - script doesn't work as expected


  • Subject: Re: Sorting characters of the text - script doesn't work as expected
  • From: Yvan KOENIG <email@hidden>
  • Date: Sun, 16 Apr 2017 16:00:24 +0200

A single instruction was the wrongdoer.
Here is the script after some cleaning.

tell application "TextEdit"
activate
set p2d to path to desktop as text
set theFile to p2d & "fakeGreek.txt"
set theDoc to open file theFile
set MyDoc to text of theDoc


--set visible of window 1 to false --optional


set theParagraphs to paragraphs of MyDoc
set GreekCharacterSet to {"α", "β", "γ", "δ", "ε", "ζ", "η", "θ", "ι", "κ", "λ", "μ", "ν", "ξ", "ό", "о", "π", "ρ", "ς", "Ύ", "φ", "χ", "ψ", "ω"}
set GreekYes to {} --Greek characters of the text go there
set GreekNo to {} --Non-Greek characters of the text go there


repeat with i from 1 to (count theParagraphs) --1st loop. Selects every paragraph of the text of the document.
set ParagraphCharacters to text items of paragraph i of MyDoc
repeat with item_ref in GreekCharacterSet --2nd loop. Compares every characters of GreekCharacterSet to every characters of selected paragraph of the text of the document
set itemref to item_ref as text
if itemref is in ParagraphCharacters then
repeat with j from 1 to (count ParagraphCharacters)
if itemref = item j of ParagraphCharacters then
set end of GreekYes to itemref
--set GreekCharactersCount to (count GreekYes)
else
set maybe to item j of ParagraphCharacters as text
if maybe is not in {" ", "(", ")", "-", "+", "=", "|", "{", "}", "°", "[", "]", "^", "/", "\\", "·", "$", "€", "‡", "±", "*", "<", ">", "≥", "≤", "≠", ":", ";", ".", ",", "⁄", "‹", "›", "—", "_", "?", "!", "«", "»", "", linefeed, "1", "2", "3", "4", "5", "6", "7", "8", "9", "0"} then
if maybe is not in GreekNo then set end of GreekNo to maybe --contents of item j of ParagraphCharacters --GreekNo --variable which then is counted.


--set NonGreekCharactersCount to (count GreekNo)
end if
end if
end repeat
end if #  contents of item_ref 
end repeat
end repeat
end tell

{GreekYes, count GreekYes, linefeed, GreekNo, count GreekNo}



Yvan KOENIG running Sierra 10.12.4 in French (VALLAURIS, France) dimanche 16 avril 2017 16:00:19



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Sorting characters of the text - script doesn't work as expected
      • From: Yvan KOENIG <email@hidden>
References: 
 >Sorting characters of the text - script doesn't work as expected (From: ILJA SHEBALIN <email@hidden>)

  • Prev by Date: Re: Sorting characters of the text - script doesn't work as expected
  • Next by Date: Re: Sorting characters of the text - script doesn't work as expected
  • Previous by thread: Re: Sorting characters of the text - script doesn't work as expected
  • Next by thread: Re: Sorting characters of the text - script doesn't work as expected
  • Index(es):
    • Date
    • Thread