Re: Pages and Applescript
Re: Pages and Applescript
- Subject: Re: Pages and Applescript
- From: Axel Luttgens <email@hidden>
- Date: Sun, 4 Apr 2010 11:03:02 +0200
Le 2 avr. 2010 à 19:30:16, Yvan KOENIG a écrit :
> Hello
>
> I'm a bit annoyed with Pages.
>
> If the selection is made of two different strings of text,
>
> I may grab several useful infos with this trick :
>
> tell application "Pages" to tell document 1
> set theSel to get the selection
> try
> theSel * 1
> on error errmsg
> log errmsg
> end try
> end tell
>
> which return this log :
>
> [...]
>
> or
>
> [...]
>
> or
>
> tell application "Pages"
> get selection of document 1
> {text from character 26 to character 27 of object text of text box 1 of foreground layer of page 2 of document id 5462874, text from character 32 to character 33 of object text of text box 1 of foreground layer of page 2 of document id 5462874}
> (*Impossible de transformer {text from character 26 to character 27 of object text of text box 1 of foreground layer of page 2 of document id 5462874 of application "Pages", text from character 32 to character 33 of object text of text box 1 of foreground layer of page 2 of document id 5462874 of application "Pages"} en type number.*)
> end tell
>
> which may be easily deciphered with a bit of trickery.
>
> Alas, when the selection is a single chunck of text, if grabbing the properties of the selection, I may know
> that it sits in a given page
> that it starts at character offset x (in a container which is not reported)
> that it contains contents
> and
> that it's length is, what a surprise, length of the contents.
>
> But I found no way to grab the infos about the container which may be :
> body text of
> or
> object text of shape x of foreground layer of
> or
> object text of text box y of foreground layer of
>
> At least from my point of view, the problem is that when the selection is a single object,
> get selection doesn't return a selection's descriptor but the selection's contents, and get a reference to the selection behaves the same.
>
> I think that a logical behaviour would be:
>
> get the selection returns a description
> and
> get contents of the selection returns … the contents
>
> which is the real behaviour when several objects are selected.
>
> I wish to know your advice before filing a bug report.
Hello Yvan,
I think this is more a matter of AppleScript's usual evaluation rules, amongst them:
"AppleScript supports coercion of a single-item list to any class to which
the item can be coerced if it is not part of a list." (ASLG 2.0, p. 93)
As a result, when the selection is a single item list, the "*" operator will try to evaluate the item itself in the hope to end with a number.
So, in order to still get the "meaningful" error message even when the selection contains a single object, one may for instance ask for some silly property instead of applying a too invasive operator:
templates of (get selection)
(the "get" is needed here, so as to avoid to ask the selection object itself)
Note that there's an added advantage: an error is raised even if the selected text happens to be a valid numeric string. ;-)
That said, it's amazing that one has to decipher error messages in order to know the containing piece of the selection. That's possibly the bug...
HTH,
Axel
_______________________________________________
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