Re: Sorting characters of the text - script doesn't work as expected
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: "Nigel Garvey" <email@hidden>
- Date: Sun, 28 May 2017 22:37:37 +0100
Yvan Koenig wrote on Sun, 28 May 2017 21:06:49 +0200:
>(1) the asker can't use it because - off list - I learnt that he is
>running under Lion.
There's always something they don't tell you. :D Still, it's been an
interesting exercise.
>which show that the regex splitting the documents into words doesn't
>behave like TextEdit on the asker's machine.
Although most of Ilja's code's in a TextEdit 'tell' statement, I don't
think it's TextEdit doing the counting. If I open the Russian document
in TextEdit and run this script ...
tell application "TextEdit"
count words of text of document 1 -- TextEdit counting the words in the document.
end tell
... the result is almost immediately 29244. But in Ilja's script, the text
is an AppleScript object ...
tell application "TextEdit"
set theText to text of document 1 -- Text extracted as AS text.
count words of theText -- AppleScript counting the words in the result.
end tell
... and it's this form which freezes. In the first form, 'text' and
'words' are elements of the TextEdit document and I think it's TextEdit
doing the counting. In the second form, they're elements of an
AppleScript object and AppleScript does the counting.
Exploring the issue further, this script, run against the Russian
document ...
tell application "TextEdit"
words 1 thru 25 of text of document 1
end tell
... returns:
{"Итоги", "2014", "2016", "гг", "прогноз", "до", "2019", "г", "Итоги", "2014", "2016", "гг", "прогноз", "до", "2019", "г", "Содержание", "Список", "таблиц", "и", "диаграмм", "3", "Таблицы", "3", "Диаграммы"}.
This form ...
tell application "TextEdit"
set theText to text of document 1
words 1 thru 25 of theText
end tell
... doesn't freeze, but returns:
{"", "", "", "", "", "", "", "", "Итоги", "2014", "2016", "гг", "прогноз", "до", "2019", "г", "", "", "", "", "", "Итоги", "2014", "2016", "гг"}
Those apparently "empty" words are in fact $FFFC characters being
interpreted as words. That's probably one reason why my regex script
reports a lower word count than Ilja's does. Mine also reports a lower
count than the first script above, but the reason for this isn't yet
known. Either my regex or TextEdit is interpreting something differently
...
NG
_______________________________________________
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