Toggle Full Screen Mode in Monterey for Mail & Safari

I usually run Mai, Safari, and Music in Full-Screen mode and in Windows when the MacBook Pro M1 is connected to a large display. I have been trying to get an AppleScript to toggle this automatically or at least via keystroke. I have been unsuccessful. Note that Monterey changes the fullscreen key to Fn F.
Here is the script based on an example that was working for an earlier version of macOS.
Any help is appreciated. I have tried Moom, but it is also unable to deal with Full Screen.

-- Toggle screens of apps
set toggleOnFull to false

-- set myList to {"Safari", "Mail", "Fantastical", "Music"}
set myList to {"Safari", "Mail"}
repeat with theItem in myList
	
	tell application theItem
		activate
		delay 1
		(* 
  Initially from http://stackoverflow.com/questions/8215501/applescript-use-lion-fullscreen
*)
		set isfullscreen to false
		tell application "System Events" to tell process theItem
			set isfullscreen to value of attribute "AXFullScreen" of window 1
		end tell
		--display dialog "var " & isfullscreen
		
		if isfullscreen is toggleOnFull then
			tell application "System Events" to keystroke "f" using {command down, control down}
			delay 4
		end if
	end tell
	
end repeat

How do you properly paste code in this forum?

You type three backticks (`) on a line at the beginning and end. I’ll edit you post.

Oh, you mean like Markdown?
:wink:

1 Like