From 430b159913ad1287c52a2d2d72c1cd5800a599a2 Mon Sep 17 00:00:00 2001 From: Jason Koh Date: Mon, 4 May 2020 15:24:27 -0700 Subject: [PATCH] Tweak location-based detection logic Signed-off-by: Jesse Vincent --- bin/find-device-port-macos | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/bin/find-device-port-macos b/bin/find-device-port-macos index b33a1e82..11b7e366 100644 --- a/bin/find-device-port-macos +++ b/bin/find-device-port-macos @@ -69,10 +69,13 @@ sub try_for_raw_serialnum { sub try_for_location_id { my $location_id = shift; - # Here, also, the final character is always a "1", so if macOS ever stops doing that, this - # will need an update, as well. - my $loc = substr($location_id, 2, 3); - exit_with_port_if_exists("/dev/cu.usbmodem" . $loc . 1); + # macOS truncates the string of "0"s from the right of the location id. + # Here, also, the final character is an appended "1", so if macOS ever stops doing that, + # this will need an update, as well. + if ($location_id =~ /0x(\d+?)0*\b/) { + my $loc = $1; + exit_with_port_if_exists("/dev/cu.usbmodem" . $loc . "1"); + } } sub try_for_sn_prefix {