Applescript для обновления программного обеспечения для Snow Leopard Server - PullRequest
1 голос
/ 11 января 2011

Использование сервера SWU на сервере Snow Leopard, и я пытаюсь создать скрипт, который изменит CatalogURL, а затем сбросит его после выхода из SWU.Он запустит скрипт и запустит SWU, но не запустит скрипт оболочки, указанный после приглашения «on quit».Нет ошибки, она просто перестает работать после запуска 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

1 Ответ

1 голос
/ 12 января 2011

Обработчик 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
...