Well, now we understand why your updated macro didn't work. And I learned something too. I wrongly claimed earlier that a comparison between file paths would simply compare text strings. Apparently NWP is a bit smarter than that and tries to interpret abbreviated paths and relative paths too, as long as one of the two is a file path object.
But that still leaves a mystery about why your original code didn't work right. Just to quote it again:
Code: Select all
$docPath = "~/Documents/mydoc"
$actDoc = Document.active
$actDocPath = $actDoc.filePath
if ! $actDocPath = $docPath
Document.open $docPath
else
do suchandsuch
end
Now as I mentioned earlier the extension is necessary, and the comparison operator has to be '==' not '='. So I update the code to:
Code: Select all
$docPath = "~/Documents/mydoc.rtf"
$actDoc = Document.active
$actDocPath = $actDoc.filePath
if ! $actDocPath == $docPath
Document.open $docPath
else
do suchandsuch
end
And this still doesn't work!
If I change the comparison by dropping the '!' and using '!=' instead, it works fine. But what I don't understand is that if the
syntax is bad, why doesn't it throw an error? Perhaps this is a 'two-operator' violation, and NWP is evaluating the '!' before the '==', but in that case it should throw an error. Also NWP doesn't accept parentheses to disambiguate such expressions.
So, Martin, is this a bug?