【问题标题】:Applescript for Software Update for Snow Leopard Server雪豹服务器软件更新的 Applescript
【发布时间】:2011-01-11 18:22:45
【问题描述】:

在雪豹服务器上使用 SWU 服务器,我正在尝试创建一个脚本来更改 CatalogURL,然后在 SWU 退出后将其重置。它将运行脚本并启动 SWU,但不会运行“退出”提示后指示的 shell 脚本。没有错误,只是在SWU启动后停止运行。

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"
        continue quit
    on error
        do shell script ¬
            "rm /Library/Preferences/com.apple.SoftwareUpdate.plist"
    end try
end quit

【问题讨论】:

    标签: macos shell osx-snow-leopard applescript


    【解决方案1】:

    on quit 处理程序将在 AppleScript 接收到退出事件时运行,而不是在软件更新退出时运行;事实上,由于脚本在激活软件更新后会自行退出,因此退出处理程序将永远不会运行。您需要做的是让脚本等到软件更新完成,然后运行清理步骤。我没有正确测试过,但它应该可以工作:

    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
    

    【讨论】:

      猜你喜欢
      • 2011-04-13
      • 1970-01-01
      • 2011-02-24
      • 1970-01-01
      • 1970-01-01
      • 2011-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多