Re: Weird problem with a script?
Re: Weird problem with a script?
- Subject: Re: Weird problem with a script?
- From: Dave <email@hidden>
- Date: Tue, 15 Mar 2016 12:04:42 +0000
Hi,
> It would be more convincing as a fix if you understood why that fixed it.
I agree! I was at a customer site and just needed a quick fix which the “starts with” helped with, but you’re right, I need to understand the underlying cause. I *think* it’s because a new line character is being added to the value. Here are the missing methods:
on makeNewWordCustomDocumentPropertyWithDocumentID:(theDocumentID as string) andPropertyName:(thePropertyName as string) andPropertyValue:(thePropertyValue as string)
--say "makeNewWordCustomDocumentPropertyWithDocumentID:"
set myDocument to my getWordDocumentWithDocumentID:theDocumentID
tell application id "com.microsoft.Word"
make new custom document property at myDocument with properties {name:thePropertyName, value:thePropertyValue, type:"text"}
end tell
end makeNewWordCustomDocumentPropertyWithDocumentID:andPropertyName:andPropertyValue:
on getWordCustomDocumentPropertyWithDocumentID:(theDocumentID as string) andPropertyName:(thePropertyName as string)
--say "getWordCustomDocumentPropertyWithDocumentID:"
set myDocument to my getWordDocumentWithDocumentID:theDocumentID
tell application id "com.microsoft.Word"
set myValue to the value of (custom document properties of myDocument whose name is thePropertyName)
end tell
if myValue is not equal to missing value then
return myValue
end if
get my makeNewWordCustomDocumentPropertyWithDocumentID:(theDocumentID) andPropertyName:(thePropertyName) andPropertyValue:("*DEFAULT*")
tell application id "com.microsoft.Word"
set myValue to the value of (custom document properties of myDocument whose name is thePropertyName)
end tell
return myValue as string
end getWordCustomDocumentPropertyWithDocumentID:andPropertyName:
All the Best
Dave
> On 14 Mar 2016, at 19:44, Nigel Garvey <email@hidden> wrote:
>
> Dave wrote on Mon, 14 Mar 2016 13:39:07 +0000:
>
>> Hi All,
>>
>> I fixed it by changes the test to:
>>
>> if myCustomValue is equal to "HIGH" then
>>
>> to if myCustomValue is starts with "HIGH" then
>>
>> and that fixed it!
>
> It would be more convincing as a fix if you understood why that fixed it.
>
> The symptoms described in your previous post suggest that the code in
> the getWordCustomDocumentPropertyWithDocumentID handler, which you
> didn't post, may contain a 'repeat with someVariable in someList' repeat
> and that the handler's returning the value of the loop variable. If so,
> the value won't actually be "LOW" or "HIGH", but a reference something
> like 'item 1 of {"LOW", "HIGH"}'. In most tests — such as logging,
> seeing what it starts with, etc. — this will behave as it was one of the
> strings. But a test to see if it _is_ one of the strings will always
> return 'false' because it's actually a reference to a position in a
> list. If this is the case, returning the 'contents' of the reference
> will return the string you want.
>
> The other possibility, given your fix, is that the handler does return a
> string but that this ends with white space of some description.
>
> NG
>
> _______________________________________________
> 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
_______________________________________________
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