2015-09-25 75 views
0

我正在为一个Alfred工作流编写脚本。但是,字符串比较永远不会评估为真。字符串比较在Alfred中永远不会评估为真

脚本内的"{query}"确实会被替换,我可以正面使用display dialog "{query}"display dialog class of "{query}"正确ctext值类型。

if "{query}" is equal to "a" then 
    say "in the a case" 
else 
    say "in the else case" 
end if 

我也曾尝试使用if "{query}" = "a" then但仍然有相同的结果。

评估一直下降到else声明。

在编写条件语句时,我指的是下面的文章。

http://computers.tutsplus.com/tutorials/if-and-if-else-applescript-conditional-statements--mac-45590

enter image description here

+0

检查“**双引号**”和“** **反斜杠”复选框来设置的AppleScript – jackjr300

+0

逃逸@ jackjr300感谢您的意见。检查转义复选框后,评估仍然是错误的。 –

回答

1

这是不正常的,这个脚本调试它,也许字符串包含有不可见字符。

set t to "{query}" 
display dialog "The ID of 'a' is " & id of "a" --> the id of a is 97 
repeat with i in t -- check the id of every character in "{query}" 
    display dialog "The ID of '" & i & "' is " & id of i 
end repeat 
if t is equal to "a" then 
    say "in the a case" 
else 
    say "in the else case" 
end if 
+0

是的,你是对的。 “{query}”中的第一个字符是一个空字符,其char代码为“32”。上面的代码对于调试是有效的。谢谢。 –