Friday, January 28, 2022

#1 2021-11-26 01:06:15 pm

Joy
Member
From:: Tirol
Registered: 2008-07-04
Posts: 680

Detect fullscreen

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

Applescript:


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 neutral

Offline

 

#2 2021-11-26 08:46:13 pm

wch1zpink
Member
Registered: 2011-08-20
Posts: 77

Re: Detect fullscreen

Applescript:

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.

Applescript:

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}

Last edited by wch1zpink (2021-11-26 09:04:03 pm)

Offline

 

#3 2021-11-27 12:53:01 am

ccstone
Member
Registered: 2009-02-07
Posts: 417

Re: Detect fullscreen

Hey Joy,

Applescript:


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

Last edited by ccstone (2021-11-27 01:00:47 am)

Offline

 

#4 2021-11-27 07:10:32 am

peavine
Member
From:: Prescott, Arizona
Registered: 2018-09-04
Posts: 1218

Re: Detect fullscreen

Joy wrote:

I need to keep the command generic, because I want to track any app - if it is in fullscreen mode or not.



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.

Applescript:

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

Last edited by peavine (2021-11-27 07:26:15 am)


2018 Mac mini - macOS Monterey - Script Debugger 8

Offline

 

#5 2021-11-28 05:19:45 am

wch1zpink
Member
Registered: 2011-08-20
Posts: 77

Re: Detect fullscreen

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.

Applescript:

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}

Nv083Xy.png?2


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.

Offline

 

#6 2021-11-28 10:31:27 am

Joy
Member
From:: Tirol
Registered: 2008-07-04
Posts: 680

Re: Detect fullscreen

@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

Last edited by Joy (2021-11-28 10:33:29 am)

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)