Re: Addi item to dock - defaults write problem
Re: Addi item to dock - defaults write problem
- Subject: Re: Addi item to dock - defaults write problem
- From: Gnarlodious <email@hidden>
- Date: Wed, 09 Jun 2004 12:47:04 -0600
Unfortunately "defaults" can't recognize any file structure, you are stuck a
the root level.
Here is a sed piece I use to delete the cookie option from the IE pref file:
do shell script "sed -e '/HTTP Cookies2/,/<data>/!b' -e '/<data>/!b' -e
':loop' -e 'N;/<\\/data>/!bloop' -e 's/\\(\\n\\).*\\n/\\1/'''
In your case perl is probably a better solution, I don't have TextEdit and
can't figure out exactly what you need to insert. if you can identify where
you want to START the insert and END the insert it should be possible.
-- Gnarlie
Entity Laine Lee spoke thus:
>
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.