Reposition a Keyboard Maestro Palette

To get a better idea of what each section of code does check out the notes in the AppleScript below.

AppleScript (click to expand/collapse)
set kmInst to system attribute "KMINSTANCE"
tell application "Keyboard Maestro Engine"
	set xRes to getvariable "local_xRes" instance kmInst --retrieves the local_xRes variable from KM
	set yRes to getvariable "local_yRes" instance kmInst --retrieves the local_yRes variable from KM
end tell


tell application "System Events" to tell application process "Keyboard Maestro Engine"
	
	--repeatedly delays 1/10 of a second until the conflict palette appears
	--the subrole is the kind of "window" that the palette is
	repeat until (first window whose subrole is "AXSystemDialog") exists
		delay 0.1
	end repeat
	
	--sets the name of the palette of the AppleScript variable "palName"
	tell (first window whose subrole is "AXSystemDialog")
		set palName to its name
	end tell
	
	--controls the palette
	tell window palName
		
		--sets two variables to the palettes size
		--palXsize is it's width
		--palYsize is it's height
		set {palXsize, palYsize} to its size
		
		--does some math to position the palette in the center of the front screen
		--xRes - palXsize takes the screens width, subtracts the palette's width, and then divides that by 2
		--yRes - palYsize takes the screen's height, subtracts the palette's height, and then divides that by 2
		--that basically gives it the coordinates to position the palette so it is centered according to it's size and the screen resolution
		set its position to {(xRes - palXsize) / 2, (yRes - palYsize) / 2}

	end tell	
end tell

I don't quite follow what the issue is you’re referring to... but I haven't had my afternoon coffee yet :sweat_smile:
Could you elaborate please?

1 Like