Trying to input text into application window

At my office we use Minolta network printers, which require a billing code input. I have some users who have to print multiple documents at a time and don’t like having to type in their billing code for every single document. I wanted to automate this process, but came across an error.

Basically, I have a pop up that asks the user their billing code, and I want that input to be copied into the field in the Print manager application. (a third party application called “Equitrac Login Controller”.


display dialog "Choose multiple files by holding Shift and selecting the first and last file you would like." with title "Select Files to Print" 

set theFiles to choose file with multiple selections allowed 

tell application "System Events" 
	display dialog "Enter Billing Code:" default answer ""
	
	set theNumber to text returned of result 
end tell

tell application "Finder"
	print theFiles
end tell

tell application "System Events"
	tell window "WINDOW NAME" of process "APPLICATION NAME"
		set value of text field 1 to theNumber
		click button "OK" of group 2
	end tell
end tell



The error that comes up is:
"Can’t set window “WINDOW NAME” of <> “APPLICATION NAME” of application “System Events” to “####”

Any suggestions?

After the tell application “System Events” you must insert the instruction :
tell process “nameOfTheProcess”

I don’t know the real name of the process.

Is it “Finder” or is it the process really triggered by the print command ? I’m not a sooth sayer and can’t guess that.

Run this script :

display dialog "Choose multiple files by holding Shift and selecting the first and last file you would like." with title "Select Files to Print"

set theFiles to choose file with multiple selections allowed

tell application "System Events"
	display dialog "Enter Billing Code:" default answer ""
	
	set theNumber to text returned of result
	set processBefore to name of processes
end tell

tell application "Finder"
	print theFiles
end tell
tell application "System Events"
	set processAfter to name of processes
end tell
{processBefore, " ------- ", processAfter}

The result will be something like that :

{{“loginwindow”, “maybe2”, “SystemUIServer”, “talagent”, “Dock”, “Finder”, “AirPlayUIAgent”, “DictationIM”, “NotificationCenter”, “com.apple.dock.extra”, “UserEventAgent”, “Folder Actions Dispatcher”, “TISwitcher”, “WacomTabletDriver”, “ASObjC Runner”, “FastScripts”, “XMenu”, “Box SimpleShare”, “SMARTReporter”, “TabletDriver”, “Safari”, “storeagent”, “Mail”, “iTunesHelper”, “iTunes”, “firefox”, “Numbers”, “AppleSpell”, “Activity Monitor”, “AppleScript Editor”, “Mactracker”, “TextEdit”, “Property List Editor”, “WebProcess”, “System Events”, “mdworker”}, " ------- ", {“loginwindow”, “maybe2”, “SystemUIServer”, “talagent”, “Dock”, “Finder”, “AirPlayUIAgent”, “DictationIM”, “NotificationCenter”, “com.apple.dock.extra”, “UserEventAgent”, “Folder Actions Dispatcher”, “TISwitcher”, “WacomTabletDriver”, “ASObjC Runner”, “FastScripts”, “XMenu”, “Box SimpleShare”, “SMARTReporter”, “TabletDriver”, “Safari”, “storeagent”, “Mail”, “iTunesHelper”, “iTunes”, “firefox”, “Numbers”, “AppleSpell”, “Activity Monitor”, “AppleScript Editor”, “Mactracker”, “TextEdit”, “Property List Editor”, “WebProcess”, “System Events”, “mdworker”}}

Comparing the two lists will give you the name of the process which you will have to use to replace the fake nameOfTheProcess.

KOENIG Yvan (VALLAURIS, France) jeudi 19 septembre 2013 21:11:26