Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Add/Remove from Dock?



On Jun 27, 2006, at 7:35 AM, Laine Lee wrote:

Why does the following Applescript, if run repeatedly, keep adding
occurrences of TextEdit to my Dock? My interpretation of manual for defaults
leads me to believe that duplicate entries would not result from such a
command.


The only workaround I've found is to search for the entry first, then
not add it if it's found. Thanks.

do shell script "defaults write com.apple.dock persistent-apps - array-add '<dict><key>tile-data</key><dict><key>file-data</ key><dict><key>_CFURLString</key><string>/Applications/TextEdit.app</ string><key>_CFURLStringType</key><integer>0</integer></dict></ dict></dict>'"

tell application "Dock" to quit

The problem is that you're one level lower than you think. (Maybe. See the second paragraph.) The top level of the "defaults" domain is a key-value dictionary, so, for instance, you could never get two entries named "persistent-apps". However, what you're doing is adding an item to an array value, which is perfectly capable of adding anything regardless of the existing contents of the array.


Reading the man page myself, I see this possibly confusing sentence in the description of "-array-add":

If the key was not present, it is created with the specified array as its value.

What that means in your case is that if there is no "persistent-apps" key, then it will make it using the array you gave -- in other words, adding stuff to a non-existent array is ok; it's as if the array was there, but empty. It does *not* mean that it checks the array contents for a duplicate item.


--Chris Nebel AppleScript Engineering

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/applescript-users/email@hidden

This email sent to email@hidden
References: 
 >Re: Add/Remove from Dock? (From: "Laine Lee" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.