0

Trying to learn how to use AppleScript records and lists to their upmost potential I've been trying to create a report of a BBEdit project but I'm finding very limited documentation. I asked a question yesterday trying to figure out why my find pattern wasn't working but after finding out that the issue was from me lacking returning results:true I was able to get the result record and I verified it was a record after reading Class and running:

class of findFunction

Since it says it's a record I reviewed here and ran length of findFunction and count of findFunction and they both returned 2. I was curious to know what the two items were in the record so I used return findFunction and was told there was:

found: true
found matches: list of X items

Wanting to know where and what files the matches were located in the list, I did some more searching and read Lists and records and ran:

set theMatches to get found matches of findFunction

it returned the list items and checking the new variable with get count of theMatches I am able get the quantity of items in the targeted list inside the record. When I review what's in the list (learned from: How to get a value from a list with a string in AppleScript? and Searching for items in list) I am able to conclude that when using the find in BBEdit every item in the list contains:

end_offset : 
match_string :
message :
result_file :
result_kind :
result_line :
start_offset :

Experimenting with an item I set a variable with:

set itemOne to get item 1 of theMatches

and checked to see if it worked with:

display dialog (result_file of itemOne) as text

and a dialog with the full file path was displayed. Trying to utilize DRY I created:

set filesResult to get (result_file of (get item 1 of theMatches)) as text

Wanting to add any of the mentioned above to a file with something like:

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

I recalled being able to use the clipboard and found Set clipboard to Applescript variable? so I added:

set filesResult to the clipboard
make new text document
paste

but my issue I'm running into is how can I take every item in the list found_matches and add it to the clipboard an item on each line? I thought about using a repeat but I get an error when I try:

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

With a message of:

The variable matchesItems is not defined.

So how can I get every item from the list into the clipboard with every item on it's own line so I can paste all items from the clipboard into a new file?

4

1 回答 1

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
于 2017-04-22T21:04:53.350 回答