From 43526c4d92528568c97c83f27fc24f4f19263a1a Mon Sep 17 00:00:00 2001 From: Jason Koh Date: Mon, 4 May 2020 15:40:48 -0700 Subject: [PATCH] Slightly updated probing logic based on Jason's code. Signed-off-by: Jesse Vincent --- bin/find-device-port-macos | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/bin/find-device-port-macos b/bin/find-device-port-macos index 11b7e366..82778ff6 100644 --- a/bin/find-device-port-macos +++ b/bin/find-device-port-macos @@ -55,15 +55,24 @@ sub try_for_raw_serialnum { # High Sierra sometimes has a mismatch between the serial number and the device # filename. I'm not sure why, but system_profiler has a serial number ending in "E", # whereas the device filename ends in "1". In fact, when I change HID.getShortName() - # to return "kbio02", the final character is replaced with a "1", so we should do the - # same here. If the serial number doesn't end in a digit, however, we may want to append - # rather than replace the last character with a 1. + # to return "kbio02", the final character is replaced with a "1". + if ($serial_port_name =~ /\d$/) { - $serial_port_name =~ s/.$/1/; + chop $serial_port_name; + exit_with_port_if_exists($serial_port_name . "1"); } else { - $serial_port_name .= "1"; + # If the serial port name doesn't end with a digit, try -appending- rather than replacing + # the last character of the port name + exit_with_port_if_exists($serial_port_name . "1"); + + # and if that didn't work, try replacing the last character with a "1" anyway. + # Jason Koh reports that he saw this behavior as required on Catalina in May 2020. + + chop $serial_port_name; + exit_with_port_if_exists($serial_port_name . "1"); } - exit_with_port_if_exists($serial_port_name); + + } sub try_for_location_id {