AppleScript从列表中选择对象类型的选择
我很久没碰AppleScript了,所以这可能是我做的不对。我通过收集路径中倒数第二个文本项创建了一个列表。路径将如下所示:AppleScript从列表中选择对象类型的选择,applescript,Applescript,我很久没碰AppleScript了,所以这可能是我做的不对。我通过收集路径中倒数第二个文本项创建了一个列表。路径将如下所示: set myFile to choose from list archiveFileNames with prompt "Select An Archive" -->return class of myFile repeat with i from 1 to count of every item of archiveFileNames
set myFile to choose from list archiveFileNames with prompt "Select An Archive"
-->return class of myFile
repeat with i from 1 to count of every item of archiveFileNames
if (myFile is equal to (item i of archiveFileNames as string)) then
log myFile & "::" & item i of archiveFileNames & "::" & i
end if
end repeat
高清:用户:xxxxxxxx:库:开发者:Xcode:档案:2017-06-14:focus 6-14-17AM 8.03。Xcode:档案:
因此,列表中填充了如下字符串:focus 6-14-17,8.03 AM.xcsarchive
然后,我向用户演示并要求他们选择一个存档。我有另一个包含所有存档路径的列表。我希望做的是获取所选存档,在存档名称列表中找到它的索引,然后从存档路径列表中提取路径。至少我认为这相当简单。代码的相关部分像这样的书:
set myFile to choose from list archiveFileNames with prompt "Select An Archive"
-->return class of myFile
repeat with i from 1 to count of every item of archiveFileNames
if (myFile is equal to (item i of archiveFileNames as string)) then
log myFile & "::" & item i of archiveFileNames & "::" & i
end if
end repeat
我从未找到匹配项,即使我只是在存档名称列表中重复并使用日志语句,我也可以得到我想要的结果:
log myFile & "::" & item i of archiveFileNames & "::" & i
(参见比赛的最后结果)
因此,我认为这一定是一个类/类型问题,因为我在比较苹果和橙子,所以不存在相等性。当我运行它并取消注释myFile的-->返回类时,我从列表中选择的类就是一个列表
显然我做错了什么。我希望类型是字符串,可能是文本,而不是列表。帮帮我,欧比万,你是我唯一的希望!:D
编辑:好,如果我将条件更改为:
如果(myFile等于(archiveFileNames的项目i为列表),则
我得到了预期的结果。但我仍然不明白为什么从字符串列表中选择的对象的类型是列表。尝试使用附加组件更改类型
as text
因此,与其进行比较
if A is B
对于不同的类,这可能会失败-对文本进行强制
if (A as text) is (B as text)
此外,这里还有一个处理程序,用于获取列表中的项目位置
on list_position(this_item, this_list)
repeat with i from 1 to the count of this_list
if ((item i of this_list) as text) is (this_item as text) then return i
end repeat
return 0
end list_position
编辑:要澄清列表问题,请说明如何创建列表尝试使用附加模块更改类型
as text
因此,与其进行比较
if A is B
对于不同的类,这可能会失败-对文本进行强制
if (A as text) is (B as text)
此外,这里还有一个处理程序,用于获取列表中的项目位置
on list_position(this_item, this_list)
repeat with i from 1 to the count of this_list
if ((item i of this_list) as text) is (this_item as text) then return i
end repeat
return 0
end list_position
编辑:为了澄清您的列表问题,请说明您是如何创建列表的问题发生的原因是
choose from List
始终返回对象的列表(或布尔false
,如果用户按取消)
你得把名单弄平
set myFile to choose from list archiveFileNames with prompt "Select An Archive"
if myFile is false then return
set myFile to item 1 of myFile
repeat with i from 1 to count of every item of archiveFileNames
set currentItem to item i of archiveFileNames
if myFile = currentItem then
log myFile & "::" & currentItem & "::" & i
end if
end repeat
出现此问题的原因是
choose from list
始终返回对象的列表(如果用户按取消,则返回布尔值false
)
你得把名单弄平
set myFile to choose from list archiveFileNames with prompt "Select An Archive"
if myFile is false then return
set myFile to item 1 of myFile
repeat with i from 1 to count of every item of archiveFileNames
set currentItem to item i of archiveFileNames
if myFile = currentItem then
log myFile & "::" & currentItem & "::" & i
end if
end repeat
一直都是这样的,我不记得以前必须这样做,但我做任何硬核应用程序已经有6年了。一直都是这样的。一直都是这样的,我不记得过去必须这样做,但我做任何硬核应用程序已经有6年了。一直都是这样的.这里绝对是赢家.这里绝对是赢家。