試圖學習如何使用AppleScript記錄和列表到他們最高的潛力我一直在試圖創建一個BBEdit項目的報告,但我發現非常有限的文檔。我問了一個問題yesterday試圖找出爲什麼我的查找模式不起作用,但發現問題來自我缺乏returning results:true
我能夠獲得結果記錄,並且在讀取Class並運行後驗證它是記錄:如何將一個AppleScript列表變成一個字符串
class of findFunction
因爲它說,這是我回顧here跑length of findFunction
和count 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。
所以,我怎樣才能從列表中的每一項與它自己的行每一個項目剪貼板上,這樣我可以從剪貼板粘貼所有項目到一個新文件?