Question

I am attempting to enumerate the RecentApplication > CustomListItems property-list item's array of a property-list file (.plist), but am having some difficulty with the syntax:

tell application "System Events"

  set the plist_path to "~/Library/Preferences/com.apple.recentitems.plist"
  set the plist_file to property list file plist_path

  set itemNodes to property list item "CustomListItems" of property list item "RecentApplications" of plist_file

  repeat with i from 1 to number of items in itemNodes

    set itemNode to item i of itemNodes

    display dialog text of property list item "Name" of property list item itemNode

  end repeat

end tell

I get an error that reads:

"System Events got an error: Can’t make every text of property list item \"Name\" of property list item (property list item \"CustomListItems\" of property list item \"RecentApplications\" of contents of property list file \"Macintosh HD:Users:craibuc:Library:Preferences:com.apple.recentitems.plist\") into type string." number -1700 from every text of property list item "Name" of property list item (property list item "CustomListItems" of property list item "RecentApplications" of contents of property list file "Macintosh HD:Users:craibuc:Library:Preferences:com.apple.recentitems.plist") to string

Moreover, if I change the code to:

  repeat with i from 1 to number of items in itemNodes

    display dialog i

  end repeat

I get a single dialog. In other words, it doesn't seem to be examining the array itself.

What is the correct way to capture the PLI's array?

Was it helpful?

Solution

The correct syntax is:

set itemNodes to property list items of property list item "CustomListItems" of property list item "RecentApplications" of plist_file

I needed to add 'property list items of'.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top