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

Applescript click into text field

Hello,


I've just started learning AppleScript and my first task is to install a network printer after the pkg has already been installed (no ppd file available). Here's my script so far:

tell application "AddPrinter" to activate

tell application "System Events"

tell process "AddPrinter"

tell window 1 -- or “window 1”

click button "IP" of toolbar 1 -- or “button 3”

tell group 1 of group 1

delay 1

keystroke ip_address

end tell

delay 1

tell group 2 of group 1

set value of text field 1 to copier_name

set value of text field 2 to copier_location

end tell

end tell

end tell

end tell

I'm having an extra hard time getting the script to click in the Address field of the window. It simply "dings" and moves on, or I should say it does nothing. If I set delay to 4 seconds or something to give me some time and manually click the Address field then the script will continue. I've tried set focused of text field 1 to true, that did not work, I've tried click as well, that did not work either. How do I put the mouse cursor in that field so keystroke would work?


Thank you!

iMac (24-inch Early 2008), OS X El Capitan (10.11.1), null

Posted on Nov 19, 2015 12:27 PM

Reply
Question marked as Best reply

Posted on Nov 19, 2015 2:08 PM

Hello,


Try this, it works here:


tell application "AddPrinter"
    launch
    activate
end tell
tell application "System Events"
    tell process "AddPrinter"
        set frontmost to true
        delay 1
        tell window 1
            click button "IP" of toolbar 1
            tell group 1 of group 1
                delay 1
                set focused of text field 1 to true
                keystroke ip_address
            end tell
        end tell
    end tell
end tell
7 replies
Question marked as Best reply

Nov 19, 2015 2:08 PM in response to Yonko

Hello,


Try this, it works here:


tell application "AddPrinter"
    launch
    activate
end tell
tell application "System Events"
    tell process "AddPrinter"
        set frontmost to true
        delay 1
        tell window 1
            click button "IP" of toolbar 1
            tell group 1 of group 1
                delay 1
                set focused of text field 1 to true
                keystroke ip_address
            end tell
        end tell
    end tell
end tell

Feb 8, 2016 6:30 AM in response to viggi47

Hi,


viggi47 wrote:


This code is working fine for me and after selection of printer

i am not able to click on "add" button , would you please help me on this.....🙂


This button is an element of the window, so


tell application "System Events"

tell process "AddPrinter"

set frontmost to true

delay 1

tell window 1

click button "IP" of toolbar 1

tell group 1 of group 1

delay 1

set focused of text field 1 to true

keystroke ip_address

delay 4

end tell

click button "Add"

end tell

end tell

end tell

Applescript click into text field

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