Detect fullscreen

I thought a simple script would do the trick, but I was wrong


tell app "VLC" 
fullscreen true
activate
end

tell app "System events"
set frontPr to (get name of first process whose frontmost is true and visible is true) 
tell process frontPr to set isFullscreen to value of attribute "AXFullScreen" of window 1
end

return (frontPr, isFullscreen) 

Example, I get always false if “VLC” is in fullscreen mode.

I need to keep the command generic, because I want to track any app - if it is in fullscreen mode or not.
I guess, ObjC could do a much better analysis if the frontmost process is in fullscreen or not, but by all love, ObjC takes time I don’t have :expressionless:

tell application "VLC"
	activate
	set fullscreen mode to true -- only works if currently playing a vid
end tell

For me, this seems to solve the issue of not correctly reporting if app is fullscreen.

tell application "System Events"
	set visibleApps to name of processes where visible is true
end tell

set text item delimiters to linefeed
set theApps to do shell script "echo " & quoted form of (visibleApps as text) & " | sort"

activate
set frontPr to (choose from list (paragraphs of theApps) ¬
	with title "Visible Apps" with prompt "Get app's fullscreen status." OK button name ¬
	"OK" cancel button name "Cancel") as text

tell application frontPr to activate

tell application "System Events"
	set frontmost of process frontPr to true
	repeat until frontmost of process frontPr
		delay 0.1 -- may need to adjust
	end repeat
	delay 0.3 -- may need to adjust
	if true is in value of attribute "AXFullScreen" of windows of process frontPr then
		set isFullscreen to true
	else
		set isFullscreen to false
	end if
end tell

return {frontPr, isFullscreen}

Hey Joy,


tell application "VLC"
	
	# Boolean
	set isFullScreen to fullscreen mode
	
	# Toggle
	set fullscreen mode to not (fullscreen mode)
	
	# Toggle	
	fullscreen
	
end tell


It looks like VLC rolls-it’s-own full-screen mode, so AXFullScreen is not relevant.

-Chris

The OP appears to raise two issues that are related but may need to be addressed separately. One is testing for fullscreen mode with VLC and the other is testing for fullscreen mode with “any app.” I tested the OP’s script (with slight modification using FastScripts) and it returned the correct results with Script Editor, Script Debugger, Safari, FSNotes, Mail, and Preview. I don’t have VLC installed for testing.

tell application "System Events"
	set frontPR to name of first process whose frontmost is true
	tell process frontPR
		set isFullscreen to value of attribute "AXFullScreen" of window 1
	end tell
end tell

display dialog "The app process is " & frontPR & " and fullscreen is " & isFullscreen

VLC.app is a little “Moody” with the whole “Fullscreen” thing. If you run this following shortened version of the code in my post from yesterday, you can see that it does return “AXFullScreen” values.

set frontPr to "VLC"

tell application frontPr to activate

tell application "System Events"
	set frontmost of process frontPr to true
	repeat until frontmost of process frontPr
		delay 0.1 -- may need to adjust
	end repeat
	delay 0.3 -- may need to adjust
	if true is in value of attribute "AXFullScreen" of windows of process frontPr then
		set isFullscreen to true
	else
		set isFullscreen to false
	end if
end tell

return {frontPr, isFullscreen}

The problem seems to be because the original code targets “window 1” of the front app process. “Window 1” isn’t always the visible window or frontmost window, which is what was causing the incorrect results. My alternate version of the code checks all the windows of the app process. It doesn’t matter which window reports “AXFullScreen” as true because if it is true for any window then the entire app is in FullScreen mode.

@wch1zpink
Good finding, window 1 works well for common apps, but windows is even better, - hopefully lasting between major updates. Works for me, thank you and thanks to all as well