Hi,
It would be great to add a new action "Move Mouse Cursor to Next Monitor" under "Other Mouse Actions", similar to how we already have a "Move Window to Next Monitor".
Thanks!
Hi,
It would be great to add a new action "Move Mouse Cursor to Next Monitor" under "Other Mouse Actions", similar to how we already have a "Move Window to Next Monitor".
Thanks!
Just checking.. Any updates here? I don't think it should be too difficult to implement. Otherwise I'd have to look for alternative options. Thanks!
Move mouse to position.... should do what you're looking for.
Thanks for the reply @Caliguvara
Unfortunately that doesn't quite do what I want. What I need is an action that moves the mouse cursor like this:
Monitor 1 -> Monitor 2 -> Monitor 3 -> Monitor 1 -> etc.
I.e. not just a one-time movement to a specific position, but continuously cycling between monitors.
Haven't used an external monitor in years, but with negative values in the position relative to the Botton right corner I think you should be able to achieve this
Then working with additional actions to get the other "jumps".
You can use the "Run Real Javascript action" and add some logic there to achieve this. Here is an example:
The example code (just very quickly hacked together, you'll need to adapt the coordinates)
(async() => {
let action = {
"BTTPredefinedActionType" : 153,
"BTTMoveMouseToPosition" : undefined,
"BTTMoveMouseRelative" : "0",
};
let currentMonitor = await callBTT('get_number_variable', {variable_name: 'currentMon'});
if(!currentMonitor) {
currentMonitor = 0;
}
if(currentMonitor == 0) {
action.BTTMoveMouseToPosition = "{100, 100}";
await callBTT('trigger_action', {json: JSON.stringify(action)});
currentMonitor = 1;
returnToBTT('0');
}else
if(currentMonitor == 1) {
action.BTTMoveMouseToPosition = "{200, 200}";
await callBTT('trigger_action', {json: JSON.stringify(action)});
currentMonitor = 2;
returnToBTT('1');
}else
if(currentMonitor == 2) {
action.BTTMoveMouseToPosition = "{300, 300}";
await callBTT('trigger_action', {json: JSON.stringify(action)});
currentMonitor = 0;
returnToBTT('2');
}
await callBTT('set_number_variable', {variable_name: 'currentMon', to: currentMonitor});
})()
I'm here looking for the same exact thing—an action called "Move Mouse to Next Display and Center" and "Move Mouse to Previous Display and Center". Bonus points to BTT if they allow for wrapping too where continual presses of the shortcut key would cycle through the displays (e.g. on far right display would wrap to far left display).
@Andreas_Hegenberg I tried using your script but it just cycles the mouse position diagonally on my main display. Here's a GIF of what I'm seeing on my end: https://geigel.com/shares/Cdoc9i3
Further, my displays are setup this way in case that has any bearing on the script: https://geigel.com/shares/IlPcO7o
Any pointers and/or updates to the script achieve my desired functionality described above?
Thanks in advance!
AG3
Interested in this option too. For many of us, recording mouse position is not really viable because our monitor setup/arrangement will change between work and home.
I too would be interested in such an action.
Thanks.
There is no acceptable way to do this with current scripting capabilities.
"adapting the coordinates" will not work with monitors of different resolution or if the mouse changes monitor without using the script.
Example.
There is also a problem if the mouse changes monitor without using the script.
Because of this limitations we need the ability to get the current active monitor and to get the current mouse position to be able to implement this with a scrip.
Getting the action to actually move the mouse would be better, though.
Here is another way to move the cursor. My monitors have different screen sizes so I used them.
(async() => {
let action = {
"BTTPredefinedActionType" : 153,
"BTTMoveMouseToPosition" : undefined,
"BTTMoveMouseRelative" : "0",
};
const focusedScreenHeight = await callBTT("get_number_variable", {
variable_name: "mouse_screen_height"
});
const screens = {
laptop: {
height: 967,
mousePosition: "{693.91, 490.40}",
},
monitorTwo: {
height: 1080,
mousePosition: "{2545.93, 570.86}",
},
};
let mousePosistion;
if (focusedScreenHeight === screens.laptop.height) {
// focus on monitorTwo
mousePosistion = screens.monitorTwo.mousePosition;
} else if (focusedScreenHeight === screens.monitorTwo.height) {
// focus on Laptop
mousePosistion = screens.laptop.mousePosition;
}
if (mousePosistion) {
action.BTTMoveMouseToPosition = mousePosistion;
await callBTT('trigger_action', {json: JSON.stringify(action)});
}
})()
Hi,
I had the same problem and I regularly use different monitor configurations. Sometimes I rotate one of the monitors, sometimes I use a projector or a different monitor. So, I didn’t want to use any of the hard coded solutions. Here is my current setup, which automatically orders the monitors from left to right. You can use it in BTT as a JavaScript file and then select one of the methods from the bottom of the file. Explanations are in the moveMouseMonitor function. I am using moveMouseMonitorLeftOpenDockFocusWindow (and the same with Right). This version will stop, if there is no next monitor to the left, briefly open the dock (so that the default application switcher opens on that monitor) and then focus the window under the cursor.
It would be nice if one could easily configure a trigger to count the number of repetitions and pass that to the script. Then, one could jump – in a three-monitor setup – from the left to the right monitor without opening the dock in the middle one.
async function getScreenList() {
// Get list with displays
const screenString = await get_string_variable({ variable_name: 'active_screen_resolutions' });
let screenStringList = screenString.match(/\{\{(-?\d+), (-?\d+)\}, \{(-?\d+), (-?\d+)\}\}/g);
// List with Display origin and dimension
let screenList = [];
for (let screen of screenStringList) {
screenList.push(screen.match(/-?\d+/g).map(Number));
}
// We assume that displays are next to each other (not above each
// other) and order the displays according to their x-coordinate.
screenList.sort(function (a, b) { return a[0] - b[0] });
return screenList
}
async function getScreenXFromVariable(focused_screen) {
// If `focused_screen=true`, use `focused_screen_x` to determine
// current screen, otherwise use `mouse_screen_x`. Currently,
// `focused_screen` does not work with fullscreen applications.
let variable_name = 'mouse_screen_x';
if (focused_screen == true) {
variable_name = 'focused_screen_x';
}
const screen_x = await get_number_variable({ variable_name: variable_name });
return screen_x
}
function getActionDefinitionMouseMove(x, y, duration, anchor) {
// Create action definition for mouse move.
return {
"BTTPredefinedActionType": 153,
"BTTAdditionalActionData": {
"BTTMouseMoveAnchor": anchor,
"BTTMouseMoveX": x,
"BTTMouseMoveY": y,
"BTTMouseMoveDuration": duration,
}
}
}
async function triggerMouseMove(x, y, duration, anchor = 1002) {
// trigger BTT to move mouse
return await callBTT('trigger_action', { json: JSON.stringify(getActionDefinitionMouseMove(x, y, duration, anchor = anchor)) });
}
async function moveMouseMonitor(direction, focused_screen = false, openDock = false, focusWindow = false) {
// javascript function to tell BTT to move the mouse to the middle
// of the next monitor
//
// direction: move left (-1) or right (+1) or cycle left (-2) or
// right (+2)
//
// focused_screen: Use `focused_screen` instead of `mouse_screen`
// BTT variable. Currently, only `mouse_screen` seems to work
// reliably.
//
// openDock: First move cursor at bottom of screen to open Dock.
// Afterwards, the Application Switcher opens on this Display.
//
// focusWindow: Focus window under cursor after moving mouse.
const [screenList, screen_x] = await Promise.all([
getScreenList(),
getScreenXFromVariable(focused_screen)
]);
// Get index of current screen
const screen_index = screenList.findIndex(function (a) { return a[0] == screen_x });
let next_screen_index = screen_index;
if (direction > 0 && screen_index < screenList.length - 1) {
next_screen_index = screen_index + 1;
} else if (direction == 2 && screen_index == screenList.length - 1) {
next_screen_index = 0;
} else if (direction < 0 && screen_index > 0) {
next_screen_index = screen_index - 1;
} else if (direction == -2 && screen_index == 0) {
next_screen_index = screenList.length - 1;
}
const a = screenList[next_screen_index];
if (openDock == true) {
await triggerMouseMove(x = a[0] + a[2] / 2 - 2, y = a[1] + 1, duration = .001);
await triggerMouseMove(x = a[0] + a[2] / 2 + 2, y = a[1] + 1, duration = .25);
}
await triggerMouseMove(x = a[0] + a[2] / 2, y = a[1] + a[3] / 2, duration = .001);
if (focusWindow == true) {
const actionDefinitionFocusWindow = {
"BTTPredefinedActionType": 204,
"BTTPredefinedActionName": "Activate or Bring to Front Window Under Cursor",
};
await callBTT('trigger_action', { json: JSON.stringify(actionDefinitionFocusWindow) });
}
}
async function moveMouseMonitorRight() {
return await moveMouseMonitor(1, focused_screen = false, openDock = false, focusWindow = false);
}
async function moveMouseMonitorLeft() {
return await moveMouseMonitor(-1, focused_screen = false, openDock = false, focusWindow = false);
}
async function moveMouseMonitorRightOpenDock() {
return await moveMouseMonitor(1, focused_screen = false, openDock = true, focusWindow = false);
}
async function moveMouseMonitorLeftOpenDock() {
return await moveMouseMonitor(-1, focused_screen = false, openDock = true, focusWindow = false);
}
async function moveMouseMonitorRightOpenDockFocusWindow() {
return await moveMouseMonitor(1, focused_screen = false, openDock = true, focusWindow = true);
}
async function moveMouseMonitorLeftOpenDockFocusWindow() {
return await moveMouseMonitor(-1, focused_screen = false, openDock = true, focusWindow = true);
}
async function moveMouseMonitorRightFocusWindow() {
return await moveMouseMonitor(1, focused_screen = false, openDock = false, focusWindow = true);
}
async function moveMouseMonitorLeftFocusWindow() {
return await moveMouseMonitor(-1, focused_screen = false, openDock = false, focusWindow = true);
}
async function cycleMouseMonitorRight() {
return await moveMouseMonitor(2, focused_screen = false, openDock = false, focusWindow = false);
}
async function cycleMouseMonitorLeft() {
return await moveMouseMonitor(-2, focused_screen = false, openDock = false, focusWindow = false);
}
async function cycleMouseMonitorRightOpenDock() {
return await moveMouseMonitor(2, focused_screen = false, openDock = true, focusWindow = false);
}
async function cycleMouseMonitorLeftOpenDock() {
return await moveMouseMonitor(-2, focused_screen = false, openDock = true, focusWindow = false);
}
async function cycleMouseMonitorRightOpenDockFocusWindow() {
return await moveMouseMonitor(2, focused_screen = false, openDock = true, focusWindow = true);
}
async function cycleMouseMonitorLeftOpenDockFocusWindow() {
return await moveMouseMonitor(-2, focused_screen = false, openDock = true, focusWindow = true);
}
async function cycleMouseMonitorRightFocusWindow() {
return await moveMouseMonitor(2, focused_screen = false, openDock = false, focusWindow = true);
}
async function cycleMouseMonitorLeftFocusWindow() {
return await moveMouseMonitor(-2, focused_screen = false, openDock = false, focusWindow = true);
}
For some reason, the focused_screen_x variable doesn’t seem to work with full screen applications, which is a bit annoying. Otherwise, I would prefer to move the mouse from the focused monitor to the next one, not from the monitor where the mouse is currently. In particular, the cursor can be on a different monitor than the (hidden) mouse after switching with the application switcher to an application on a different monitor.
hi guys, im a layman and dunno about scripting. i tried all of the scripts here and none of them work. most of them just make my mouse jump to the top left corner of my main display, it doesnt move to the other display at all
can someone please advise me how to customise the code to make it move between my displays?
im on a 13inch air for my main display, then an external 23 inch monitor for my external. i just want to have the mouse switch between them, roughly in the centre but doesnt need to be exact.
If I remember correctly from my tests when I wrote the script, your mouse jumping to the top left corner could mean that the coordinate the scripts tried to move your cursor to where outside your screens. Most of the above scripts you actually have to modify according to your specific monitor setup and this could be the issue.
My version of the script actually does calculate the position automatically, so you should not need to change the script. It works fine for me with various monitors, but I have not tested it on Tahoe yet. To rule out some problems, you could try with the functions moveMouseMonitorLeft and moveMouseMonitorRight first. (You need to write these names in the Async function to call (optional)-field right below the field where you enter the script in BTT.) Importantly, your monitors need to be next to each other (not above each other). If it still does not work, you can try to change their relative positioning in system preferences and then try again.
Thank you so much, this is the issue then: my monitors are above each other. I need this workflow unfortunately. Is there any way to make this work with the monitors above each other?
I’m using my 13 inch m1 macbook air on 1280x800, and my external 23 inch monitor is above it, on 1600x900
thanks so much
Did you try again what I suggested above?
The script should also work for vertical monitors, only that it determines the order based on the horizontal alignment of the top left corners of the screens. If it does not work, please try to put the monitors side by side (in systems preferences, not physically) so that moving the curser out at the right side of one screen brings it in on the left side of the other screen. Then try again.
If it still does not work, could you verify the active_screen_resolutions variable and paste its value here? You can find the “Variables and Scripting” window in the BTT settings pane under “Scripting BTT” in the side bar and then use the search field to look for that variable.
If you just have a static setup, the easiest solution is to use the predefined action "Cycle Through Multiple Actions" and have two "Move Mouse To Postion" actions configured (you can position the mouse cursor using the "relative to screen with name" options:
This would make my life soooo much easier if it can be done built into BTT. Thanks !
I'm not sure if you understand how easy that is. It's actually “built in”. All you have to do is select your screen names from the predefined actions ![]()
Do you know how to set up a cycle action?