AppleScripting an app to change background of Notification Center in OSX 10.8

437 Views Asked by At

here's my code:

set NCBGPath to path ("Machintosh hd:System:LIbrary:Core Services:Notification Center:Contents:Resources")
set NCBackground to {"linen.tiff"}
set themeFolder to choose folder with prompt "Choose a Theme"
tell application "Finder"
if exists file (themeFolder & NCBackground) then
    copy file (themeFolder & NCBackground) to NCGBPath
end if
end tell `

What do I need to change to make it work? It should let you choose a folder, if in that folder there's a file called linen.tiff then copy that file to a set path:

/System/Library/CoreServices/Notification Center/Contents/Resources 

replacing the one that already exist...

In troubles setting the path and making it work

1

There are 1 best solutions below

3
On

You seem to have all of your paths messed up. You're just not using them correctly. Also the Finder does not have a "copy" command. It has a "duplicate" command though. However because you're performing the duplicate to a restricted location I would use the cp shell command instead and run it with "administrator privileges".

So the below code will do what you are trying to do (I did not test it). However I doubt it's a good idea and don't know if it will even work. Normally just replacing a file won't make a change like you're expecting without restarting notification center. Also, as I mention in the code, you're going to have a file permissions issue. Files in that folder have special permissions that your copied file will not have. Finally, it's not a good idea to touch things in the /System directory.

With all that being said, if you still want to continue then give this a try.

set NCBGPath to "/System/Library/CoreServices/Notification Center/Contents/Resources/"
set NCBackground to "linen.tiff"
set themeFolder to (choose folder with prompt "Choose a Theme") as text
set themePath to themeFolder & NCBackground
set posixNCPath to NCBGPath & NCBackground

set shouldCopy to false
tell application "Finder"
    if exists file themePath then set shouldCopy to true
end tell

if shouldCopy then
    do shell script "cp " & quoted form of POSIX path of themePath & space & quoted form of posixNCPath with administrator privileges
    -- you probably should correct the file permissions too as the copied file probably won't have the proper owner and stuff
else
    display dialog "Could not find the background file in the chosen folder."
end if