如何重新启动查找程序 [英] How to relaunch finder application

查看:199
本文介绍了如何重新启动查找程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下的AppleScript 来重新启动查找程序。

I am using following applescript to relaunch finder application.

osascript -e "tell application \"Finder\"" -e "delay 1" -e "try" -e "quit" -e "delay 1" -e "activate" -e "end try" -e "end tell"  

但有时这个剧本是不是重新推出Finder应用程序(仅在quiting取景器应用程序)。我没有得到在控制台的任何错误。结果
http://www.cocoabuilder.com/archive/cocoa/113654-nsapplescript -buggy.html 结果
任何人都可以请帮我吗?

But sometimes this script is not relaunching finder application(only quiting finder application). i am not getting any error in console.
http://www.cocoabuilder.com/archive/cocoa/113654-nsapplescript-buggy.html
Can anyone please help me out?

推荐答案

下面是一个AppleScript的方式。如您所见,你不能依赖于特定的延迟时间。因此,我们手动等待Finder来检查,如果它在运行的进程列表中退出。当它不再列表,然后我们知道它已经退出,我们可以再次激活它。

Here's an applescript way. You cannot rely on a specific delay time as you've seen. Therefore we manually wait for the Finder to quit by checking if it's in the list of running processes. When it is no longer in the list then we know it has quit and we can activate it again.

您还会注意到我把时间检查脚本,因为重复循环。以防万一出错,我们不想重复循环永远运行。因此,如果它运行超过10秒,我们会自动退出重复循环。

You'll also note I put a time check in the script because of the repeat loop. Just in case something goes wrong we do not want the repeat loop to run forever. As such if it runs for more than 10 seconds we automatically exit the repeat loop.

tell application "Finder" to quit

set inTime to current date
repeat
    tell application "System Events"
        if "Finder" is not in (get name of processes) then exit repeat
    end tell
    if (current date) - inTime is greater than 10 then exit repeat
    delay 0.2
end repeat

tell application "Finder" to activate

下面是code的osascript版本。

Here's the osascript version of that code.

/usr/bin/osascript -e 'tell application "Finder" to quit' -e 'set inTime to current date' -e 'repeat' -e 'tell application "System Events"' -e 'if "Finder" is not in (get name of processes) then exit repeat' -e 'end tell' -e 'if (current date) - inTime is greater than 10 then exit repeat' -e 'delay 0.2' -e 'end repeat' -e 'tell application "Finder" to activate'

这篇关于如何重新启动查找程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆