开发者

Applescript for Software Update for Snow Leopard Server

Using SWU Server on Snow Leopard Server, and I'm trying to create a script that will change the CatalogURL, and then reset it after SWU quits. It will run the script and launch SWU, but will not run the shell script indicated after the "on quit" prompt. There is no error, it just stops running after SWU is launched.

tell application "System Events"
    set OSVersion to do shell script "sw_vers -productVersion"
end tell
if OSVersion starts with "10.4" then
    -- set up Tiger thing
    set catalogURLValue to "http://server.local:8888/index.sucatalog"
else if OSVersion starts with "10.5" then
    -- set up Leopard thing
    set catalogURLValue to "http://server.local:8888/index-leopard.merged-1.sucatalog"
else if OSVersion starts with "10.6" then
    -- set up Snow Leopard thing
    set catalogURLValue to "http://server.local:8888/index-leopard-snowleopard.merged-1.sucatalog"
else
    return
end if
do shell script "defaults write /Library/Preferences/com.apple.SoftwareUpdate CatalogURL " & catalogURLValue

tell application "Software Update"
    activate
end tell


on quit
    try
        do shell script ¬
            "defaults delete /Library/Preferences/com.apple.SoftwareUpdate CatalogURL"
        continu开发者_Python百科e quit
    on error
        do shell script ¬
            "rm /Library/Preferences/com.apple.SoftwareUpdate.plist"
    end try
end quit


The on quit handler will be run when the AppleScript receives a quit event, not when Software Update quits; in fact, since the script simply exits itself after activating Software Update, the quit handler will never run at all. What you need to do is make the script wait until Software Update finishes, then run the cleanup steps. I haven't tested this properly, but it should work:

tell application "System Events"
    set OSVersion to do shell script "sw_vers -productVersion"
end tell
if OSVersion starts with "10.4" then
    -- set up Tiger thing
    set catalogURLValue to "http://server.local:8888/index.sucatalog"
else if OSVersion starts with "10.5" then
    -- set up Leopard thing
    set catalogURLValue to "http://server.local:8888/index-leopard.merged-1.sucatalog"
else if OSVersion starts with "10.6" then
    -- set up Snow Leopard thing
    set catalogURLValue to "http://server.local:8888/index-leopard-snowleopard.merged-1.sucatalog"
else
    return
end if
do shell script "defaults write /Library/Preferences/com.apple.SoftwareUpdate CatalogURL " & catalogURLValue

tell application "Software Update"
    activate
end tell

set runCount to 1
repeat while runCount > 0
    delay 5
    tell application "System Events" to set runCount to the count of (processes whose name is "Software Update")
end repeat
try
    do shell script ¬
        "defaults delete /Library/Preferences/com.apple.SoftwareUpdate CatalogURL"
    continue quit
on error
    do shell script ¬
        "rm /Library/Preferences/com.apple.SoftwareUpdate.plist"
end try
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜