(*

Replace Dock icons.app

This small applescript application accepts a dropped folder of Dock.app replacement images and then installs them for you, creating a backup if necessary.

This source is released into the public domain, but please email me if you use it.  If you make changes or improve it, please make them available for everyone to benefit.


(c) Grayson Hansard 2007

info@fromconcentratesoftware.com

http://www.fromconcentratesoftware.com/

*)


on open theFolder

my copyFolder(theFolder)

end open


on run

set action to button returned of (display dialog "What do you want to do?" buttons {"Quit", "Restore Dock", "Replace Dock"} default button 3)

if action is "Replace Dock" then

set theFolder to choose folder without invisibles

copyFolder(theFolder)

else if action is "Restore Dock" then

my restoreDock()

end if

end run


on copyFolder(theFolder)

-- First, make backup

try

do shell script "ls ~/Documents/Dock\\ backup"

on error e

-- No "Dock backup" folder.  Let's back it up

do shell script "mkdir ~/Documents/Dock\\ backup/"

do shell script "cp /System/Library/CoreServices/Dock.app/Contents/Resources/scurve* ~/Documents/Dock\\ backup/" with administrator privileges

end try

-- Overwrite the old ones with the new

set newPath to scrubPath(POSIX path of theFolder) & "scurve*"

do shell script "cp -f " & newPath & " /System/Library/CoreServices/Dock.app/Contents/Resources/" with administrator privileges

do shell script "killall Dock" -- Reset the Dock

end copyFolder


on restoreDock()

do shell script "cp -f ~/Documents/Dock\\ backup/scurve* /System/Library/CoreServices/Dock.app/Contents/Resources/" with administrator privileges

do shell script "killall Dock"

end restoreDock


on scrubPath(p)

set scrubs to {" ", "*", "?"}

set scrubbedPath to ""

repeat with c in p

if c is in scrubs then set scrubbedPath to scrubbedPath & "\\"

set scrubbedPath to scrubbedPath & c

end repeat

return scrubbedPath

end scrubPath