• 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: Insert text into a document (beginners Question)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Insert text into a document (beginners Question)


  • Subject: Re: Insert text into a document (beginners Question)
  • From: Paul Berkowitz <email@hidden>
  • Date: Fri, 12 Dec 2003 13:04:14 -0800

On 12/12/03 11:54 AM, "Robert Morse" <email@hidden> wrote:

> Well, Actually I am trying to insert into XCode text document. I
> thought that
> TextEdit and Xcode would have about the same way to input
> data into the document.

!!! Have you looked at TextEdit's so-called dictionary? There's no
comparison. Xcode has a very complete dictionary, and you can do what you
want there.

>But, I am still not able to input
> anything.
>
> I tried :
>
> tell application "Xcode"
> activate
> set doc to text document 1
> tell doc
> set selection to (return & "Hello" & return)
> end tell
> end tell
>
> but it does not seem to work.

You didn't read the dictionary carefully enough.
>
> The XCode dictionary has a "selection selection-object" as a property
> of its
> text document class.

Indeed it does. 'selection' is a property of both 'text document' and of
'application' (Xcode Application suite.) And also of 'source document'. The
dictionary tells you that the class of this 'selection' property is
'selection-object'. Conveniently, that's listed in the same two suites:


Class selection-object:
Plural form:
selection-objects
Elements:
Super classes:
item
Properties:
class type class [r/o] -- (inherited from the 3item2 class) The class
of the object.
properties record -- (inherited from the 3item2 class) All of the
object's properties.
id Unicode text -- (inherited from the 3item2 class) The unique
identifier for the item.
name Unicode text -- (inherited from the 3item2 class)
script script -- (inherited from the 3item2 class) the script of the
object
contents text
character range point



See 'contents' there? Its class is text. That looks promising, so try it.
This works:


tell application "Xcode"
tell text document 1
set contents of selection to "Insert a sentence here. "
end tell
end tell


So does this:

tell application "Xcode"
set contents of selection to "Insert another sentence here. "
end tell



Pretty simple. Take care in that here the resulting sentence is itself
selected (which makes sense.) So my second command _replaces_ the first one.
I'd have to figure out how to reset the selection to just the end of the
first inserted sentence (i.e. collapse the selection) if I wanted to insert
a second sentence _after_ the first one. I'm sure that's possible.

Xcode's dictionary was evidently created by real, proper AppleScript team -
probably _the_ AppleScript team. It shares a lot with the As Studio
dictionary too. What a pleasure to see.
--
Paul Berkowitz
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Insert text into a document (beginners Question)
      • From: Paul Berkowitz <email@hidden>
References: 
 >Re: Insert text into a document (beginners Question) (From: Robert Morse <email@hidden>)

  • Prev by Date: Re: Bizarre error message
  • Next by Date: Re: try...on error...no error?
  • Previous by thread: Re: Insert text into a document (beginners Question)
  • Next by thread: Re: Insert text into a document (beginners Question)
  • Index(es):
    • Date
    • Thread