• 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
Addi item to dock - defaults write problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Addi item to dock - defaults write problem


  • Subject: Addi item to dock - defaults write problem
  • From: Laine Lee <email@hidden>
  • Date: Wed, 09 Jun 2004 12:28:05 -0500

I wrote this script to add TextEdit to the Dock. I've tried to insure that
the lines won't wrap.

I've been unable to find a way to add dictionary children to the array
persistent-apps in the Dock's plist file using defaults write.

Please tell me a better way to use Applescript to add an item to the dock
without using non-default scripting additions. Thanks.

Laine

----------
property newtext : missing value
property bad_string : missing value
property OK_string : missing value
property keystring : "persistent-apps"


do shell script ,
"defaults write com.apple.dock" & space & keystring & space ,
& "-array-add" & space ,
& "some_text_I_hope_no_one_else_will_put_here"


set bad_string to ,
"<string>some_text_I_hope_no_one_else_will_put_here</string>"
set OK_string to "<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>
<key>file-label</key>
<string>TextEdit</string>
</dict>
<key>tile-type</key>
<string>file-tile</string>
</dict>"

set the target_plist to ((path to home folder as string) ,
& "Library:Preferences:com.apple.dock.plist") as alias

open for access target_plist with write permission

set newtext to read target_plist

set newtext to replace_chars(newtext, bad_string, OK_string)

set eof of target_plist to 0

write newtext to target_plist starting at eof

close access target_plist

tell application "Dock" to quit

display dialog ,
"TextEdit Has been installed into your Dock." buttons ,
{"OK"} default button 1


on replace_chars(newtext, bad_string, OK_string)
set old_t to AppleScript's text item delimiters
set AppleScript's text item delimiters to (bad_string as Unicode text)
set item_list to every text item of newtext
set AppleScript's text item delimiters to (OK_string as Unicode text)
set newtext to item_list as Unicode text
set AppleScript's text item delimiters to old_t
return newtext
end replace_chars

----------
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: Addi item to dock - defaults write problem
      • From: Gnarlodious <email@hidden>
  • Prev by Date: Re: Startup !
  • Next by Date: Curl
  • Previous by thread: Re: Re: cant get script to run
  • Next by thread: Re: Addi item to dock - defaults write problem
  • Index(es):
    • Date
    • Thread