您可以通過在shell命令行和applescript之間使用交叉來簡化此操作。
set jpegSearch to paragraphs of (do shell script "mdfind -onlyin/'kMDItemContentType == \"public.jpeg\" '")
的mdfind命令
諮詢中央元數據存儲,並返回匹配給定的元數據查詢該文件的列表 。該查詢可以是字符串 或查詢表達式。
AFAIK這是聚光燈使用的。
mdfind文件將給你一個這個命令如何工作的想法。但部份腳本只搜索在「/」並查找內容類型的屬性,它是public.jpeg
回報是文本。匹配文件的POSIX路徑列表。這段文字就像一個文本文檔,每條路線都在一條新的線路上,但實際上有一個條目與Applescript相關。
他們需要在蘋果列表中分解。所以我通過詢問結果的段落來做到這一點。
此外,如果你想打開一個新的Finder窗口:
嘗試類似:
tell application "Finder"
activate
set myWindow to make new Finder window to startup disk
end tell
要回答爲什麼你得到你的錯誤在試圖獲得的目標的POSIX路徑文件。
如果您查看搜索窗口中返回的文件之一的屬性。
tell application "Finder" to set fileList to properties of first file of front window
你會看到該文件的屬性有一個名爲原始項目
如果你真的想這樣做,你正在做它,其中一個方法方式屬性得到原始項目。將結果強制轉換爲別名形式,然後獲取posix路徑。
tell application "Finder" to set aFile to POSIX path of (original item of first file of front window as alias)
在正常的查找器窗口中,您可以使用。
tell application "Finder" to set fileList to POSIX path of (first file of front window as alias)
這些只是示例來告訴你怎麼回事。
查找程序窗口結果類型的差異是因爲在搜索窗口中顯示的是原始文件的別名文件(類:別名文件),因此是原始項目屬性。
更新2
要經過您的項目在你的清單,檢查他們對另一名單很簡單。
蘋果有一些工具可以幫助您處理代碼。
在您的腳本中。
crtl +鼠標點擊將保存jpg結果作爲列表的變量。
這會給你一個包含幫手代碼的上下文菜單。 轉到菜單中的重複例程文件夾。
然後到它的 '處理每一個項目'
這將重複例行添加到您的代碼。
並從那裏你可以用它來檢查每個項目根據您的其他名單。
set yourOtherList to {"/Library/Desktop Pictures/Abstract/Abstract 2.jpg", "/Library/Desktop Pictures/Abstract/Abstract 1.jpg"}
set jpegSearch to paragraphs of (do shell script "mdfind -onlyin/'kMDItemContentType == \"public.jpeg\" '")
repeat with i from 1 to number of items in jpegSearch
set this_item to item i of jpegSearch
if this_item is in yourOtherList then
-- do something
log this_item
end if
end repeat
重複例程的工作原理是這樣的。
它在給定列表
每個項目將會從第1項到迭代列表中的項目數量遍歷。
i變量保存循環迭代次數。即在第一個循環中它將是1,在第300個循環中將是300。
等第一循環this_item項我jpegSearch就相當於設置爲寫設置this_item第1項jpegSearch
,但蘋果可以節省您不必編寫每個項目的每個數字與重複我 ..
變量我可以是您選擇符合正常允許變量命名語法的任何字或字母。
你可以做的事情是從匹配的項目中建立一個新的列表。通過將它們複製到先前聲明的列表中。然後,您可以在重複循環完成後在該列表上工作。
這裏bigList被聲明爲空列表{}
匹配的項目將被複制到bigList。它收到的每個新項目都被添加到列表的末尾。
set bigList to {}
set yourOtherList to {"/Library/Desktop Pictures/Abstract/Abstract 2.jpg", "/Library/Desktop Pictures/Abstract/Abstract 1.jpg"}
set jpegSearch to paragraphs of (do shell script "mdfind -onlyin/'kMDItemContentType == \"public.jpeg\" '")
repeat with i from 1 to number of items in jpegSearch
set this_item to item i of jpegSearch
if this_item is in yourOtherList then
copy this_item to end of bigList
end if
end repeat
bigList
非常感謝Mark,我可以從中獲得一些提示。 –
我已更新我的問題以更好地解釋我的意圖。這不是我最終感興趣的路徑列表,只是它是我所處階段我需要的下一個東西。道歉。 –
更新我的答案。 – markhunte