Applescript检查窗口是否是一个屏幕

时间:2011-11-21 22:12:44

标签: window 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

如果我在桌面上没有Windows,则会出现错误。 如何检查窗口是否在屏幕上,因此我可以将if语句放入屏幕  如果屏幕上没有窗口,请运行它。

1 个答案:

答案 0 :(得分: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

您还可以在尝试引用count of windows之前尝试检查front window,但这更容易出错(因为窗口可能会在您获取其边界之前消失)。

相关问题