到目前为止,我有这个:
tell application "Finder"
set number_of_items to (count (every item of the desktop))
set correct_grammar to "" as text
if number_of_items is 1 then
set number_of_items to "one" as text
end if
if number_of_items is greater than 1 then
set s_letter to "s" as text
end if
set correct_grammar to "are" as text
if number_of_items is 1 then
set correct_grammar to "is" as text
end if
if number_of_items is greater than 1 then
set correct_grammar to "are"
end if
set s_letter to "s" as text
if number_of_items is 1 then
set s_letter to "" as text
end if
tell application "System Events"
display dialog "There " & correct_grammar & " " & number_of_items & " file" & s_letter & " in this folder." buttons {"Yes", "Exit"} with title "Test"
end tell
end tell
我正在尝试显示一个对话框,显示文本“one”而不是数字值“1”一旦我这样做,脚本就会停止修复语法。下面的代码部分是导致问题发生的原因,但这是正确语法事物的全部意图。
if number_of_items is 1 then
set number_of_items to "one" as text
end if
答案 0 :(得分:0)
脚本的第二行,您必须将number_of_items强制转换为字符串:
set number_of_items to (count (every item of the desktop)) as string
并进行其他测试"如果"在(桌面的每个项目的计数)
答案 1 :(得分:0)
实际上你的代码是正确的,因为maven-war-plugin
的整数值被隐式强制转换为文本,尽管这是明确做到这一点的好习惯。
代码可以写得更短:
number_of_items
修改强>
如果您使用Yosemite及更高版本,可以使用AppleScriptObjectiveC和Cocoa的tell application "Finder" to set number_of_items to (count items of desktop)
if number_of_items is 1 then
set correct_grammar to "is"
set number_of_items to "one"
set s_letter to ""
else
set s_letter to "s"
set correct_grammar to "are"
end if
tell application "System Events"
display dialog "There " & correct_grammar & " " & (number_of_items as text) & " file" & s_letter & " in this folder." buttons {"Yes", "Exit"} with title "Test"
end tell
来创建数字字符串
NSNumberFormatter