Unexpected behavior – calling `get_location` outputs old location

Describe the bug

Today I traveled roughly 370 km by car between two European cities (both in the same timezone). I use a JXA script to obtain my current latitude and longitude, which are then used to display my location in the menubar via reverse geocoding. Before my trip, while connected to my home WiFi network, the location was correctly displayed. However, during the trip when I switched to my iPhone hotspot, the menubar continued showing my old location. Even after reconnecting to my home WiFi at my final destination, the script (when run either in Script Editor or via the command line) still outputted the old coordinates. Only after restarting BetterTouchTool does the script return the updated, correct location.

Context

• I wrote the following JXA script to fetch my current geolocation:

ObjC.import('stdlib');

function run(argv) {
  // Determine if running from Terminal (native array) or Script Editor
  const formatAsJSON = false; // Set to true in Script Editor to simulate '--json'
  argv = Array.isArray(argv) ? argv : (formatAsJSON ? ['--json'] : []);

  const outputJson = argv.includes('--json');
  const btt = Application("BetterTouchTool");
  const location = btt.get_location();

  if (outputJson) {
    const parts = location.split(',');
    return JSON.stringify({
      lat: parts[0].trim(),
      long: parts[1].trim()
    });
  } else {
    return location;
  }
}

• The output of this script is used to update my menubar with current location data (via reverse geocoding).

Expected Behavior:

The script should always output the current geolocation, regardless of any network change.

Actual Behavior:

The script outputs stale location coordinates until BetterTouchTool is restarted.


Affected input device (e.g. MacBook Trackpad, Magic Mouse/Trackpad, Touch Bar, etc.):

BetterTouchTool Scripting Interface


Device information:

Device: MacBook Pro (14-inch, 2021)

macOS: 15.4 (24E248)

BTT Version: 5.301 (2025040403)

Alpha: 0 update(s) behind latest Alpha version 5.301 (2025040403).

Regular: Installed version is ahead of latest Regular version 5.140.


Additional information (e.g. crash logs, related issues, etc.):

BTT Crash – WiFi turned off triggers get_location()

Variable: the currently connected WiFi does not update when leaving a network

BTT keeps asking permission for location