Hello, "consiglieri"
The first thing you need to do is learn some basic AppleScript syntax. You
can't just plunge in without knowing how AppleScript works. Even a basic
primer such as "AppleScript: The Missing Manual" (O'Reilly) would be enough
to get you going here. It's particularly important if you're going to
attempt an unorthodox and complex application dictionary such as Word's.
Word's immense dictionary is contributing to the confusion (see below), but
you're first stumbling on basic AppleScript syntax.
'document' is not a "command" - it's a class. Commands are (like) verbs,
classes are (like) nouns.
In AppleScript, every class has a number of 'properties' and, usually, some
'elements' as well. Properties are attributes: the class, and every instance
(object) of that class that you have, always has one of each property listed
in the dictionary. Elements are things that an object (an instance of the
class) might have none or any number of.) You can see from the dictionary
for 'document', as for every other class, that the dictionary (in Script
Editor 2 for Panther and Tiger) first lists ELEMENTS (if any), then
PROPERTIES.
You're running up against the fact that some applications, including Word,
also has a 'properties' property. That's nothing to do with what you're
looking for here, nothing to do with what the User Interface shows in
"Properties..." menu item in the File menu. It simply means a record of
every AppleScript property belonging to that object - all the other
properties listed for that class in the dictionary. It's just a quick way to
get a record of all of them. So if you were to get
properties of active document
you'd see a very long record of
{class:document, name:"Document1", path:"Macintosh HD:Users:your
username
ocuments", show hidden bookmarks:false, footnote options:footnote
options of active document of application "Microsoft Word", .... }
and so on, with every one of those properties and its value listed. Not what
you're looking for.
If you look among the elements for 'document' class, however, you will see
an element called 'document property'. _That's_ what you're looking for! (In
Script Editor, it's listed by its plural 'document properties' under
ELEMENTS.) It is awfully confusing that 'document property' is so similar to
'properties of document', but the AppleScript compiler will know the
difference if you use it correctly. The fact that it's an element means you
can have several different 'document property' elements of your document.
That makes sense - in the UI there are always several different
Properties... available (Title, Subject, Author, Manager, Company, Category,
Keywords, Comments, etc.) some of which are always filled by default and
some of which are empty by default if you don't fill them in (like
Comments). Just to see what your front (active) document has already, try
this:
tell application "Microsoft Word"
every document property of active document
end tell
--> {document property "Title" of active document of application "Microsoft
Word", document property "Subject" of active document of application
"Microsoft Word", document property "Author" of active document of
application "Microsoft Word", document property "Keywords" of active
document of application "Microsoft Word", document property "Comments" of
active document of application "Microsoft Word", ...}
There are actually about 20 or 30 more of them. But you can see how to deal
with them: fortunately, they are known by their name. And, at least in
English language versions of Word, the Comments are known as 'document
property "Comments"'. (Let's not get into how you'd find the right one for
other language versions at te moment, since you don't need to mess with
this.) Note that you must put "Comments" into double-quotes: it's text.
You can see from the dictionary, and from this result above, that the
element 'document property' of 'document' is itself of the class 'document
property'. So look that up in the dictionary. You can do that by clicking
the hyperlink 'document properties' in ELEMENTS for 'document'. That takes
you to:
document property n, pl document properties [inh. base object] : Every
document property
ELEMENTS
contained by documents, templates.
PROPERTIES
document property type (type class) : Returns or sets the document property
type.
link source (Unicode text) : Returns or sets the source of a lined custom
document property.
link to context (boolean) : True if the value of the document property is
lined to the content of the container document. False if the value is
static. This only applies to custom document properties. For built-in
properties this is always false.
name (Unicode text) : Returns or sets the name of the document property
value (Unicode text) : Returns or sets the value of the document property.
The name of the one you want is "Comments" (of type Unicode text, which is
why you need to put it in quotes), and the text you want to insert for it is
its value - also Unicode text, a clear sign that this is what you want to
set.
To check this out, first enter some Comments manually in the UI
(File/Properties.../Summary/Comments). If it's currently empty, enter "Try
this out", and click OK. Now, in Script Editor, try this out:
tell application "Microsoft Word"
get value of document property "Comments" of active document
end tell
-->"Try this out."
So that's it. To set the Comments by script, just set it instead of getting
it:
tell application "Microsoft Word"
set value of document property "Comments" of active document to "Change
the Comments to this text."
end tell
In the UI, go to (File/Properties.../Summary/, and you'll see the Comments
box now displays "Change the Comments to this text.", or whatever you used
in the script above.
If you want to remove comments, just do this:
tell application "Microsoft Word"
set value of document property "Comments" of active document to ""
end tell
--
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <
http://www.entourage.mvps.org/faq/index.html>
AppleScripts for Entourage: <
http://macscripter.net/scriptbuilders/>
Please "Reply To Newsgroup" to reply to this message. Emails will be
ignored.
PLEASE always state which version of Microsoft Office you are using -
**2004**, X or 2001. It's often impossible to answer your questions
otherwise.
From: consiglieri <
[email protected]>
Organization:
http://groups.google.com
Newsgroups: microsoft.public.mac.office.word
Date: 17 Aug 2006 06:13:10 -0700
Subject: Help understanding applescript dictionary for word2004
Hi
I'm trying to understand how one reads the dictionary for word2004 in
applescript .. for instance, I have been trying to do the following
insert a certain text string ib the commentary field of document
properties.
The dictionary tells me there is a command called document that
contains an element called "document properties", if I look in
"document properties" it shows the following
---
document property n, pl document properties [inh. base object] :
Every document property
elements
contained by documents, templates.
properties
document property type (type class) : Returns or sets the document
property type.
link source (Unicode text) : Returns or sets the source of a lined
custom document property.
link to context (boolean) : True if the value of the document property
is lined to the content of the container document. False if the value
is static. This only applies to custom document properties. For
built-in properties this is always false.
name (Unicode text) : Returns or sets the name of the document property
value (Unicode text) : Returns or sets the value of the document
property.
--
I really cannot get a grip on the syntax.
I have tried variations of this
tell application "Microsoft Word"
activate
set document property Comments to "stuff"
end tell
which ofcourse doesnt work
Cold someone point out how I can deduce a syntax from the dictionary?
--B_3238653437_81203524
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
X-Google-AttachSize: 11432
<HTML>
<HEAD>
<TITLE>Re: Help understanding applescript dictionary for word2004</TITLE>
</HEAD>
<BODY>
<FONT FACE="Verdana, Helvetica, Arial"><SPAN STYLE='font-size:12.0px'>Hello,
"consiglieri"<BR>
<BR>
The first thing you need to do is learn some basic AppleScript syntax. You
can't just plunge in without knowing how AppleScript works. Even a basic
primer such as "AppleScript: The Missing Manual" (O'Reilly) would
be enough to get you going here. It's particularly important if you're going
to attempt an unorthodox and complex application dictionary such as Word's.
Word's immense dictionary is contributing to the confusion (see below), but
you're first stumbling on basic AppleScript syntax.<BR>
<BR>
'document' is not a "command" - it's a class. Commands are (like)
verbs, classes are (like) nouns.<BR>
<BR>
In AppleScript, every class has a number of 'properties' and, usually, some
'elements' as well. Properties are attributes: the class, and every instance
(object) of that class that you have, always has one of each property listed
in the dictionary. Elements are things that an object (an instance of the
class) might have none or any number of.) You can see from the dictionary for
'document', as for every other class, that the dictionary (in Script Editor 2
for Panther and Tiger) first lists ELEMENTS (if any), then PROPERTIES. <BR>
<BR>
You're running up against the fact that some applications, including Word,
also has a 'properties' property. That's nothing to do with what you're
looking for here, nothing to do with what the User Interface shows in
"Properties..." menu item in the File menu. It simply means a
record of every AppleScript property belonging to that object - all the other
properties listed for that class in the dictionary. It's just a quick way to
get a record of all of them. So if you were to get<BR>
<BR>
properties of active document<BR>
<BR>
you'd see a very long record of<BR>
<BR>
{class:document, name:"Document1",
path:"Macintosh HD:Users:your username
ocuments", show hidden
bookmarks:false, footnote options:footnote options of active document of
application "Microsoft Word", .... }<BR>
<BR>
<BR>
and so on, with every one of those properties and its value listed. Not what
you're looking for. <BR>
<BR>
If you look among the elements for 'document' class, however, you will see an
element called 'document property'. _That's_ what you're looking for! (In
Script Editor, it's listed by its plural 'document properties' under
ELEMENTS.) It is awfully confusing that 'document property' is so similar to
'properties of document', but the AppleScript compiler will know the
difference if you use it correctly. The fact that it's an element means you
can have several different 'document property' elements of your document.
That makes sense - in the UI there are always several different Properties...
available (Title, Subject, Author, Manager, Company, Category, Keywords,
Comments, etc.) some of which are always filled by default and some of which
are empty by default if you don't fill them in (like Comments). Just to see
what your front (active) document has already, try this:<BR>
<BR>
<FONT COLOR="#1B08FF"><B>tell</B></FONT> <FONT
COLOR="#1B08FF">application</FONT> "Microsoft Word"<BR>
<FONT COLOR="#1B08FF"><B>every</B></FONT> <FONT
COLOR="#1B08FF">document property</FONT> <FONT
COLOR="#1B08FF"><B>of</B></FONT> <FONT COLOR="#1B08FF">active document<BR>
<B>end</B></FONT> <FONT COLOR="#1B08FF"><B>tell<BR>
</B></FONT>--> {document property "Title" of active document of
application "Microsoft Word", document property "Subject"
of active document of application "Microsoft Word", document
property "Author" of active document of application "Microsoft
Word", document property "Keywords" of active document of
application "Microsoft Word", document property
"Comments" of active document of application "Microsoft
Word", ...}<BR>
<BR>
There are actually about 20 or 30 more of them. But you can see how to deal
with them: fortunately, they are known by their name. And, at least in
English language versions of Word, the Comments are known as 'document
property "Comments"'. (Let's not get into how you'd find the right
one for other language versions at te moment, since you don't need to mess
with this.) Note that you must put "Comments" into double-quotes:
it's text. <BR>
<BR>
You can see from the dictionary, and from this result above, that the element
'document property' of 'document' is itself of the class 'document property'.
So look that up in the dictionary. You can do that by clicking the hyperlink
'document properties' in ELEMENTS for 'document'. That takes you to:<BR>
<BR>
<BR>
<B>document property</B> <I>n, pl </I><B>document properties</B> [inh. <FONT
COLOR="#1907EF"><U>base object</U></FONT>] : Every document property<BR>
<BR>
ELEMENTS<BR>
contained by <FONT COLOR="#1907EF"><U>documents</U></FONT>, <FONT
COLOR="#1907EF"><U>templates</U></FONT>.<BR>
<BR>
PROPERTIES<BR>
<B>document property type</B> (type class) : Returns or sets the document
property type.<BR>
<B>link source</B> (Unicode text) : Returns or sets the source of a lined
custom document property.<BR>
<B>link to context</B> (boolean) : True if the value of the document property
is lined to the content of the container document. False if the value is
static. This only applies to custom document properties. For built-in
properties this is always false.<BR>
<B>name</B> (Unicode text) : Returns or sets the name of the document
property<BR>
<B>value</B> (Unicode text) : Returns or sets the value of the document
property.<BR>
<BR>
<BR>
The <B>name </B>of the one you want is "Comments" (of type Unicode
text, which is why you need to put it in quotes), and the text you want to
insert for it is its <B>value </B> - also Unicode text, a clear sign that
this is what you want to set.<BR>
<BR>
<BR>
To check this out, first enter some Comments manually in the UI
(File/Properties.../Summary/Comments). If it's currently empty, enter
"Try this out", and click OK. Now, in Script Editor, try this
out:<BR>
<BR>
<FONT COLOR="#1B08FF"><B>tell</B></FONT> <FONT
COLOR="#1B08FF">application</FONT> "Microsoft Word"<BR>
<FONT COLOR="#1B08FF"><B>get</B></FONT> <FONT
COLOR="#1B08FF">value</FONT> <FONT COLOR="#1B08FF"><B>of</B></FONT> <FONT
COLOR="#1B08FF">document property</FONT> "Comments" <FONT
COLOR="#1B08FF"><B>of</B></FONT> <FONT COLOR="#1B08FF">active document<BR>
<B>end</B></FONT> <FONT COLOR="#1B08FF"><B>tell<BR>
</B></FONT>-->"Try this out."<BR>
<BR>
<BR>
So that's it. To set the Comments by script, just set it instead of getting
it:<BR>
<BR>
<FONT COLOR="#1B08FF"><B>tell</B></FONT> <FONT
COLOR="#1B08FF">application</FONT> "Microsoft Word"<BR>
<FONT COLOR="#1B08FF"><B>set</B></FONT> <FONT
COLOR="#1B08FF">value</FONT> <FONT COLOR="#1B08FF"><B>of</B></FONT> <FONT
COLOR="#1B08FF">document property</FONT> "Comments" <FONT
COLOR="#1B08FF"><B>of</B></FONT> <FONT COLOR="#1B08FF">active document</FONT>
<FONT COLOR="#1B08FF"><B>to</B></FONT> "Change the Comments to this
text."<BR>
<FONT COLOR="#1B08FF"><B>end</B></FONT> <FONT COLOR="#1B08FF"><B>tell<BR>
</B></FONT><BR>
<BR>
In the UI, go to (File/Properties.../Summary/, and you'll see the Comments
box now displays "Change the Comments to this text.", or whatever
you used in the script above.<BR>
<BR>
If you want to remove comments, just do this:<BR>
<BR>
<FONT COLOR="#1B08FF"><B>tell</B></FONT> <FONT
COLOR="#1B08FF">application</FONT> "Microsoft Word"<BR>
<FONT COLOR="#1B08FF"><B>set</B></FONT> <FONT
COLOR="#1B08FF">value</FONT> <FONT COLOR="#1B08FF"><B>of</B></FONT> <FONT
COLOR="#1B08FF">document property</FONT> "Comments" <FONT
COLOR="#1B08FF"><B>of</B></FONT> <FONT COLOR="#1B08FF">active document</FONT>
<FONT COLOR="#1B08FF"><B>to</B></FONT> ""<BR>
<FONT COLOR="#1B08FF"><B>end</B></FONT> <FONT COLOR="#1B08FF"><B>tell<BR>
</B></FONT><BR>
<BR>
-- <BR>
Paul Berkowitz<BR>
MVP MacOffice<BR>
Entourage FAQ Page: <a
href="
http://www.entourage.mvps.org/faq/index.html"><
http://www.entourage.
mvps.org/faq/index.html></a><BR>
AppleScripts for Entourage: <a
href="
http://macscripter.net/scriptbuilders/"><
http://macscripter.net/scri
ptbuilders/></a> <BR>
<BR>
Please "Reply To Newsgroup" to reply to this message. Emails will
be ignored.<BR>
<BR>
PLEASE always state which version of Microsoft Office you are using -
**2004**, X or 2001. It's often impossible to answer your questions
otherwise.<BR>
<BR>
<BR>
<FONT COLOR="#0000FF">> From: consiglieri <
[email protected]><BR>
> Organization: <a
href="
http://groups.google.com">
http://groups.google.com</a><BR>
> Newsgroups: microsoft.public.mac.office.word<BR>
> Date: 17 Aug 2006 06:13:10 -0700<BR>
> Subject: Help understanding applescript dictionary for word2004<BR>
> <BR>
> Hi<BR>
> <BR>
> I'm trying to understand how one reads the dictionary for word2004
in<BR>
> applescript .. for instance, I have been trying to do the following<BR>
> <BR>
> insert a certain text string ib the commentary field of document<BR>
> properties.<BR>
> <BR>
> The dictionary tells me there is a command called document that<BR>
> contains an element called "document properties", if I look
in<BR>
> "document properties" it shows the following<BR>
> ---<BR>
> document property n, pl document properties [inh. base object] :<BR>
> Every document property<BR>
> elements<BR>
> contained by documents, templates.<BR>
> properties<BR>
> document property type (type class) : Returns or sets the document<BR>
> property type.<BR>
> link source (Unicode text) : Returns or sets the source of a lined<BR>
> custom document property.<BR>
> link to context (boolean) : True if the value of the document
property<BR>
> is lined to the content of the container document. False if the
value<BR>
> is static. This only applies to custom document properties. For<BR>
> built-in properties this is always false.<BR>
> name (Unicode text) : Returns or sets the name of the document
property<BR>
> value (Unicode text) : Returns or sets the value of the document<BR>
> property.<BR>
> --<BR>
> <BR>
> I really cannot get a grip on the syntax.<BR>
> <BR>
> I have tried variations of this<BR>
> <BR>
> tell application "Microsoft Word"<BR>
> activate<BR>
> set document property Comments to "stuff"<BR>
> end tell<BR>
> <BR>
> which ofcourse doesnt work<BR>
> <BR>
> Cold someone point out how I can deduce a syntax from the
dictionary?<BR>
> <BR>
</FONT></SPAN></FONT>
</BODY>
</HTML>
--B_3238653437_81203524--