Note, I’m referring to TexEdit Plus, not Text-Edit
I want to instruct a TexEdit Plus document to insert the contents of another document into it.
I check the TE+ dictionary, and I find:
insert contents‚v : Insert the contents of the given file
insert contents
of file specification : the file whose contents will be inserted
[at location specifier] : the new location for the inserted material
But then I don’t know what to do.
Is there a reason dictionary(ies) don’t use the syntax they’re defining, in an example? Seems like that would make applescript-learning more intuitive. Instead of having to pester people here with quasi-obvious questions.
Anyway, here’s my code.
(It errors with “window 1 doesn’t understand the insert message”. Yeah, yeah, great. )
set theUserFolderPath to path to home folder as string
set theFile to (theUserFolderPath & "New rrr stylesheet XTGs.txt") as alias
tell application "Tex-Edit Plus"
-- set theDoc to open theFile
tell document 1
tell window 1
insert(contents of theFile) & return
--before character 1 of paragraph 2
end tell
end tell
Just a wild guess: try
insert(get contents of theFile) & return
Now that’s odd. The two replies I posted to this (on 3rd & 4th of December) are no longer here. Fortunately, I saved them after posting:
Fri, 3 December 2010 12:50:47 pm (GMT):
The command name here is insert contents (ie. two English words separated by a space), not just insert. You mustn’t put a bracket in the middle of it. The of is a labelled parameter of the insert contents command, not part of a reference contents of theFile.
It looks as though you have to use some other operation to insert the return.
Last edited by Nigel Garvey (Sat, 4 December 2010 10:26:21 am)
Sat, 4 December 2010 10:15:41 am (GMT):
Further to my post above, this works in Tex-Edit Plus 4.9.7:
set theUserFolderPath to path to home folder as string
set theFile to (theUserFolderPath & "New rrr stylesheet XTGs.txt") as alias
tell application "Tex-Edit Plus"
tell document 1
set insertion point before paragraph 2 to return -- Make new paragraph 2.
insert contents of theFile at paragraph 2 -- Overwrite it with the file contents.
end tell
end tell
Last edited by Nigel Garvey (Sat, 4 December 2010 10:22:18 am)
Thanks for that, Nigel.
(Just noticed the email reporting the reply)
I don’t all the specifics about the ways that AppleScript support can be implemented, but my general understanding is that the dictionaries you can open in the editor are generated directly from the files (and such) that are actually used by the Apple Events system. That is, the dictionary is simply a statement of information; It is not intended to give examples.
Right, its just tempting, because it seems as if some of you guys are able to deduce proper syntax via dictionaries, but I usually just find angst.
Dictionaries are hard to fathom at first. But with a little understanding of the principles of elements and properties ” and with a little experimentation ” you soon get the hang of them.
I think those dictionaries are very clear. The purpose of a dictionary is not to give you examples at all. It must be a quick reference when you want too look the class’s properties and methods. You normally script other applications, so the manuals and examples should be found in the application’s documentation and not in the dictionary.