• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Add/Remove from Dock?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Add/Remove from Dock?


  • Subject: Re: Add/Remove from Dock?
  • From: Christopher Nebel <email@hidden>
  • Date: Tue, 27 Jun 2006 10:49:52 -0700

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Add/Remove from Dock?
      • From: Laine Lee <email@hidden>
References: 
 >Re: Add/Remove from Dock? (From: "Laine Lee" <email@hidden>)

  • Prev by Date: Re: intel and Applescript
  • Next by Date: Re: intel and Applescript
  • Previous by thread: Re: Add/Remove from Dock?
  • Next by thread: Re: Add/Remove from Dock?
  • Index(es):
    • Date
    • Thread