JMichaelTX
10/12/2011 - 3:35 PM

If you use ScanSnap, you can have GUI Scripting automate the process of switching among your scan profiles ...

If you use ScanSnap, you can have GUI Scripting automate the process of switching among your scan profiles ...

-- Launches ScanSnap Manager, if necessary. Opens the ScanSnap Manager settings window,
-- changes to named profile, applies changes, and closes the window
-- Example:
SwitchToProfile("Standard")

on SaveActiveApplication()
	return application
end SaveActiveApplication

on OpenOptionsWindow()
	
	tell application "System Events"
		tell application process "ScanSnap Manager"
			activate
			set isWindowOpen to false
			repeat while isWindowOpen is false
				try
					window 1
					set isWindowOpen to true
				on error
					tell menu 1 of menu bar item "ScanSnap Manager" of menu bar 1
						click menu item "Settings..."
					end tell
					delay 0.5
				end try
			end repeat
			
		end tell
	end tell
	
end OpenOptionsWindow

on ApplyChangesAndCloseOptionsWindow()
	
	tell application "System Events"
		tell application process "ScanSnap Manager"
			-- Apply
			click button "Apply" of window 1
			-- Close
			click button 1 of group 2 of window 1
		end tell
		
	end tell
	
end ApplyChangesAndCloseOptionsWindow

-- Our definition of "Is Running" is that it has the menu item available for opening the settings window … we wait for that
-- because if we just wait for it to be "launched" it may still be setting up ...
on EnsureScanSnapRunning()
	tell application "System Events"
		launch application "ScanSnap Manager"
		set isLaunched to false
		repeat while isLaunched is false
			try
				menu 1 of menu bar item "ScanSnap Manager" of menu bar 1 of application process "ScanSnap Manager"
				set isLaunched to true
			end try
		end repeat
	end tell
	
end EnsureScanSnapRunning

on SwitchToProfile(profileName)
	
	EnsureScanSnapRunning()
	
	OpenOptionsWindow()
	
	tell application "System Events"
		tell application process "ScanSnap Manager"
			tell (pop up button 1 of group 2 of window 1)
				click
				
				tell menu 1
					try
						click menu item profileName
					on error
						cancel
						display dialog "Can't find the target menu item \"" & profileName & "\", please make sure you have a profile set up with this name, or modify the script to match the desired name"
					end try
					
				end tell
			end tell
		end tell
	end tell
	
	ApplyChangesAndCloseOptionsWindow()
	
end SwitchToProfile