Apple脚本重启并在重新启动后退出应用程序

时间:2017-02-14 12:59:41

标签: macos applescript

此Apple脚本保存为应用程序Mac_restart.app 在运行Mac_restart.app mac restart并重新启动后,这个应用程序仍然在Dock上运行应用程序,我可以点击再次重新启动它,我已经添加了应用程序退出但它不起作用。 我想在重新启动后完全使用这个应用程序,并且不希望Dock作为打开的应用程序。 我错过了什么?请帮助。

如果我没有把尝试放在整个脚本应用程序中将在AppleEvent超时(-1712)一段时间后抛出错误,我可以看到编辑选项我不想要这就是为什么它放整个尝试如果我尝试上面的处理程序它仍然会继续重新启动我想要直到我按重新启动它寿衣不重启。  以下是最终应用程序,重启后不退出应用程序。休息工作正常。

try
    with timeout of 400 seconds
        tell application "Finder"
            display dialog "Create Folder & Restart." buttons {"Cancel", "Ok"} default button 1 with icon 0 with title "Create Folder & Restart" giving up after 400
            if the button returned of the result is "Cancel" then
                return
            end if
        end tell
    end timeout

    try
        do shell script "mkdir -p /Volumes/MAC/Users/jack/Desktop/2014"
        do shell script "mkdir -p /Volumes/MAC/Users/jack/Desktop/2015"
        do shell script "mkdir -p /Volumes/MAC/Users/jack/Desktop/2016"
        do shell script "mkdir -p /Volumes/MAC/Users/jack/Desktop/2017"
    end try

    tell application "Finder"
        activate
        display dialog "Click on Restart." with icon 0 buttons ("Restart") giving up after 60
    end tell
    tell application "Finder"
        restart
    end tell
end try

1 个答案:

答案 0 :(得分:0)

如果脚本保存为应用程序,请使用on quit处理程序

on run
    tell application "Finder"
        activate
        display dialog "Computer restart " with title "Restart Mac" with icon 0 buttons ("Restart Now")
    end tell
    quit
end run

on quit
    tell application "Finder" to restart
    continue quit
end quit
相关问题