HP’s scanning software is horrendous in OS X. They package scanner drivers for each scanner with some iteration of their HP Scan Pro software. Why they don’t just have one version of HP Scan Pro, and drivers for each scanner to download is beyond me. Want to get software for three scanners? Download three 100 MB packages each containing different versions of the same program! Then, when you install, you don’t even get to pick a destination. Apparently HP knows where I want my applications. On top of that, HP uses generic filenames for preference files. So when you install a second scanner package, it will not only want to overwrite the scanning software designed to work with scanner #1 (located in the again generically named “Hewlett Packard” folder), but also scanner #1’s preference files.

What if I have one scanner at work and one at home? Or in my case, I want to make a system image for a lab that has a few different scanners and I don’t want to have to keep track of which scanner is plugged into which computer and what HP scanner package needs to be installed. Here is how I solved this using Applescript.

  1. I installed the software for scanner #1 (hp 3970) and verified everything worked.
  2. I created a folder called HPPrefs in /Library
  3. I looked in ~/Library/Preferences to see which files were added by the installer, and moved them into a folder called hp3970 within the HPPrefs folder.
  4. I renamed the Hewlett Packard folder to HP3970 in /Applications so it would not be overwritten when I ran the second scanner install.
  5. I then repeated this process for the other two software packages.

Now I have three folders in /Applications called HP3970, HP4570c, and HP4370.

multiscanner1.jpg

I also have a folder (/Library/HPPrefs) that contains three folders hp3970, hp4570c, and hp4370. These folders contain the proper preference files from each of the installs. At this point, all I need is a script that will do the following:

  1. Delete any current HP scanning preference files in ~/Library/Preferences
  2. Prompt the user to define the currently installed scanner
  3. Copy the proper preferences based on the user input from /Library/HPPrefs into ~/Library/Preferences
  4. Launch the proper version of scan pro

The code:

-- Set variables to the the name of the HD and the current user
tell application "Finder"
	set HDName to name of startup disk
	set myname to do shell script "whoami"
end tell

-- 1.) Delete any current HP scanning preference files in ~/Library/Preferences
do shell script "rm -Rf /Users/" & myname & "/Library/Preferences/HP*"
do shell script "rm -Rf /Users/" & myname & "/Library/Preferences/com.hp*"

-- 2.) Prompt the user to define the currently installed scanner
display dialog "Which scanner model is attached to this computer?" buttons {"hp3970", "hp4570c", "hp4370"}
set model to button returned of result

-- 3.) Copy the proper preferences based on the user input from /Library/HPPrefs into ~/Library/Preferences
tell application "Finder" to duplicate items in folder (HDName & ":Library:HPPrefs:" & model) to folder (HDName & ":Users:student:Library:Preferences") replacing yes

-- Delay 3 secs for the file copy
delay 3

-- 4.) Launch the proper version of scan pro
if model = "hp3970" then
	tell application "Finder"
		open HDName & ":Applications:HP3970:HP Scan Pro.app"
	end tell
else if model = "hp4570c" then
	tell application "Finder"
		open HDName & ":Applications:HP4570c:HP Scan Pro.app"
	end tell
else if model = "hp4370" then
	tell application "Finder"
		open HDName & ":Applications:HP4370:HP Scan Pro.app"
	end tell
end if

I saved the script as an application (No startup screen, run only) gave it an applicable icon and tossed it in the dock. Now the user just clicks the app, picks the scanner, and scans away!

multiscanner2.jpg

Leave a Reply

Posted in Apple No Comments leaf