klep / scanline

Command line scanning utility for OSX
MIT License
126 stars 23 forks source link

Usability: Need improved error message when scanner in use by another application #47

Open srikantkt opened 5 months ago

srikantkt commented 5 months ago

I needed a tool to specify a different DPI than what the UI offered and this tool saved the day! My environment: MacOS Sonoma 14.4.1

I had a minor issue when I used this tool for the first time. I didn't realize that I also had preview app attempting to import from the scanner. The error message wasn't obvious. See below

➜  ~ scanline -list
Available scanners:
* HP Color LaserJet MFP M283cdw (F8D366)

Done
➜  ~ 
➜  ~ scanline -flatbed -name s_pp.pdf -resolution 100
Error received while attempting to open a session with the scanner.
Failed to scan document.
Done
➜  ~ scanline -flatbed -name s_pp.pdf -resolution 100 -scanner "HP Color LaserJet MFP M283cdw (F8D366)"
Error received while attempting to open a session with the scanner.
Failed to scan document.
Done
➜  ~ scanline -flatbed -name s_pp.pdf -resolution 100 -scanner "HP Color LaserJet MFP M283cdw (F8D366)" -verbose
Browsing for scanners.
Waiting up to 10.0 seconds to find scanners
Added device: {
    UUIDString = "564E4252-5037-5330-3651-6C02E0F8D366";
    autolaunchApplicationPath = "";
    class = ICScannerDevice;
    connectionID = 0x00000000;
    delegate = "<0x0>";
    deviceID = 0x00000000;
    deviceRef = 0x100001f0;
    iconPath = "(null)";
    locationDescription = "HP Color LaserJet MFP M283cdw (F8D366)";
    moduleExecutableArchitecture = 0;
    modulePath = "/System/Library/Image Capture/Devices/AirScanScanner.app";
    moduleVersion = "1.0";
    name = "HP Color LaserJet MFP M283cdw (F8D366)";
    persistentIDString = "564E4252-5037-5330-3651-6C02E0F8D366";
    shared = NO;
    softwareInstallPercentDone = "0.000000";
    transportType = ICTransportTypeTCPIP;
    type = 0x00000402;
}  availableFunctionalUnitTypes  : 
  selectedFunctionalUnit        : (null) <0x0>
  transferMode                  : ICScannerTransferModeFileBased
  downloadsDirectory            : file:///Users/srikant/Pictures/
  documentName                  : Scan
  documentUTI                   : public.tiff

Done searching for scanners
Found scanner: HP Color LaserJet MFP M283cdw (F8D366)
Opening session with scanner
didOpenSessionWithError: The operation couldn’t be completed. (com.apple.imagecapture error 4294967249.)
Error received while attempting to open a session with the scanner.
Failed to scan document.
Done

Once I figured this out and shutdown/closed the preview app and retried, everything worked as expected. I am able to consistently reproduce this issue

  1. Ensure scanner is in use from another application. for ex.,
    • open preview and perform import from scanner operation
    • Printers & Scanners --> select printer/scanner --> Open Scanner
  2. Run scanline from terminal --> error message shown above
  3. Terminate app using scanner (from Step 1)
  4. Run scanline from terminal --> successful scan
klep commented 5 months ago

Glad to hear scanline is working out for you!

I think probably the right fix here is to output the full error code when scanning fails. I don't think scanline itself should attempt to interpret those error codes, since they could have multiple meanings and it's not something a command line tool would typically do. But I agree that it's non-obvious and next time I'm in the code, I'll bump up the log level on the error code.