Best way to delete a .plist item?

Hi everyone! ๐Ÿ˜€

I have found similar topics on this...but maybe someone can clear it up for me? ๐Ÿ˜€

I want to delete an item within a .plist, specifically to remove an item from the Dock by scripting. (See com.apple.dock.plist) If I use System Events I can take one of the "Dictionary" types with a number under persistent-apps and delete the value so basically it works...it's just I leave the empty line with the number there. Using "defaults delete" I can't seem to access this item...maybe it's too deeply nested or I just don't have the syntax right? And I'm not sure about Cocoa? I'm using Applescript Studio...

I can search using System Events and find all the needed info I'm looking for...I just can't find a simple way to say delete the entry! ๐Ÿ˜Ÿ

Thanks in advance,

Reg ๐Ÿ˜€

Powerbook G4 12" 1.5GHz 1.25Gb RAM, Mac OS X (10.4.8)

Posted on Dec 14, 2006 1:16 AM

Reply
10 replies

Dec 14, 2006 6:05 PM in response to Reggie Ashworth

Hi guys! ๐Ÿ˜€

Thanks for the reply!

I have read that post that you suggested and it actually does a good job. I'm just trying to avoid using plist buddy as I don't know for sure if a computer will have it for sure to be able to use its functions...

I have read the "man defaults" page and I can't seem to get the syntax right! ๐Ÿ˜Ÿ Either that or it's not possible? For example:

delete domain key
Removes the default named key from domain.


But I can't seem to delete anything that's nested beyond that first key? I've read that defaults can't handle deeply nested items well, and in this case I just need to go one more step. (In com.apple.dock.plist "persistent-apps" is the key which contains dictionary entries 0 through however many apps are in your dock. I need to be able to delete one of those entries by scripting somehow.)

Thanks for the help! Any more ideas? ๐Ÿ˜€

Reg

Dec 15, 2006 8:32 AM in response to Robert Jones30

Hi Robert! ๐Ÿ˜€

Thanks for the replay...it needs to be part of a script that will go into an app. So the script needs to decide which icon needs to be removed then remove it. So it's something that will always be different. There's nothing difficult of course about removing an icon from the dock, or even removing it using Property List Editor or similar is ok too...just not sure yet how to do it via scripting.

Thanks again! ๐Ÿ˜€

Reg

Dec 15, 2006 8:34 AM in response to Reggie Ashworth

OK then, how about this?

1) Figure out which item to remove from the Dock.
2) Write a new plist file that contains everything needed in the Dock except that one item.
3) Overwrite the existing Dock plist with your new one.
4) Use "do shell script" to kill the Dock. The Dock will automatically restart after it is killed, and voilร ! Robert's your father's brother, as they say.

Robert (not your father's brother)

Dec 15, 2006 11:40 AM in response to Reggie Ashworth

You can use System Events' Property List Suite to delete nested plist item, try the follow, it'll delete iTunes from the Dock:

set file_path to "Library:Preferences:com.apple.dock.plist"
tell application "System Events"
set _home to (POSIX file (home directory of current user)) as text
set dock_plist to property list file (_home & file_path)
set apps_values to value of ((property list items of dock_plist) whose name is "persistent-apps")
set new_values to {}
repeat with apps_value in apps_values
if |_CFURLString| of (|file-data| of (|tile-data| of (apps_value as item))) does not contain "iTunes" then copy apps_value as item to end of new_values -- change to "iTunes" to other app if needed
end repeat
set value of ((property list items of dock_plist) whose name is "persistent-apps") to new_values
end tell

Dec 15, 2006 7:34 PM in response to Cyclosaurus

Hi Cyclosaurus! ๐Ÿ˜€

Thanks for the script! Funny on my end it hangs with this error:

Can't get |file-data| of {|file-label|:""}.

I think it's on the last number of persistent-apps...I've noticed that using System Events it adds an extra number to the total shown in PLE. So if it show 22 (mine for example) in PLE then System Events can actually go up to 23. That's ok...it just needs an exit repeat or something. I just woke up here (in the Philippines) so once I have some coffee I would work on it more. But this helps for sure! ๐Ÿ˜€

Thanks a lot! ๐Ÿ˜€

Reg

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Best way to delete a .plist item?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.