2

I'm working on an GUI scripting AppleScript that will, for the open FileMaker Pro Advanced document, go to the File menu and select the File Options dialog box, then set some checkbox/radio button and field values.

The dialog box looks like this:

enter image description here

I would like my script to do the following:

  1. tick the "Log in using:" checkbox if it is not already selected
  2. select the "Account Name and Password" radio button if it is not already selected
  3. Enter a value into the "Account:" field
  4. Enter a value into the "Password:" field
  5. Click the OK button

I've got it opening the dialog box but I'm not able to get past setting the checkbox - this is my first time with GUI scripting. I'm using OS X Yosemite 10.10.3.

Here's my script:

-- check that GUI Scripting is available

GUIScripting_status()


-- bring FileMaker Pro Advanced to the front

tell application "FileMaker Pro Advanced"
    activate
end tell


setfmFileOptions()

on click_button(app_name, button_name)
    try
        tell application app_name
            activate
        end tell
        tell application "System Events"
            tell process app_name
                click button button_name of front window
            end tell
        end tell
        return true
    on error error_message
    end try
end click_button


on do_menu(app_name, menu_name, menu_item)
    try
        -- bring the target application to the front
        tell application app_name
            activate
        end tell
        tell application "System Events"
            tell process app_name
                tell menu bar 1
                    tell menu bar item menu_name
                        tell menu menu_name
                            click menu item menu_item
                        end tell
                    end tell
                end tell
            end tell
        end tell
        return true
    on error error_message
        return false
    end try
end do_menu


on setfmFileOptions()

    -- choose the Developer Utilities menu item from the Tools menu of FileMaker Pro Advanced

    do_menu("FileMaker Pro Advanced", "File", "File Options...")


    -- click the "Log in using" checkbox:

    if (exists checkbox "Log in using:" of window 1) is true then
 click checkbox "Log in using:" of window 1
 end if


end setfmFileOptions


on GUIScripting_status()
    -- check to see if assistive devices is enabled
    tell application "System Events"
        set UI_enabled to UI elements enabled
    end tell
    if UI_enabled is false then
        tell application "System Preferences"
            activate
            set current pane to pane id "com.apple.preference.universalaccess"
            display dialog "This script utilizes the built-in Graphic User Interface Scripting architecture of Mac OS x which is currently disabled." & return & return & "You can activate GUI Scripting by selecting the checkbox \"Enable access for assistive devices\" in the Universal Access preference pane." with icon 1 buttons {"Cancel"} default button 1
        end tell
    end if
end GUIScripting_status

It won't compile and returns this error the line " if (exists checkbox "Log in using:" of window 1) is true then":

enter image description here

1

try this little syntax change:

on setfmFileOptions(app_name)

    -- choose the Developer Utilities menu item from the Tools menu of FileMaker Pro Advanced

    do_menu(app_name, "File", "File Options...")


    -- click the "Log in using" checkbox:
    tell application "System Events"
        tell process app_name
            repeat until (exists checkbox "Log in using:" of tab group 1 of window 1)
                delay 1
            end repeat
            click checkbox "Log in using:" of tab group 1 of window 1
        end tell
    end tell
end setfmFileOptions

You can't use window 1 without telling what process window 1 is in. You'll have to specify app_name as a parameter now.

So, like this:

setfmFileOptions("FileMaker Pro Advanced")
  • Thanks for your reply. I've updated my script with your suggestions but it's not clicking the checkbox. It looks like the line: if (exists checkbox "Log in using" of window 1) is true then is not being recognised, as I added a dialog box as part of that branch and it doesn't display the dialog box. Any ideas why or alternative syntax suggestions? – user982124 Jul 2 '15 at 12:24
  • Try the updated code. It can take a little time for the checkbox to become available after you tell a window to appear. You have to check for its presence for awhile to know when to click it. This updated code should do that. – William T Froggard Jul 2 '15 at 13:02
  • Thanks - I've left it running for a few minutes but still no result. It's like it doesn't "see" the window - I've tried specifying the window name by it's window title but that didn't make a difference. Any other suggestions? – user982124 Jul 2 '15 at 13:20
  • 1
    One way to determine what you should be clicking on is by using this code: tell application "System Events" to get checkboxes of window 1 of process "FileMaker Pro Advanced" Look at the checkboxes that are returned, if any, if you don't find what you're looking for then try this: tell application "System Events" to get checkboxes of UI elements of window 1 of process "FileMaker Pro Advanced" then keep adding of UI elements after checkboxes until you get the checkbox you're looking for. This is a simple way to crawl the view hierarchy. Do this in a separate script though. – William T Froggard Jul 2 '15 at 13:23
  • Although, if the checkbox isn't named, it's possible you'll have to use trial and error to determine if a given checkbox is the one you're looking for. It depends on how the developers designed their UI. – William T Froggard Jul 2 '15 at 13:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .