Seb
Seb

Reputation: 545

AppleScript : get all the values of a specified key in a plist file

I'm looking for a way to get ALL the values for a specified key in a plist file. Indeed, I want to go through the plist file and every time I read the specified key, I put the value in an array for example.

Thanks a lot :)

Upvotes: 1

Views: 1025

Answers (2)

adayzdone
adayzdone

Reputation: 11238

You can try to access the values with sed. Assuming:

enter image description here

set keyValues to paragraphs of (do shell script "sed -En '/CFBundleIconFile/ {
n
s/.*>([^<]+).*/\\1/
p
}' < " & quoted form of "/Users/John/Desktop/Info.plist")

Upvotes: 1

tompaman
tompaman

Reputation: 104

I'm not sure I understand you fully, but here's an example on how to read all the IODisplayLocation values from the windowserver preferences and create an applescript array.

set oldDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to ";"
set theItems to (do shell script "defaults read /Library/Preferences/com.apple.windowserver | grep IODisplayLocation | awk '{print $3}'")
set itemList to (every text item of theItems) as list
set AppleScript's text item delimiters to oldDelimiters
display dialog item 4 of itemList

Upvotes: 1

Related Questions