Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Twain Sane and Mac OS 10.7 Lion

I think suitable to put here a following subject of the similar topic in the Mac OS 10.6 section.


I try to sum up:


- the Twain Sane interface of Mattias Ellert no longer works properly under Lion. In Graphic Converter, it no more appears. In Image Capture, the Preview button works, but the scan button doesn't work, except perhaps with the text mode and tiff format


- At the time, Mattias Ellert did not announce a 10.7 version of his interface


- MacPorts reports a build failure while trying to build Twain Sane on Lion


- If the SANE drivers are still there (Lion installation on Snow Leopard, not a clean install perhaps), the scanimage command on the Terminal is still working and one may scan an entire A4 document for exemple, and then modify if with somme other software. Here is a code, for example:


/usr/local/bin/scanimage --mode Color --format tiff --resolution 600 > ~/scanimage.tiff


- The Snac small software makes it more easy to choose the parameters of the scanimage command, with a little graphic interface. There are less possibilities than in Twain Sane Interface, but though announced for Tiger, it seems to still works with Lion, perhaps after a new intall.

Posted on Aug 16, 2011 4:58 AM

Reply
Question marked as Best reply

Posted on Aug 17, 2011 1:33 PM

After the 10.7.1 update of Lion, I tried once more to scan.


First I tried directly Image Capture. I realized that when I used the button "Mask the details", the scanning worked, only with an A4 and US Letter option, and produced a jpeg document witch opened in Apple Preview at the second time (curiously, not the first time I tried). No resize is available. 10.7.1 improvement or did I just forget to try the button ?


Then I tried with the GraphicConverter menu File -> Scan with Image Capture . There is the preview, but as well with or without the details, with the option "Scan to GraphicConverter", there is an error message "Dossier d'importation non disponible" in the French version (No available importation file). Still nothing at all happening while trying "Select the Twain Source" (though Image Capture recognize it) nor "Scan with Twain Sane". Perhaps because there is no more Rosetta and it should be needed ?

39 replies

Aug 15, 2012 2:14 PM in response to actiyo

After some more applescripting, i got to the following script... Regards, wimdmr


--scan with sane 3.3 by wimdmr

--declaring the variables

global theWay, theWidth, theHeight, theFormat, theRes, theMode, theDepth, theWidthList, theHeightList, theResList, theModeList, theDepthList, fromTop, fromLeft, theFile, theFileRaw, theScript

set theWayList to {"Select settings manually", "Document A4", "Document A3", "Document A3 landscape", "Photo A4", "Photo A3", "Photo A3 landscape"}

set theWidthList to {50, 100, 148, 210}

set theHeightList to {50, 100, 148, 210, 297}

set theFormatList to {"tiff", "pnm"}

set theResList to {150, 300, 600, 1200}

set theModeList to {"Color", "Gray", "Lineart"}

set theDepthList to {8, 16}

set fromTop to 0

set fromLeft to 0

set theFormat to "tiff"

set ajaj to "User cancelled."

--choosing options with dialogs

set theWay to choose from list theWayList with prompt "Select Scan options" default items {"Document A4"} OK button name "Continue"

if theWay as string is equal to "Select settings manually" then

try

set theWidth to choose from listtheWidthListwith prompt "This wide (mm):" default items (last item of theWidthList) OK button name "OK"


checkInput(theWidth)

set theHeight to choose from listtheHeightListwith prompt "This high (mm):" default items (last item of theHeightList) OK button name "OK"


checkInput(theHeight)

set theFormat to choose from listtheFormatListwith prompt "choose format" default items (first item of theFormatList) OK button name "OK"


checkInput(theFormat)

set theRes to choose from list theResList with prompt "with scan resolution (dpi):" default items (first item of theResList) OK button name "OK"


checkInput(theRes)

set theMode to choose from listtheModeListwith prompt "Choose mode" default items (second item of theModeList) OK button name "OK"


checkInput(theMode)

if theMode as string is equal to "Lineart" then

set theDepth to 0 -- no depth when lineart selected

else

set theDepth to choose from list theDepthList with prompt "with depth (bits):" default items (first item of theDepthList) OK button name "OK"


checkInput(theDepth)

end if



setFileAndScriptAndRun()

on error optionsError

display alert optionsError message "You escaped during setting the options." & return & "Aborting scan…" & return & "Source: optionsError"

end try

else if theWay as string is equal to "Document A4" then

setOptions(210, 297, 150, "Gray", 16)

else if theWay as string is equal to "Document A3" then

setOptions(148, 210, 150, "Gray", 16)

else if theWay as string is equal to "Document A3 landscape" then

setOptions(210, 148, 150, "Gray", 16)

else if theWay as string is equal to "Photo A4" then

setOptions(210, 297, 600, "Color", 16)

else if theWay as string is equal to "Photo A3" then

setOptions(148, 210, 600, "Color", 16)

else if theWay as string is equal to "Photo A3 landscape" then

setOptions(210, 148, 600, "Color", 16)

else --

try


checkInput(theWay)

on error theWayFalse

display alert theWayFalse message "No scan selected." & return & "Now quitting…" & return & "Source: theWayFalse" buttons {"I Know"}

end try

end if


--handlers


to setOptions(aWidth, aHeight, aRes, aMode, aDepth)

set theWidth to aWidth

set theHeight to aHeight

set theRes to aRes

set theMode to aMode

set theDepth to aDepth


setFileAndScriptAndRun()

end setOptions

to checkInput(inputValue)

if inputValue is false then

error number -128 --user cancelled.

end if

end checkInput

to setFileAndScriptAndRun()

try

set theFileRaw to (choose file name with prompt ("Select location and file name.") default name "Scanimage-1" default location (path to downloads folder))

set theFile to quoted form of POSIX path of theFileRaw & "." & theFormat

if theMode as string is equal to "Lineart" then

set theScript to "/usr/local/bin/scanimage -t " & fromTop & " -l " & fromLeft & " -x " & theWidth & " -y " & theHeight & " --format " & theFormat & " --mode " & theMode & " --resolution " & theRes & " > " & theFile -- no depth when lineart selected

else

set theScript to "/usr/local/bin/scanimage -t " & fromTop & " -l " & fromLeft & " -x " & theWidth & " -y " & theHeight & " --format " & theFormat & " --mode " & theMode & " --resolution " & theRes & " --depth " & theDepth & " > " & theFile

end if


executeTask("sim")

on error fileError

display alert fileError message "No file selected." & return & "Source: fileError."

end try

end setFileAndScriptAndRun

to executeTask(how) --sim or run

if how as string is equal to "sim" then


theScript

else if how as string is equal to "run" then


do shell scripttheScript

tell application "Finder"

open (theFileRaw as string) & "." & theFormat as string

end tell

end if

end executeTask

Aug 16, 2012 12:41 AM in response to wimdmr

Sorry the previous script is only simulating, here is the running script:


--scan with sane 3.4 by wimdmr

--declaring the variables

global theWay, theWidth, theHeight, theFormat, theRes, theMode, theDepth, theWidthList, theHeightList, theResList, theModeList, theDepthList, fromTop, fromLeft, theFile, theFileRaw, theScript

set theWayList to {"Select settings manually", "Document A4", "Document A3", "Document A3 landscape", "Photo A4", "Photo A3", "Photo A3 landscape"}

set theWidthList to {50, 100, 148, 210}

set theHeightList to {50, 100, 148, 210, 297}

set theFormatList to {"tiff", "pnm"}

set theResList to {150, 300, 600, 1200}

set theModeList to {"Color", "Gray", "Lineart"}

set theDepthList to {8, 16}

set fromTop to 0

set fromLeft to 0

set theFormat to "tiff"

set ajaj to "User cancelled."

--choosing options with dialogs

set theWay to choose from list theWayList with prompt "Select Scan options" default items {"Document A4"} OK button name "Continue"

if theWay as string is equal to "Select settings manually" then

try

set theWidth to choose from listtheWidthListwith prompt "This wide (mm):" default items (last item of theWidthList) OK button name "OK"


checkInput(theWidth)

set theHeight to choose from listtheHeightListwith prompt "This high (mm):" default items (last item of theHeightList) OK button name "OK"


checkInput(theHeight)

set theFormat to choose from listtheFormatListwith prompt "choose format" default items (first item of theFormatList) OK button name "OK"


checkInput(theFormat)

set theRes to choose from list theResList with prompt "with scan resolution (dpi):" default items (first item of theResList) OK button name "OK"


checkInput(theRes)

set theMode to choose from listtheModeListwith prompt "Choose mode" default items (second item of theModeList) OK button name "OK"


checkInput(theMode)

if theMode as string is equal to "Lineart" then

set theDepth to 0 -- no depth when lineart selected

else

set theDepth to choose from list theDepthList with prompt "with depth (bits):" default items (first item of theDepthList) OK button name "OK"


checkInput(theDepth)

end if



setFileAndScriptAndRun()

on error optionsError

display alert optionsError message "You escaped during setting the options." & return & "Aborting scan…" & return & "Source: optionsError"

end try

else if theWay as string is equal to "Document A4" then

setOptions(210, 297, 150, "Gray", 16)

else if theWay as string is equal to "Document A3" then

setOptions(148, 210, 150, "Gray", 16)

else if theWay as string is equal to "Document A3 landscape" then

setOptions(210, 148, 150, "Gray", 16)

else if theWay as string is equal to "Photo A4" then

setOptions(210, 297, 600, "Color", 16)

else if theWay as string is equal to "Photo A3" then

setOptions(148, 210, 600, "Color", 16)

else if theWay as string is equal to "Photo A3 landscape" then

setOptions(210, 148, 600, "Color", 16)

else --

try


checkInput(theWay)

on error theWayFalse

display alert theWayFalse message "No scan selected." & return & "Now quitting…" & return & "Source: theWayFalse" buttons {"I Know"}

end try

end if


--handlers


to setOptions(aWidth, aHeight, aRes, aMode, aDepth)

set theWidth to aWidth

set theHeight to aHeight

set theRes to aRes

set theMode to aMode

set theDepth to aDepth


setFileAndScriptAndRun()

end setOptions

to checkInput(inputValue)

if inputValue is false then

error number -128 --user cancelled.

end if

end checkInput

to setFileAndScriptAndRun()

try

set theFileRaw to (choose file name with prompt ("Select location and file name.") default name "Scanimage-1" default location (path to downloads folder))

set theFile to quoted form of POSIX path of theFileRaw & "." & theFormat

if theMode as string is equal to "Lineart" then

set theScript to "/usr/local/bin/scanimage -t " & fromTop & " -l " & fromLeft & " -x " & theWidth & " -y " & theHeight & " --format " & theFormat & " --mode " & theMode & " --resolution " & theRes & " > " & theFile -- no depth when lineart selected

else

set theScript to "/usr/local/bin/scanimage -t " & fromTop & " -l " & fromLeft & " -x " & theWidth & " -y " & theHeight & " --format " & theFormat & " --mode " & theMode & " --resolution " & theRes & " --depth " & theDepth & " > " & theFile

end if


executeTask("run")

on error fileError

display alert fileError message "No file selected." & return & "Source: fileError."

end try

end setFileAndScriptAndRun

to executeTask(how) --sim or run

if how as string is equal to "sim" then


theScript

else if how as string is equal to "run" then


do shell scripttheScript

tell application "Finder"

open (theFileRaw as string) & "." & theFormat as string

end tell

end if

end executeTask

Dec 2, 2012 1:01 AM in response to boninmi

A while ago messed with wimdmr's applescript and added the ability to save as jpg, png and pdf.

Also this script has a choice to collate all the scans - ie create a multipage pdf.

It saves each page to /var/tmp/ and converts the final image to the user's choice of dir.


It could do with some tidying up - I'd love to merge this with wimdmr's latest version... but here it is anyway:

Cheers


--

set fromTop to 0

set fromLeft to 0

set multipdf to (button returned of (display dialog "Multpage pdf?" buttons {"Yes", "No"} default button (2)))


set theWidth to choose from list {"50", "100", "150", "200", "215"} with prompt "Width (mm):" default items {"215"} OK button name "OK" --215

set theHeight to choose from list {"50", "100", "150", "200", "297"} with prompt "Height (mm):" default items {"297"} OK button name "OK" --297


if (multipdf = "yes") then

set theFormat to "pdf"

else

set theFormat to (button returned of (display dialog "Choose file format to be used:" buttons {"jpeg", "pdf", "png"} default button 1))

end if


set theExtension to theFormat

if (theFormat = "jpeg") then set theExtension to "jpg"


set theRes to choose from list {"100", "150", "200", "300", "600", "1200"} with prompt "with scan resolution:" default items {"150"} OK button name "OK"

set theMode to (button returned of (display dialog "and Color scheme Specify Colors" buttons {"Color", "Gray", "Lineart"} default button 2))

--

set pdfArgs to ""


set theFile to quoted form of POSIX path of (choose file name with prompt ("Choose file name: (no spaces)") default name "Scanimage-1" default location (path to desktop folder))


repeat

set timestamp to do shell script "date +%s"

set tmpFile to "/var/tmp/scan_" & timestamp

set theScript to "/usr/local/bin/scanimage -t " & fromTop & " -l " & fromLeft & " -x " & theWidth & " -y " & theHeight & " --format tiff " & " --mode " & theMode & " --resolution " & theRes & " > " & tmpFile & ".tiff"


-- scan


do shell scripttheScript


-- convert image

set theScript to "/usr/bin/sips -s format " & theFormat & " " & tmpFile & ".tiff" & " --out " & tmpFile & "." & theExtension


do shell scripttheScript


-- delete the tmp scan

do shell script "rm " & tmpFile & ".tiff"


set pdfArgs to pdfArgs & " " & tmpFile & "." & theExtension



-- are we done?

if (multipdf = "no") then

set nextScan to "Finished"

else

display dialog "Place next page..." buttons {"Scan", "Finished"} default button "Scan"

set nextScan to button returned of the result

end if

if nextScan = "Finished" then exit repeat


end repeat


-- combine the pdf if required

if (multipdf = "yes") then

do shell script "\"/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py\" -o " & theFile & "." & theExtension & pdfArgs


do shell script "rm " & pdfArgs

else


do shell script "cp " & tmpFile & "." & theExtension & " " & theFile & "." & theExtension

do shell script "rm " & tmpFile & "." & theExtension

end if

Dec 2, 2012 1:55 AM in response to timolooch

Excellent scripts from wimdmr (the simple one) and timolooch. I will use them both depending on what I need to do. I mostly use the one of wimdmr because I can only use PDF OCR X.app on one page. The one of timolooch will save lots of time if I only need photocopies ...
I have OS X 10.8.2. ancd can still use my old CanoScan N670U!

Twain Sane and Mac OS 10.7 Lion

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.