Scripting a GUI button

Hello

I am trying to write a simple script to get an xls file to open. The file starts to open, however an popup box opens and asks if I want to “Enable\Disable Macros” (this is expected). I have searched for two days now and I can not find an example of how to script a GUI button click. I know one is out there I just have not found it.

Does anyone know how to do this and can they show me? I also want to learn so any docs\links would help.

Below I copied the contents of the Accessibility Inspector and the contents of the script

Thanks
Chad
I have a screen shot, I just don’t know how to attach it. If some one can point me to the instructions, I will post it.

Accessibility Inspector

<AXApplication: “Excel”>
<AXWindow: “Microsoft Excel”>
<AXButton: “Enable Macros”>

Attributes:
AXRole: “AXButton”
AXRoleDescription: “button”
AXParent: “<AXWindow: “Microsoft Excel”>”
AXTitle: “Enable Macros”
AXWindow: “(null)”
AXTopLevelUIElement: “<AXWindow: “Microsoft Excel”>”
AXPosition: “x=434 y=475”
AXSize: “w=119 h=20”
AXEnabled: “1”
AXFocused (W): “0”

Actions:
AXPress - press

Here is a copy of the code:
tell application “Microsoft Excel”
launch
delay 5 – watching to verify action, will be removed
activate
delay 5 – watching to verify action, will be removed
open file “Untitled:Users:amdapple:Documents:Apple_Script:inventory.xls”
end tell

This is typically how you script the press of buttons. There is a great program for this called “Prefab UI Browser” that you can use for getting the code for the object hierarchy. It has a free thirty day trial as well.

activate application "Microsoft Excel"
tell application "System Events"
	tell process "Microsoft Excel"
		perform action "AXPress" of button "Whatever button you want" of window "Microsoft Excel"
	end tell
end tell

Dallas

Thanks Dallas, Sorry No Dice :frowning:

I tried modding the example code that you attached
Here is one of the edits


activate application "Microsoft Excel"
tell application "System Events"
	tell process "Microsoft Excel"
		perform action "AXPress" of button "Open" of window "Microsoft Excel"
	end tell
end tell

Now I get a new error :slight_smile:

When I run the script I get the following error:
Apple Script Error
System Events got an error: Can’t get window “Project Gallery - New” of process “Microsoft Excel”

Any thoughts?

Thanks
Chad

Hi,

just try window 1 instead of window “Microsoft Excel”

I wouldn’t bother trying to find a specific button. When you open the file nirmally, can you hit a key to clear the box? Just “Return” if the default button is what you want, or maybe “e” for enable or “d” for disable (it could be command-e or command-d).

Anyway, find the key stroke that will clear it. In your script, after you open the Excel file, put a big delay to make sure the script has time to open the file and display the message, and then do:


tell application "Microsoft Excel"
		activate
              --Do your open command
		delay 8
		tell application "System Events"
			keystroke "e" using {command down}   --if commmand-e was needed
			keystroke "e"   --if just "e" needed to be pressed
			keystroke Return   --if the default button is what you want and you can just press the return key
		end tell
end tell

Model: G5
Browser: Safari 419.3
Operating System: Mac OS X (10.4)