2011-11-21 24 views
0

我写了这个脚本函数AppleScript的检查,如果窗口是一个屏幕

on GetWindowLocation() 
    set front_app to (path to frontmost application as Unicode text) 
    tell application front_app 
     item 1 of (get bounds of front window) 
    end tell 
end GetWindowLocation 

on GetDockStatus() 
    tell application "System Events" to get the autohide of the dock preferences 
end GetDockStatus 

如果我在桌面上没有窗户了它的错误。 如何检查窗口是否在屏幕上,以便我可以将if语句设置为不是 如果窗口不在屏幕上,请运行它。

回答

1

也许最简单的解决这里是简单地捕捉错误:

tell application front_app 
    try 
     return item 1 of (get bounds of front window) 
    on error 
     -- do something here to handle there being no front window 
    end try 
end tell 

您也可以尝试尝试引用front window之前检查count of windows,但这是稍微更容易出错(如窗口可能消失之前你抢它的边界)。

+0

该工作完全在这里OK感谢就是我工作的http://ice-os.com/downloads/WindowDodge-1.0.tar.bz2的OSX告诉我你的想法 – zeitue

+0

有趣的概念,但它似乎取决于在特定的屏幕尺寸和/或底座位置上 - 我的系统在右侧有停靠栏,并且没有反应。它也一直使用100%的CPU。 – duskwuff

+0

好的,我必须弄清楚它有什么问题。我的Dock在左边 – zeitue