Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enumerate a property list item array using AppleScript

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?

like image 210
craig Avatar asked Jul 22 '26 23:07

craig


1 Answers

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'.

like image 160
craig Avatar answered Jul 26 '26 04:07

craig



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!