防止对话框阻止用户注销?

问题描述:

我们有一个用applescript编辑器制作的简单.app文件,当用户登录时会弹出一个显示对话框。问题是许多用户忽略了这个框,并且不按“ok”关闭它。如果保持打开状态,则会阻止用户注销计算机。防止对话框阻止用户注销?

有没有办法阻止对话框阻止注销进程?

两件事我能想到的:1)你可以把一个对话框上的命令“之后放弃”,所以,这是一个时间后自动关闭,例如5数秒

display dialog "Hello" giving up after 5 

或者你可以自己写一个注销脚本。该脚本将在用户注销时运行。像这样的东西会奏效。

tell application "System Events" 
    if exists process "ApplicationName" then 
     set itExists to true 
    else 
     set itExists to false 
    end if 
end tell 

if itExists then 
    tell application "ApplicationName" to activate 
    tell application "System Events" to keystroke return 
end if 

Google针对“注销挂钩”来查找如何在注销时运行脚本。

+0

第二种解决方法有点不好意思,您不觉得吗? ;-)顺便说一句,注销钩的最大问题是,你只能拥有一个,而通过各种方法拥有无限量的登录脚本是没有问题的。 – Mecki 2011-03-30 18:05:47

+0

是的,这是肯定的哈克。如果您调用的脚本调用其他脚本,则可以有多个注销脚本!我的注销命令调用了一个applescript,我可以根据需要做很多事情。 – regulus6633 2011-03-31 15:15:42

请问我为什么不只是修改AppleScript代码后自动关闭对话框,比如说5分钟?这肯定比“黑客入侵”系统更容易。

display dialog "Hello World" buttons "Ok" giving up after (5 * 60) 

此对话框将在5分钟后自动关闭。如果你真的关心它,而其他人无视它,就像你在你的问题中指出的那样,用户阅读它就足够长。

不幸的是,显示对话框始终需要用户采取措施才能消失,除非您自己使用“放弃之后”通知自行消失,而不必一定阅读它。

假设您需要它们来阅读它,并且如果您可以控制将要启动的计算机,则可以使用Growl来显示您的通知。

它发生在我身上,你可以把显示对话框放在空闲处理程序中,如果他们确实点击“ok”,脚本就退出;如果他们没有点击“确定”,则按照其他答案中的描述使用“放弃后”,以便在想要的秒数后消失,然后在下一次空闲时重新弹出。这可能非常烦人,并且如果在对话框启动时它们发生注销,仍然存在阻止注销的风险。

on idle 
    --display the alert for 7 seconds 
    display alert "Very Important Message" giving up after 7 
    if the button returned of the result is "ok" then 
     quit 
    end if 

    --idle for 90 seconds 
    return 90 
end idle 

这个工作对我来说,强制用户注销。在Mac OS X中完全禁用“重新打开Windows时重新打开”并注销确认

tell application "System Events" 
    keystroke "Q" using {command down, option down, shift down} 
    quit 
end tell