Visible frame of Script Runners not updating

I added SWM to a fullscreen UI that uses visible frame. its almost ready but its not launching on correct resize on some situations.

i guess current application in applescript references to btt script runners

if i change dock / menubar autohide setting visible frame changes but it remains same on script runners
also same story with changing monitors while mirroring or if i use my macbook in clamshell mode then i remove monitor connection it still uses visible frame of monitor

is there any way to update visible frame of script runners or restarting btt only way?

here is simplified preset for testing. it opens webview on fn+O. you can close it with any key
VisibleFrameTest.bttpreset (6.4 KB)

Thanks btw

webview html

<html>
<head>
<style>
body{
	background-color:rgba(0,0,0,.6);
	display:block;
	height:calc(100% - 4px);
	width:calc(100% - 4px);
	border:2px solid red;
	margin:0;
}
</style>
<script>
c=()=>{callBTT('trigger_action',{closeFloatingWebView:1})}
window.onkeydown=e=>{e.preventDefault();c()}
BTTInitialize=async()=>{
VF=(await runAppleScript({script:`
use framework "AppKit"
tell current application
	set m to its NSEvent's mouseLocation()
	repeat with s in its NSScreen's screens()
		if NSPointInRect(m, s's frame()) then
			set v to s's visibleFrame()
			set {{x, y}, {w, h}} to v
			set {vx, vy} to {NSMinX(v), (NSMaxY(s's frame())) - (NSMaxY(v))}
			set {vw, vh} to {(NSMaxX(v)) - x, NSHeight(v)}
			exit repeat
		end if
	end repeat
end tell
x & ":" & y & ":" & w & ":" & h & ":" & vx & ":" & vy & ":" & vw & ":" & vh as text
`})).split(":")
//visible frame with wrong origin
callBTT('resize_webview',{x:VF[0],y:VF[1],width:VF[2],height:VF[3]})
//visible frame with correct origin excluded menubar
//callBTT('resize_webview',{x:VF[4],y:VF[5],width:VF[6],height:VF[7]})
}
</script>
</head>
<body>
</body>
</html>

webview settings

Unfortunately that is a macOS bug that has been there forever. I think I reported it 2011 to Apple.

You could try whether the built in variable works better, but I think it will also not work in all cases (requires latest btt):

let x = await callBTT('get_number_variable', {variable_name:'focused_screen_visible_frame_x'})
let  y = await callBTT('get_number_variable', {variable_name:'focused_screen_visible_frame_y'})
let  width = await callBTT('get_number_variable', {variable_name:'focused_screen_visible_frame_width'})
let  height = await callBTT('get_number_variable', {variable_name:'focused_screen_visible_frame_height'})

apple is not best on fixing bugs, they're ignoring minor bugs

i look for that variables but didn't saw in documentation, actually i need visible frame of mouse with screen and tried mouse_screen_visible_frame_x instead of focused_screen_visible_frame_x and it worked.

thanks for your support

why there is a difference between applescript and btt visible frame

Applescript > x:0,0 y:25,0 w:1680,0 h:956,0
BTT > x:0,0 y:69,0 w:1680,0 h:956,0

Applescript cordinates start from top so y shows menubar height
BTT coordinates start from bottom so y shows dock height

is there an option for this or a variable

Im using applescript to resize, move or align some parts of SWM. they are using top to bottom coordinate system

use framework "AppKit"
tell current application
	set m to its NSEvent's mouseLocation()
	repeat with s in its NSScreen's screens()
		if NSPointInRect(m, s's frame()) then
			set v to s's visibleFrame()
			set {{x, y}, {w, h}} to v
			set {vx, vy} to {NSMinX(v), (NSMaxY(s's frame())) - (NSMaxY(v))}
			set {vw, vh} to {(NSMaxX(v)) - x, NSHeight(v)}
			exit repeat
		end if
	end repeat
end tell
x & ":" & y & ":" & w & ":" & h & ":" & vx & ":" & vy & ":" & vw & ":" & vh as text
1 Like