【问题标题】:Apple script to restart and after restart quit applicationApple脚本重新启动并在重新启动后退出应用程序
【发布时间】:2017-02-17 17:15:11
【问题描述】:

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

如果我不把 try 放在整个脚本应用程序中,AppleEvent 超时(-1712)一段时间后会抛出错误,我可以看到我不想要的 Edit 选项,这就是它放的原因整个 try 并且如果我在上面的处理程序上尝试它仍然会继续重新启动我想要的直到我按下重新启动它不会重新启动它。 以下是重启后未退出应用程序的最终应用程序。休息很好。

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

【问题讨论】:

    标签: macos applescript


    【解决方案1】:

    如果脚本保存为应用程序,请使用 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
    

    【讨论】:

    • 它无法正常工作,重启后它仍然在坞站上,并要求我再次重启。
    • 可能与脚本语法无关。用beep 代替restart 来证明它。脚本将退出。
    • 如果整个脚本都在try 中不占用on quit on run ..!!!! try 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 end try
    • 我的建议不包含任何try。无论如何不要将整个处理程序放在 try 块中。
    • 如果你指的是当前用户的桌面文件夹,它只是/Users/jack/Desktop/2014(没有前导Volumes/<diskname>)。启动卷由第一个斜杠表示。您可以在一行中创建 4 个文件夹:do shell script "mkdir -p /Users/jack/Desktop/{2014,2015,2016,2017}"
    猜你喜欢
    • 2013-03-20
    • 1970-01-01
    • 2019-08-10
    • 2014-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多