Can I detect fullscreen using AppleScript?

I have a script which opens a document in preview and then shows a dialog for me to enter certain data from the document into that dialog (the documents are handwritten, and this one step helps me automate collation of those documents). That works just fine, unless DT is in fullscreen mode; in this case, the document opens on the desktop and the dialog displays overlaying the DT fullscreen - i.e. the document is not visible at the same time. I haven’t found any way for the script to recognise fullscreen mode (which it could then automatically terminate and later reinstate). Setting the bounds of a DT window when it is in fullscreen mode seems to have no effect, and querying the bounds returns values which don’t represent fullscreen (but instead seem to be the bounds the window will take on when fullscreen is ended).

Is there any way to detect fullscreen using AppleScript?

There doesn’t appear to be any AppleScript support for this. zoomed of a window only applies to maximizing a window.

Maybe by comparing the width/height of the window to the one of the screen?

tell application "Finder"
set screen_resolution to bounds of window of desktop
end tell

Thanks for that suggestion; thing is, I don’t seem to be able to get the bounds of the fullscreen window:

return bounds of window 1 returns the bounds of the (only) DT window so long as it is not in fullscreen; but when it is in fullscreen, the same values are returned. Is the window no longer window 1 in fullscreen (and of course I’ve tried 0 to 5 or so, and just get the same results)?

This should work:

tell application id "DNtp"
	return bounds of viewer window 1
end tell

Thank you so much :slight_smile: Whilst viewer window 1 is not equal to screen resolution in fullscreen, it is also not equal to window 1 whilst in fullscreen (but is whilst not in fullscreen) - so this seems to work:

tell application id "DNtp"
	set a to bounds of viewer window 1
	set b to bounds of window 1
	if a = b then return "not fullscreen"
end tell

window 1 doesn’t have to be a think window (main or document window), there can be other visible windows (e.g. Sorter or preferences). Therefore I’m not sure if your comparison will always work. But the width/height of the fullscreen viewer window and of the desktop are identical over here…

That only works (for me) if the DT window is maximised (double-click on the title bar), but not in fullscreen (using the green button on the window).