我有两个不同的处理程序,一个获取文件夹中文件夹的名称(如“1.0”和“1.1”之类的数字),然后将其转换为applescript列表。然后它将该列表传递给另一个处理程序,该处理程序评估列表并据称识别最高编号(我从http://www.macosxautomation.com/applescript/sbrt/sbrt-03.html得到它)。
on set_values(project_path)
do shell script "ls " & project_path
get words of result
set allvalues to (result)
return allvalues
end set_values
然后我将结果转换为下一个处理程序的变量:
set values_list to result
这是从列表中获得最高数字的处理程序,由macosxautomation提供:
on highnum(values_list)
set the high_amount to ""
repeat with i from 1 to the count of the values_list
set this_item to item i of the values_list
set the item_class to the class of this_item
if the item_class is in {integer, real} then
if the high_amount is "" then
set the high_amount to this_item
else if this_item is greater than the high_amount then
set the high_amount to item i of the values_list
end if
else if the item_class is list then
set the high_value to highnum(this_item)
if the the high_value is greater than the high_amount then ¬
set the high_amount to the high_value
end if
end repeat
return high_amount
end highnum
问题是第二个处理程序只发出一个空响应,我无法弄清楚原因。任何帮助表示赞赏。
应用程序的目的是简化其他应用程序的创建,允许创建新的“项目”,将现有应用程序导入新的“项目”,并允许轻松编辑“项目”。如果您选择编辑项目,您可以选择“次要更新”(有效地将“0.0.1”添加到您的最新版本)或我已经完成的许多其他选项。我可以使用文本项分隔符来解决多小数加法,但我不知道如何从highnum()处理程序中获取多十进制数,这是该过程的关键部分
答案 0 :(得分:0)
highnum()
处理程序比较real
和integer
值,但shell脚本返回string
个值。
AppleScript有一个内置选项来比较数字字符串。
修改:会考虑包含至少一个点且不包含任何字母的所有值。
on highnum(values_list)
set high_amount to "0.0"
considering numeric strings
repeat with aValue in values_list
set {TID, text item delimiters} to {text item delimiters, "."}
set aValueItems to text items of aValue
if (count aValueItems) > 1 then
set text item delimiters to ""
try
aValueItems as text as integer
if aValue > high_amount then set high_amount to contents of aValue
end try
end if
set text item delimiters to TID
end repeat
end considering
return high_amount
end highnum
这是set_values()
处理程序
on set_values(project_path)
return paragraphs of (do shell script "ls " & project_path)
end set_values
要添加可以使用此处理程序的版本字符串,它会考虑具有不同“小数位”的字符串。
set newVersionString to addVersionStrings("1.1.1", "2.0") --> 3.1.1
on addVersionStrings(string1, string2)
set {TID, text item delimiters} to {text item delimiters, "."}
set textItems1 to text items of string1
set textItems2 to text items of string2
if (count textItems1) < (count textItems2) then
set minCount to count textItems1
set _sum to textItems2
set _add to textItems1
else
set minCount to count textItems2
set _sum to textItems1
set _add to textItems2
end if
repeat with i from 1 to minCount
set item i of _sum to (get (item i of _sum as integer) + (item i of _add as integer)) as text
end repeat
set theResult to _sum as text
set text item delimiters to TID
return theResult
end addVersionStrings