Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

metadata keywords

I use Bridge to append Metadata to the Keywords field. I would like the script below to get a a total file count of the PDFs containing ONLY the keyword "correction" on selected folders & output that info to a text file.

User uploaded file

I'm having difficulties with mdfind & mdls. I have no knowledge on Terminal commands. Let's say I have a 4 folders with 200 pdfs each some of them have the keyword "correction" I want the final result on the text file be:


folder 1 CORRECTS= 50

folder 2 CORRECTS= 58

folder 3 CORRECTS= 115

folder 4 CORRECTS= 35


I'm just need the correct syntax code to make this work



set target_folder to choose folderwith prompt "Choose target folders" with multiple selections allowed without invisibles

set results to ""

repeat with i from 1 to (count target_folder)

set thisFolder to (POSIX path of itemi of target_folder)



--->>>> THIS iS THE PART I NEED HELP WITH -----<<<<

set fileCount to paragraphs of (do shell script "mdfind ' kMDItemKeywords == correction' -count") & quoted form of thisFolder

¬--& " -type f -iname *.pdf | wc -l"

set results to (results & "" & tab & "CORRECTS=" & tab & fileCount & return)


--->>>> THIS iS THE PART I NEED HELP WITH -----<<<<


end repeat

set theFilePath to (path to desktop folder as string) & "PDF correction count.txt"

set theFile to open for accessfiletheFilePath with write permission

try


set eof of theFileto 0


--write results to file theFilePath


writeresultstotheFile


close accesstheFile

on error


close accesstheFile

end try

iMac, Mac OS X (10.6.8)

Posted on Mar 26, 2015 3:24 PM

Reply
1 reply

Mar 26, 2015 5:09 PM in response to macaria

I have three PDF documents on my Desktop that each have a correction keyword in them. The following syntax will restrict the mdfind to looking only in that Desktop folder, and find the case-insensitive word "correction."


If you use wc -l after the mdfind, you will get a multiple left space padded text item. By using the count of paragraphs, this results in a a nice neat integer value.


set thisFolder to POSIX path of ((path to desktop) as text)

set results to ""


set fileCount to count of paragraphs of (do shell script ¬

"mdfind -onlyin " & quoted form of thisFolder ¬

& " -name 'kMDItemKeywords == \"correction\"cdw' *.pdf")


logfileCount

-- result: 3


set results to results & name of (info for thisFolder) & space & "CORRECTS= " & fileCount & return

-- result: Desktop CORRECTS= 3

metadata keywords

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.