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 up它错误, 。 如何检查窗口是否在屏幕上,以便我可以添加 if 语句来不显示 如果屏幕上没有窗口,请运行它。
I have written this script function
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 I am on the desktop with no windows up it errors.
How can I check if a window is on screen, so I can put an if statement to not
run it if a window is not on the screen.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里最简单的修复方法可能就是简单地捕获错误:
您还可以在尝试引用
前窗口
之前尝试检查窗口数
,但这更容易出现问题错误(因为窗口可能会在您抓住其边界之前消失)。Probably the easiest fix here would be to simply catch the error:
You could also try checking the
count of windows
before trying to reference thefront window
, but that's somewhat more prone to errors (as the window may disappear before you grab its bounds).