【发布时间】:2017-04-24 01:00:16
【问题描述】:
尝试学习如何最大限度地利用 AppleScript 记录和列表我一直在尝试创建 BBEdit 项目的报告,但我发现文档非常有限。我问了一个问题yesterday 试图弄清楚为什么我的查找模式不起作用,但在发现问题出在我缺少returning results:true 之后,我能够获得结果记录,并在阅读后验证它是一个记录Class 并运行:
class of findFunction
因为它说这是一条记录,所以我查看了 here 并运行了 length of findFunction 和 count of findFunction,它们都返回了 2。我很想知道这两个项目在记录中是什么,所以我使用了 return findFunction 并且是告诉有:
found: true
found matches: list of X items
想知道匹配项在列表中的位置和文件,我进行了更多搜索并阅读了Lists and records 并运行:
set theMatches to get found matches of findFunction
它返回列表项并使用get count of theMatches 检查新变量我能够获得记录内目标列表中的项目数量。当我查看列表中的内容时(学习自:How to get a value from a list with a string in AppleScript? 和 Searching for items in list),我可以得出结论,在 BBEdit 中使用 find 时,列表中的每个项目都包含:
end_offset :
match_string :
message :
result_file :
result_kind :
result_line :
start_offset :
用我设置变量的项目进行实验:
set itemOne to get item 1 of theMatches
并检查它是否适用于:
display dialog (result_file of itemOne) as text
并显示带有完整文件路径的对话框。尝试利用我创建的 DRY:
set filesResult to get (result_file of (get item 1 of theMatches)) as text
想要将上述任何内容添加到文件中,例如:
set filesResult to get (result_file of (get item 1 of theMatches)) as text
set theMessage to get (message of (get item 1 of theMatches)) as text
set combined to filesResult & ":" & theMessage
我记得能够使用剪贴板并找到Set clipboard to Applescript variable?所以我添加了:
set filesResult to the clipboard
make new text document
paste
但我遇到的问题是如何获取列表found_matches 中的每个项目并将其添加到剪贴板中每一行的项目?我考虑过使用repeat,但尝试时出现错误:
repeat with x from 1 to (length of matchesItems)
set filesResult to get (result_file of (get item x of theMatches)) as text
set theMessage to get (message of (get item x of theMatches)) as text
set combined to filesResult & ":" & theMessage
end repeat
带有以下信息:
变量matchesItems没有定义。
那么我怎样才能将列表中的每个项目都放入剪贴板中,并且每个项目都在它自己的行中,以便我可以将剪贴板中的所有项目粘贴到一个新文件中?
【问题讨论】:
标签: list applescript record repeat bbedit