2017-04-22 60 views
0

试图学习如何使用AppleScript记录和列表到他们最高的潜力我一直在试图创建一个BBEdit项目的报告,但我发现非常有限的文档。我问了一个问题yesterday试图找出为什么我的查找模式不起作用,但发现问题来自我缺乏returning results:true我能够获得结果记录,并且在读取Class并运行后验证它是记录:如何将一个AppleScript列表变成一个字符串

class of findFunction 

因为它说,这是我回顾herelength of findFunctioncount of findFunction记录,他们都回来。我很好奇,想知道这两个项目都在记录,所以我用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 

,并与完整的文件路径W的对话如显示。试图利用干我创建:

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。

所以,我怎样才能从列表中的每一项与它自己的行每一个项目剪贴板上,这样我可以从剪贴板粘贴所有项目到一个新文件?

回答

2

为了澄清措词

theList = {A,B,C} -- this is a list with 3 variables 
theRecord = {A:something, B:somethingElse, C:somethingElseTwo} -- this is a record. 

列表可以通过其索引来解决。

theList's item 1 -- A 

的记录可以通过它的键来解决

A of theRecord -- something 

为了得到一个列表的所有项目都放到一个字符串按索引重复它(说每个产品类型的文本)

set finalString to "" 
repeat with thisItem in TheList 
    set finalString to finalString & thisItem & return -- the return creates a new line 
end repeat 

然后你有finalString做任何你喜欢的事情。

为了得到你要知道它的键(如果它不是一个ASOC的NSDictionary)

set finalString to "" 
set finalString to finalString & A of theRecord & return; 
-- repeat last line with every key 
创纪录的每一个项目
相关问题