3 ms·
This is one of the subtleties of Applescript, but it is not a bug. See http://macscripter.net/viewtopic.php?pid=96613#p96613 http://macscripter.net/viewtopic.ph
by js2 15y ago
This is one of the subtleties of Applescript, but it is not a bug. See http://macscripter.net/viewtopic.php?pid=96613#p96613 http://macscripter.net/viewtopic.php?pid=96613#p96613 and http://developer.apple.com/library/mac/documentation/AppleScript/Conceptual/AppleScriptLangGuide/AppleScriptLanguageGuide.pdf http://developer.apple.com/library/mac/documentation/AppleSc...
Note that within the loop, the loop variable (currentWord) is a reference to an item in a list, so in the test statement (if contents of currentWord is equal to "hammer" then) it must be cast to text (as text).
So you can either use something like:
contents of theItem is "hello"
or
theItem as text is "hello"
A reduction of your example:
set hello to "hello"
set ref_hello to a reference to hello
log (ref_hello = hello) -- false
log (contents of ref_hello = hello) -- true
log (ref_hello as text = hello) -- true
A similar gotcha to Java's hashCode/equals perhaps.
- zackmorris 15y agoThanks very much for this, I've updated the post and hopefully it will help somebody in the future.
- teyc 15y agoSo is a string a value type in AppleScript?