I’m trying to write a script that checks if a number of Custom Document Properties have been set and if so, do something with the Value field, but I can’t figure how to access them in AppleScript.
Why does this give an error on the repeat line?
______________________________________________________________________
Possibly because your document has NO custom properties?
Always back up to your likely sticking point and either comment-out the subsequent code or use a return result statement to break where you want to look.
Or you can be more specific and return a specific value: return customDocProperties.
You'll see right quick that a blank document will return missing value, because it has NO custom properties.
A loop with a missing value will error.
Here are some working bits (existing properties are required):
----------------------------------------------------------------- # dNam: Microsoft Word 14.5.7 » Custom Document Properties # dMod: 2015/11/03 05:04 ----------------------------------------------------------------- tell application id "com.microsoft.Word" set myDocument to active document
tell myDocument set customDocProperties to custom document properties
if customDocProperties ≠ missing value then repeat with i in customDocProperties set {propName, propValue} to {name, value} of i end repeat
# OR
tell custom document properties set customPropNameList to name set customPropValueList to value end tell
# OR
set value of (custom document properties whose name is "Department") to "File Thirty"
else error "The front Word document has NO custom properties!" end if
end tell end tell -----------------------------------------------------------------
After quite a bit of effort and research I find no working method of CREATING or DELETING custom document properties – despite the fact that make and delete are listed in the sdef for them.
While it's certainly possible that I'm missing the correct syntax, I've tried out everything reasonable. My conclusion in the absence of other evidence is that these functions are broken.
I'm peeved that Word 2011 won't take a VB string, because VB will create these with no problem.
AppleScript can run an existing macro though, so if you need to populate custom properties you can set up one or more VB macros and call them by name.
You can then change their values with AppleScript.
|