AppleScripting应用程序以更改OSX 10.8中的通知中心的背景

时间:2012-10-17 12:39:30

标签: applescript osx-mountain-lion copy-paste nsusernotificationcenter

这是我的代码:

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 `

我需要更改什么才能使其正常工作?它应该允许您选择一个文件夹,如果在该文件夹中有一个名为 linen.tiff 的文件,则将该文件复制到设置路径:

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

替换已存在的那个......

设置路径并使其正常工作的麻烦

1 个答案:

答案 0 :(得分:0)

你好像把所有的路径弄乱了。你只是没有正确使用它们。此外,Finder没有“复制”命令。它有一个“重复”命令。但是,因为您要将副本执行到受限制的位置,所以我会使用cp shell命令,并使用“管理员权限”运行它。

因此下面的代码将执行您要执行的操作(我没有测试它)。但我怀疑这是一个好主意,不知道它是否会起作用。通常只更换文件不会像您期望的那样在不重新启动通知中心的情况下进行更改。另外,正如我在代码中提到的那样,您将遇到文件权限问题。该文件夹中的文件具有您复制的文件不具有的特殊权限。最后,触摸/ System目录中的内容并不是一个好主意。

说了这么多,如果你还想继续,那就试试吧。

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