Logi Options+ Smooth Scrolling Settings

I usually use Logi Options+ smooth scrolling with the MX Master 3s’s infinite scroll. But sometimes, like when playing Minecraft, I need to switch to ratchet mode and turn off smooth scrolling, or it feels weird. Switching between infinite/ratchet scroll is just a button on the mouse, but smooth scrolling has to be toggled in Logi Options+ manually.

I noticed there’s a Logi Plugin Service, but no docs. Logi Options+ is built with Electron, so I opened its page in Chrome DevTools and found the smooth scrolling setting in the code.

The code is obfuscated and I didn’t want to read it, so I just used puppeteer to simulate button clicks. After some quick debugging, I made a script that works on macOS. For other systems, just change the launch/kill commands for Logi Options+.

package.json
JSON
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
{
  "name": "logi-options-plus-smooth-scrolling",
  "version": "1.0.0",
  "main": "main.js",
  "author": "yaoxi-std",
  "license": "MIT",
  "scripts": {
    "start": "node main.js"
  },
  "dependencies": {
    "puppeteer-core": "^24.11.2"
  }
}
main.js
JavaScript
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
#!/usr/bin/env node

const { spawn } = require("child_process");
const puppeteer = require("puppeteer-core");
const http = require("http");

// Environment variable configuration
const DEBUGGING_PORT = process.env.DEBUGGING_PORT || 9222;
const ACTION_TIMEOUT = process.env.ACTION_TIMEOUT || 10000;
const LOGI_APP_BUNDLE_PATH =
  process.env.LOGI_APP_BUNDLE_PATH || "/Applications/logioptionsplus.app";

/**
 * Kill Logi Options+ GUI process (keep the background driver service)
 * Use full path matching to ensure only the GUI process is killed, not system driver services
 */
async function killLogiOptionsPlus() {
  try {
    console.log(`[Info] Attempting to kill GUI process: logioptionsplus`);

    const killProcess = spawn("pkill", [
      "-f",
      `${LOGI_APP_BUNDLE_PATH}/Contents/MacOS/logioptionsplus`,
    ]);

    const code = await new Promise((resolve, reject) => {
      killProcess.on("close", resolve);
      killProcess.on("error", reject);
    });

    if (code === 0) {
      console.log(`[Info] Successfully killed GUI process: logioptionsplus`);
    } else {
      console.log(
        `[Info] No GUI process found or failed to kill: logioptionsplus (exit code: ${code})`
      );
    }
  } catch (error) {
    // Don't throw error, as it's not critical if killing fails
    console.log(
      `[Info] Failed to kill GUI process logioptionsplus: ${error.message}`
    );
  }
}

/**
 * Wait for element to be visible and click it
 * @param {import('puppeteer-core').Page} page - Puppeteer page object
 * @param {string} selector - CSS selector
 * @param {string} stepName - Step name for logging
 */
async function waitAndClick(page, selector, stepName) {
  console.log(`[Info] Starting to click ${stepName} (${selector})`);
  try {
    // Wait for element to be visible with timeout
    await page.waitForSelector(selector, {
      visible: true,
      timeout: ACTION_TIMEOUT,
    });
    await page.click(selector);
    console.log(`[Info] Successfully clicked ${stepName} (${selector})`);

    // Wait for UI to update, avoiding too fast consecutive operations
    await new Promise((resolve) => setTimeout(resolve, 200));
  } catch (error) {
    console.log(
      `[Error] Failed to click ${stepName} (${selector}): ${error.message}`
    );
    throw error;
  }
}

/**
 * Wait for debug port to be available
 * @param {number} port - Debug port number
 * @param {number} maxRetries - Maximum retry attempts
 * @returns {Promise<string>} WebSocket URL
 */
async function waitForDebugPort(port, maxRetries = 15) {
  for (let i = 0; i < maxRetries; i++) {
    try {
      const wsUrl = await new Promise((resolve, reject) => {
        const timeout = setTimeout(() => {
          reject(new Error("Request timeout"));
        }, 2000);

        http
          .get(`http://127.0.0.1:${port}/json/version`, (res) => {
            clearTimeout(timeout);
            let data = "";
            res.on("data", (chunk) => (data += chunk));
            res.on("end", () => {
              try {
                const parsed = JSON.parse(data);
                resolve(parsed.webSocketDebuggerUrl);
              } catch (parseError) {
                reject(
                  new Error(`Failed to parse response: ${parseError.message}`)
                );
              }
            });
          })
          .on("error", (error) => {
            clearTimeout(timeout);
            reject(error);
          });
      });

      console.log(`[Info] Successfully got WebSocket URL on attempt ${i + 1}`);
      return wsUrl;
    } catch (error) {
      console.log(
        `[Info] Attempt ${i + 1}/${maxRetries} failed: ${error.message}`
      );
      if (i === maxRetries - 1) {
        throw new Error(
          `Failed to connect to debug port after ${maxRetries} attempts`
        );
      }
      // Wait 1 second before retry
      await new Promise((resolve) => setTimeout(resolve, 1000));
    }
  }
}

/**
 * Check current scroll mode and toggle smooth scrolling accordingly
 * @param {import('puppeteer-core').Page} page - Puppeteer page object
 */
async function checkScrollModeAndToggleSmoothScrolling(page) {
  try {
    // Check current scroll mode
    const currentScrollMode = await page.evaluate(() => {
      const checkedRadio = document.querySelector(
        'input[name="scroll-mode"]:checked'
      );
      return checkedRadio ? checkedRadio.value : null;
    });

    console.log(`[Info] Current scroll mode: ${currentScrollMode}`);

    if (currentScrollMode === "freeSpin") {
      // Switch to ratchet and turn off smooth scrolling
      console.log(
        "[Info] Switching from freeSpin to ratchet and turning off smooth scrolling"
      );

      // Click ratchet radio button
      await waitAndClick(page, "#radio-button-ratchet", "Ratchet mode");

      // Check if smooth scrolling is enabled, if so, disable it
      const isSmoothScrollingEnabled = await page.evaluate(() => {
        const checkbox = document.querySelector("#smooth-scrolling");
        return checkbox ? checkbox.checked : false;
      });

      console.log(
        `[Info] Current smooth scrolling state: ${isSmoothScrollingEnabled}`
      );

      if (isSmoothScrollingEnabled) {
        await waitAndClick(
          page,
          "#toggle-button-smooth-scrolling",
          "Smooth Scrolling (disable)"
        );
      }
    } else {
      // Switch to freeSpin and turn on smooth scrolling
      console.log(
        "[Info] Switching to freeSpin and turning on smooth scrolling"
      );

      // Click freeSpin radio button
      await waitAndClick(page, "#radio-button-freeSpin", "Free spin mode");

      // Check if smooth scrolling is disabled, if so, enable it
      const isSmoothScrollingEnabled = await page.evaluate(() => {
        const checkbox = document.querySelector("#smooth-scrolling");
        return checkbox ? checkbox.checked : false;
      });

      console.log(
        `[Info] Current smooth scrolling state: ${isSmoothScrollingEnabled}`
      );

      if (!isSmoothScrollingEnabled) {
        await waitAndClick(
          page,
          "#toggle-button-smooth-scrolling",
          "Smooth Scrolling (enable)"
        );
      }
    }
  } catch (error) {
    console.error(
      `[Error] Failed to check scroll mode and toggle smooth scrolling: ${error.message}`
    );
    throw error;
  }
}

/**
 * Main function: Start Logi Options Plus application and connect to it
 */
async function main() {
  let browser;

  try {
    // 1. Cleanup Phase: Kill any existing Logi Options processes
    console.log("[Info] === Phase 1: Cleanup ===");
    await killLogiOptionsPlus();

    // 2. Launch Phase: Start Logi Options+ application
    console.log("[Info] === Phase 2: Starting Application ===");
    console.log(`[Info] Starting Logi Options+...`);

    const logiProcess = spawn("/usr/bin/open", [
      "-g", // Don't activate the window to the front
      "-n", // Start a new instance
      "-a",
      LOGI_APP_BUNDLE_PATH, // Specify the application bundle path
      "--args", // The following are arguments passed to Logi Options+
      `--remote-debugging-port=${DEBUGGING_PORT}`,
      "--disable-renderer-backgrounding", // Disable backgrounding of renderer processes
      "--disable-backgrounding-occluded-windows", // Don't treat occluded windows as background
      "--disable-background-timer-throttling", // Disable background timer throttling
    ]);

    // Listen to process output for debugging
    logiProcess.stdout?.on("data", (data) =>
      console.log(`[Logi App] ${data.toString().trim()}`)
    );
    logiProcess.stderr?.on("data", (data) =>
      console.error(`[Logi App stderr] ${data.toString().trim()}`)
    );

    // 3. Connection Phase: Wait for application to start and get debug port
    console.log("[Info] === Phase 3: Connecting to Application ===");
    console.log(`[Info] Waiting for Logi Options+ to start...`);
    await new Promise((resolve) => setTimeout(resolve, 4000));

    const wsUrl = await waitForDebugPort(DEBUGGING_PORT);

    console.log("[Info] Connecting Puppeteer to WebSocket...");
    browser = await puppeteer.connect({
      browserWSEndpoint: wsUrl,
      defaultViewport: null,
    });

    // Find main page (excluding DevTools pages)
    const pages = await browser.pages();
    const page = pages.find(
      (p) => p.url() && !p.url().startsWith("devtools://")
    );
    if (!page) {
      throw new Error("Failed to find the main page of Logi Options+");
    }
    console.log(
      `[Info] Successfully connected to the main page: ${page.url()}`
    );

    // 4. Automation Phase: Execute UI automation operations
    console.log("[Info] === Phase 4: Automation ===");
    console.log("[Info] Starting automation sequence...");

    // Select MX Master 3S device
    await waitAndClick(
      page,
      "#device-list-device-item-image[device='MX Master 3S']",
      "MX Master 3S"
    );

    // Navigate to Point and Scroll tab
    await waitAndClick(
      page,
      "#featurecontent-tabnav-pointandscroll",
      "Point and Scroll"
    );

    // Open mouse scroll wheel settings
    await waitAndClick(
      page,
      "#assignment-button-mouse_scroll_wheel_settings",
      "Mouse Scroll Wheel Settings"
    );

    // Check current scroll mode and toggle smooth scrolling accordingly
    await checkScrollModeAndToggleSmoothScrolling(page);
  } catch (error) {
    console.error(`[Error] Automation failed: ${error.message}`);
    console.error(`[Error] Stack trace: ${error.stack}`);
    process.exit(1);
  } finally {
    // 5. Cleanup Phase: Disconnect and clean up resources
    console.log("[Info] === Phase 5: Cleanup ===");
    if (browser) {
      try {
        await browser.disconnect();
        console.log("[Info] Successfully disconnected from browser");
      } catch (error) {
        console.error(
          `[Error] Failed to disconnect from browser: ${error.message}`
        );
      }
    }

    // Clean up Logi Options+ process
    await killLogiOptionsPlus();
    console.log("[Info] Automation script completed");
  }
}

// Program entry point
main();

Finally, I used a macOS Shortcut to run the script and added it to the menu bar. Now I can toggle it quickly.

shortcuts.png


Last modified on 2025-07-05

Git Version: a962d3e