I have a Canon TR7500 series printer/scanner. It has an Auto Document Feeder, which works ok, but sometimes I still want to name things while scanning on the flatbed one at a time. I had to modify my previous script for an old HP scanner for the new setup in Mac OS X Catalina (10.15).
The scanning app is similar to Image Capture in previous versions of Apple's OS X, but is accessed via the System Preferences Printers & Scanners panel. The name of the app in the AppleScript commands below will have to be modified. e.g. "Canon TR7500 series" would be replaced by whatever the app name is.
I made a shell script to execute the scan so I could use Termius (a terminal app for iPhone) on an iPhone to log in to my mac via ssh and type "scan" to start scanning.
scan document-20200524-page-1
results in this file:
scan document-20200524-page-1.tiff
or if that file already exists:
scan document-20200524-page-1 1.tiff
Another later version includes using python to drag the scan window to the right 100 pixels. Scan script using AppleScript's System Events, shell script and python.
#!/bin/sh
args=$@
`osascript -e 'tell application "System Events" to tell process "Canon TR7500 series" to set focused of text field 1 of scroll area 1 of window "Scanner" to true'`
setname=`osascript -e "tell application \"System Events\" to tell process \"Canon TR7500 series\" to set value of text field 1 of scroll area 1 of window \"Scanner\" to \"$args\""`
`osascript -e 'tell application "System Events" to tell process "Canon TR7500 series" to confirm text field 1 of scroll area 1 of window "Scanner"'`
`osascript -e 'tell application "System Events" to tell process "Canon TR7500 series" to set focused of text field 1 of scroll area 1 of window "Scanner" to false'`
interval=2
timeout=120
scanning=true
i=0
btn=`osascript -e 'tell application "System Events" to tell process "Canon TR7500 series" to return name of button 3 of window "Scanner"'`
if [ "$btn" == "Scan" ]; then
btn=`osascript -e 'tell application "System Events" to tell process "Canon TR7500 series" to click button "Scan" of window "Scanner"'`
else
echo "Not ready to Scan, 'Scan' button shows '$btn'. Check scanner and try again."
exit 1
fi
while $scanning; do
sleep $interval
i=`expr $i + $interval`
btn=`osascript -e 'tell application "System Events" to tell process "Canon TR7500 series" to return name of button 3 of window "Scanner"'`
if [ "$btn" == "Cancel" ]; then
printf "Scanning... $i\r"
else
echo "Scanned in approximately $i seconds."
scanning=false
fi
if [ $i -gt $timeout ]; then
echo "Took over $timeout seconds. Is something wrong?"
scanning=false
fi
done
-- linux_macosx_hints_etc page