Within an Applescript program, I’m trying to query a property list value by an integer key. However, I can’t figure out the proper syntax.
I read the property list from ~/Library/Preferences/com.apple.symbolichotkeys.plist, whose contents look like this (based on the output of defaults read) …
I want to get the value for a given item; for example, item 11. I am trying to do it like this, but it doesn’t work …
property hotkeysPlistFile : "~/Library/Preferences/com.apple.symbolichotkeys.plist"
tell application "System Events"
set hotkeys to (value of property list item "AppleSymbolicHotKeys" of contents of property list file hotkeysPlistFile)
end tell
-- The setting of the 'hotkeys' variable works correctly.
-- However, the following does not give me the value for item 11 ...
set value11 to value of property list item 11 of hotkeys
-- Nor does this work ...
set value11 to value of item 11 of hotkeys
-- Nor do any of these ...
set value11 to value of property list item "11" of hotkeys
set value11 to value of item "11" of hotkeys
set value11 to value of property list item |11| of hotkeys
set value11 to value of item |11| of hotkeys
Can anyone point me to some docs which explain the proper syntax for retrieving a property list item in Applescript using an integer key?
The ‘value’ of property list item “AppleSymbolicHotKeys” is a record, so you need to use a property reference with that:
property hotkeysPlistFile : "~/Library/Preferences/com.apple.symbolichotkeys.plist"
tell application "System Events"
set hotkeys to (value of property list item "AppleSymbolicHotKeys" of contents of property list file hotkeysPlistFile)
end tell
set value11 to |11| of hotkeys --> {enabled:true, value:{type:"standard", parameters:{65535, 97, 262144}}}
Or with Stefan’s suggestion, you need a name reference to a property list item:
property hotkeysPlistFile : "~/Library/Preferences/com.apple.symbolichotkeys.plist"
tell application "System Events"
set hotkeys to (property list item "AppleSymbolicHotKeys" of contents of property list file hotkeysPlistFile)
set value11 to value of property list item "11" of hotkeys --> {enabled:true, value:{type:"standard", parameters:{65535, 97, 262144}}}
end tell