Re: TextEdit oddity
Re: TextEdit oddity
- Subject: Re: TextEdit oddity
- From: Deivy Petrescu <email@hidden>
- Date: Tue, 20 May 2014 08:59:50 -0400
After Shane’s first email, I decided to run some tests here.
I thought that the problem was due to the fact that TextEdit was “copying” the text while you were trying to edit it.
Well, to create a large text edit file I copied the text of your file many times over and pasted it to a TextEdit file.
I used this script to do it:
——————————————————————————————————————————————————
set t to "Hello\n\nI'm cleaning 20755 text files.\nPart of the operation is done by a script and I finish the cleaning by hand.\n\nAs the real script make changes to the text, a bare version is :\n\ntell application \"TextEdit\" to tell document 1\n\tset leTexte to its text\n\t\n\tset its text to (leTexte & \"=azertyuiop=\")\n\t\n\tdelay 0.1\n\tset properties of its text to {font:\"Menlo-Regular\", size:11.0}\n\t\nend tell\n\nFor most of the texts, all works well.\n\nI just get a problem with large files.\nFor instance, I have one text containing 141831 characters (including space ones) the script fails\nand the Events log display :\n\n\nset properties of every text of document 1 to {font:\"Menlo-Regular\", size:11.0}\n\t\t--> error number -10000\n\n\nAfter that I can't select something in the document's window and I am forced to quit TextEdit and reopen the document which happily is correctly saved.\n\nMy first guess was that TextEdit was not ready to apply the changes.\nSo, for see, I splitted the script in two.\npart 1 :\n\ntell application \"TextEdit\" to tell document 1\n\tset leTexte to its text\n\t\n\tset its text to (leTexte & \"=azertyuiop=\")\n\t\nend tell\n\n\npart 2 :\n\ntell application \"TextEdit\" to tell document 1\n\t\n\tset properties of its text to {font:\"Menlo-Regular\", size:11.0}\n\t\nend tell\n\nAs I waited quite one minute before applying part 2 I thought that all would behave well because applying the changes by hand worked well.\nWrong guess, part 2 ended with the same error message.\nGiven that, at this time I'm using a piece of GUIscripting which behave well but I'm not satisfied by that.\n\ntell application \"TextEdit\"\n\tactivate\n\ttell document 1\n\t\tset leTexte to its text\n\t\t\n\t\tset its text to (leTexte & \"=azertyuiop=\")\n\t\t\n\tend tell\nend tell\ntell application \"System Events\" to tell process \"TextEdit\"\n\tkeystroke \"t\" using {command down, shift down} # switch to RTF\n\ttell menu bar 1 to tell menu bar item 5 to tell menu 1\n\t\trepeat\n\t\t\t# wait until the
set z to t
repeat 6 times
set z to z & z
end repeat
tell application "TextEdit"
activate
if not (exists document 1) then make new document at front
set text of document 1 to z
--set properties of text of document 1 to {font:"Verdana Italic", size:14.0}
end tell
——————————————————————————————————————————————————
I had the same problem you and Shane reported.
I wanted to find out the size of the file that the problem would start and then created another script to cut the file size and apply the styling.
It turns out that if the original file is larger than a certain size it will not work.
For instance try the script above with the script below and even thought the new size is really small, it will not work.
——————————————————————————————————————————————————
tell application "TextEdit"
activate
tell document 1
set t to its text
set its text to (text 1 thru 400 of t)
set properties of its text to {font:"Verdana Italic", size:14.0}
end tell
end tell
——————————————————————————————————————————————————
So, if the file is large enough to begin with, even if you trim it, you will have problems styling it.
Note that the size is really small.
If you change the 6 by 4 in the first script the second script will work fine.
On May 20, 2014, at 03:08 , koenig.yvan <email@hidden> wrote:
>
> Le 20/05/2014 à 02:37, Shane Stanley <email@hidden> a écrit :
>
>> On 20 May 2014, at 12:37 am, koenig.yvan <email@hidden> wrote:
>>
>>> a bare version is :
>>>
>>> tell application "TextEdit" to tell document 1
>>> set leTexte to its text
>>>
>>> set its text to (leTexte & "=azertyuiop=")
>>>
>>> delay 0.1
>>> set properties of its text to {font:"Menlo-Regular", size:11.0}
>>>
>>> end tell
>>>
>>> For most of the texts, all works well.
>>>
>>> I just get a problem with large files.
>>> For instance, I have one text containing 141831 characters (including space ones) the script fails
>>> and the Events log display :
>>>
>>>
>>> set properties of every text of document 1 to {font:"Menlo-Regular", size:11.0}
>>> --> error number -10000
>>>
>>>
>>> After that I can't select something in the document's window and I am forced to quit TextEdit and reopen the document which happily is correctly saved.
>>>
>>> Am’I doing something wrong or am’I facing a bug ?
>>
>> It looks like you're facing a bug. It often gives me a TextEdit crash/continue dialog:
>>
>> Exception Name: NSInternalInconsistencyException
>> Description: -[NSLayoutManager _fillGlyphHoleForCharacterRange:startGlyphIndex:desiredNumberOfCharacters:] *** attempted glyph generation while textStorage is editing. It is not valid to cause the layoutManager to do glyph generation while the textStorage is editing (ie the textStorage has been sent a beginEditing message without a matching endEditing.)
>> User Info: (null)
>>
>> And I can see in Console entries like:
>>
>> 20/05/2014 10:13:22.696 am TextEdit[10164]: An exception was thrown during execution of an NSScriptCommand...
>> 20/05/2014 10:13:22.696 am TextEdit[10164]: *** -[NSConcreteTextStorage attribute:atIndex:effectiveRange:]: Range or index out of bounds
>> 20/05/2014 10:13:29.750 am TextEdit[10164]: -[NSLayoutManager _fillGlyphHoleForCharacterRange:startGlyphIndex:desiredNumberOfCharacters:] *** attempted glyph generation while textStorage is editing. It is not valid to cause the layoutManager to do glyph generation while the textStorage is editing (ie the textStorage has been sent a beginEditing message without a matching endEditing.)
>>
>> Given that it's happening when you're trying to replace the contents of the document, and given that TextEdit pretty much relies on built-in support for this sort of scripting, there may well be the same problem in other apps. So you should definitely report it.
>>
>
>
> Thanks Shane
>
> Now I am even more puzzled.
>
> Before asking here I looked in the Console and didn't got the relevant messages which you reproduce.
>
> I just saw MANY messages like :
> 19/05/2014 22:07:46,000 kernel[0]: TextEdit[25398] Unable to quarantine: 93
>
> and some others like :
> 19/05/2014 22:18:33,331 TextEdit[25398]: view service marshal for <NSRemoteView: 0x7fadb78834d0> failed to forget accessibility connection due to Error Domain=NSCocoaErrorDomain Code=4099 "Impossible de communiquer avec un utilitaire." (The connection was invalidated from this process.) UserInfo=0x7fadb3e713e0 {NSDebugDescription=The connection was invalidated from this process.}
> timestamp: 22:18:33.331 Monday 19 May 2014
> process/thread/queue: TextEdit (25398) / 0x10cc9a000 / com.apple.NSXPCConnection.user.endpoint
> code: line 2972 of /SourceCache/ViewBridge/ViewBridge-46.2/NSRemoteView.m in __57-[NSRemoteView viewServiceMarshalProxy:withErrorHandler:]_block_invoke
> domain: communications-failure
>
> which doesn't seem to be related to what I face.
>
> I will clean the crash reports and make a new attempt to be check if the crash and the message are related.
>
> Yvan KOENIG (VALLAURIS, France) mardi 20 mai 2014 09:08:25
>
>
>
>
> _______________________________________________
> 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
Deivy Petrescu
email@hidden
_______________________________________________
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