Reputation: 1683
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.
Upvotes: 0
Views: 375
Reputation:
Probably the easiest fix here would be to simply catch the error:
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
You could also try checking the count of windows
before trying to reference the front window
, but that's somewhat more prone to errors (as the window may disappear before you grab its bounds).
Upvotes: 1