Is there trigger for external monitor connected

I would like to know if I can trigger actions based upon an external monitor being plugged into my MacBook.

I'm trying to turn off bluetooth if I unplug my laptop. This way I won't be eating up my bluetooth keyboard and trackpad when I'm using my laptop away from my desk.

I thought maybe conditional activation groups might do this but I can't see how.

3 Likes

Hi,

I'm not aware of such trigger.
If you are ok with playing with applescript then you should check this link:
Now if you look here: https://apple.stackexchange.com/questions/333556/how-do-i-trigger-a-script-when-a-second-monitor-is-attached
It should be possible to customise those script as trigger for BTT.

1 Like

Thanks! That's exactly the post I came across after and ended up implementing. I was not super keen on having something run in background perpetually every N seconds. Right now I compiled script as an app and run it under my "Login Items" but its not ideal because I have the app open in my task switcher. I tried to run under apple launchd which worked ok except that on shutdown the script does not stop and causes an abnormal OS shutdown.

Be really nice if there was a way to have BTT trigger.

1 Like

Check out SwitchResX. It monitors... monitors. When you switch to certain layouts or certain conditions are met that quality for a layout you've defined (aka Monitors A, B, C are present), if can fire off a script of your choosing.

I also want this, but don't want to have switchresx running either

Jumping on the bandwagon – this would be fantastic.

Likewise.

I will wait for it

You can create a conditional activation group that matches the resolutions you have when your external monitor is connected. Then you can setup a trigger that activates if this conditional activation group becomes true.

3 Likes

i made a similar thing with different way

Repeating or Time Based Trigger ( with 15 second ) > Run Real Javascript

(async()=>{

m=await runAppleScript(`tell app "Image Events" to count displays`)

let c=await callBTT('get_number_variable',{variableName:'MonitorCount'})
if(c==null){
	callBTT('set_number_variable',{variableName:'MonitorCount',to:m})
	return
}

if(m==c){return}
else if(m>1&&c==1){//monitor connected
	callBTT('set_number_variable',{variableName:'MonitorCount',to:2})
	runAppleScript(`
		launch app "HazeOver"
		launch app "LinearMouse"
		launch app "MonitorControl"
	`)
}
else if(m==1&&c>1){//monitor disconnected
	callBTT('set_number_variable',{variableName:'MonitorCount',to:1})
	runAppleScript(`
		quit app "HazeOver"
		quit app "LinearMouse"
		quit app "MonitorControl"
	`)
}
returnToBTT(1)
})()

Or you can do same with Applescript

Applescript Version
tell application "Image Events" to set m to count displays

tell application "BetterTouchTool"
	set c to get_number_variable "MonitorCount"
	if c is missing value then
		set_number_variable "MonitorCount" to m
		return
	end if
end tell

if m = c then
	return
else if m > 1 and c = 1 then
	tell application "BetterTouchTool" to set_number_variable "MonitorCount" to 2
	launch application "HazeOver"
	launch application "LinearMouse"
	launch application "MonitorControl"
else if m = 1 and c > 1 then
	tell application "BetterTouchTool" to set_number_variable "MonitorCount" to 1
	quit application "HazeOver"
	quit application "LinearMouse"
	quit application "MonitorControl"
end if

script detects you got multi monitor or not. im just using 1 external not sure works on 3 or more screens correctly. you must change numbers in conditions if you have 2 monitors then detecting third one