Mac plist search an array

(imported topic written by pdentremont91)

Hi Guys,

I’m having some trouble getting my logic right on searching an array in a plist. In Particular I need to set relevance for the keychain menu item. Path /Users/$user/Library/Preferences/com.apple.systemuiserver.plist menuExtras and search the array for value /Applications/Utilities/Keychain Access.app/Contents/Resources/Keychain.menu.

I’m pretty new to macs so if someone has an easier way to check relevance on this that would be great as well.

Thanks,

Peter

(imported comment written by pdentremont91)

I Figured out this solution and thought I would post the solution for anyone else looking for a similar problem.

exists strings whose (it contains “/Applications/Utilities/Keychain Access.app/Contents/Resources/Keychain.menu”) of values of array “menuExtras” of dictionary of file “com.apple.systemuiserver.plist” of folder (pathname of users folder & “/” & name of current user & “/Library/Preferences”)

Thanks,

Peter d’Entremont

(imported comment written by NoahSalzman)

Very nice. Welcome to the joys of plist dictionaries.

One trivial suggestion:

(pathname of current user folder & “/Library/Preferences”)

rather than

(pathname of users folder & “/” & name of current user & “/Library/Preferences”)

(imported comment written by pdentremont91)

Hi Guys,

I’m having trouble getting access to deeper nested entries in a plist. Specifically com.apple.dock.plist. All i need to do is delete Microsoft Communicator from the dock programatically. At this point i’m just trying to locate the entry and then will attempt to store it’s array index number so I can target it for removal. I’m having trouble searching for a string in a a dictionary which is in a dictionary in an array. It definately shouldn’t be this hard to remove an icon from the dock.

exists strings whose (it contains “Microsoft Communicator”) of values of array “persistent-apps” of dictionary of file “com.apple.dock.plist” of folder (pathname of users folder & “/” & name of current user & “/Library/Preferences”)

Thanks,

Peter d’Entremont

(imported comment written by NoahSalzman)

What about installing dockutil?

http://dockutil.googlecode.com/files/dockutil_v1.zip

roquefort:Desktop noah$ ./dockutil -h

usage: dockutil -h

usage: dockutil --add |

–label

folder_options

position_options

plist_location_specification

usage: dockutil --remove

plist_location_specification

usage: dockutil --move position_options

plist_location_specification

usage: dockutil --find

plist_location_specification

usage: dockutil --list

plist_location_specification

position_options:

–replacing replaces the item with the given dock label or adds the item to the end if item to replace is not found

–position [ index_number | beginning | end | middle ] inserts the item at a fixed position: can be an position by index number or keyword

–after inserts the item immediately after the given dock label or at the end if the item is not found

–before inserts the item immediately before the given dock label or at the end if the item is not found

–section

others

specifies whether the item should be added to the apps or others section

plist_location_specifications:

default is the dock plist for current user

–allhomes attempts to locate all home directories and perform the operation on each of them

–homeloc overrides the default /Users location for home directories

folder_options:

–view [grid|fan|list|automatic] stack view option

–display

stack

how to display a folder’s icon

–sort [name|dateadded|datemodified|datecreated|kind] sets sorting option for a folder view

Examples:

The following adds TextEdit.app to the end of the current user’s dock:

dockutil --add /Applications/TextEdit.app

The following replaces Time Machine with TextEdit.app in the current user’s dock:

dockutil --add /Applications/TextEdit.app --replacing ‘Time Machine’

The following adds TextEdit.app after the item Time Machine in every user’s dock on that machine:

dockutil --add /Applications/TextEdit.app --after ‘Time Machine’ --allhomes

The following adds ~/Downloads as a grid stack displayed as a folder for every user’s dock on that machine:

dockutil --add ‘~/Downloads’ --view grid --display folder --allhomes

The following adds a url dock item after the Downloads dock item for every user’s dock on that machine:

dockutil --add vnc://miniserver.local --label ‘Mini VNC’ --after Downloads --allhomes

The following removes System Preferences from every user’s dock on that machine:

dockutil --remove ‘System Preferences’ --allhomes

The following moves System Preferences to the second slot on every user’s dock on that machine:

dockutil --move ‘System Preferences’ --position 2 --allhomes

The following finds any instance of iTunes in the specified home directory’s dock:

dockutil --find iTunes /Users/jsmith

The following lists all dock items for all home directories at homeloc in the form: itempathtab

dockutil --list --homeloc /Volumes/RAID/Homes --allhomes

Notes:

When specifying a relative path like ~/Documents with the --allhomes option, ~/Documents must be quoted like ‘~/Documents’ to get the item relative to each home

Bugs:

Names containing special characters like accent marks will fail

Contact:

Send bug reports and comments to kcrwfrd at gmail.

(imported comment written by NoahSalzman)

Also, I don’t have Microsoft Communicator installed, but here is how I test if Mail is one of my dock items:

Q: exists dictionaries “tile-data” whose (string “file-label” of it is “Mail”) of dictionaries of values of array “persistent-apps” of dictionary of file “/Users/noah/Library/Preferences/com.apple.dock.plist”

A: True

Q: exists dictionaries “tile-data” whose (string “file-label” of it is “blah-blah-blah”) of dictionaries of values of array “persistent-apps” of dictionary of file “/Users/noah/Library/Preferences/com.apple.dock.plist”

A: False

I’m doing this on Mac OS X 10.7.

(imported comment written by pdentremont91)

OK I have this working

exist dictionaries “tile-data” whose (string “file-label” of it is “Microsoft Communicator”) of dictionaries of values of array “persistent-apps” of dictionary of file (pathname of current user folder & “/Library/Preferences/com.apple.dock.plist”)

but what i really need to do is delete the array item at the index where this exists.