2017-04-22 86 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 
創紀錄的每一個項目
相關問題