Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ajthomason

macrumors 6502
Original poster
Hi There,

I'm trying to write a script that will load an application, go to a tab in the application then click a button.

So far, I have this:

Code:
tell application "WirelessUtilityCardbusPCI"
	activate
end tell


tell application "System Events"
	tell process "WirelessUtilityCardbusPCI"
[B]{Insert go to tab code here}
[/B]		click button "Radio Off" of tab group 1 of window "Wireless Utility"
		click button "Radio On" of tab group 1 of window "Wireless Utility"
		
	end tell
end tell

The problem is that the app does not load on the correct tab, so it cannot click the button.

Here is a screenshot of the menu/tab bar:

81953853.png


Does anyone have any idea of the code required to get me to the 'Advanced' tab?

I know that I haven't explained this well, but hopefully someone will understand.
 
It may be that the advanced "tab" itself is in fact a radio button disguised as a tab, which is common. You can verify this using Apple's UIElementInspector. With the Inspector open, place your mouse pointer over the Advanced tab and see what it tells you. If indeed the Advanced tab turns out to be a radio button, your code in question might look something like this:

click radio button "Advanced" of tab group 1 of window 1 (or whatever it's named) of application "WirelessUtilityCardbusPCI"

Good luck...
 
It may be that the advanced "tab" itself is in fact a radio button disguised as a tab, which is common. You can verify this using Apple's UIElementInspector. With the Inspector open, place your mouse pointer over the Advanced tab and see what it tells you. If indeed the Advanced tab turns out to be a radio button, your code in question might look something like this:

click radio button "Advanced" of tab group 1 of window 1 (or whatever it's named) of application "WirelessUtilityCardbusPCI"

Good luck...

Perfect! I checked as you suggested, and it is indeed a radio button, used your code and it works with no problems!

Thanks very much for your help!
 
I have another question, if you have the time.

I'm now writing another script (although using the first one, just extending it), this time it is to change the profile of the wireless utility. I'm using Accessibility Inspector this time, but I still can't get it to click at all.

Here is a screenshot:

23105022.tiff


As you can see, I'm trying to get it to click 'Tething Link' (followed by the 'Activate' button), but it will not click the table row. Here is the code that I'm using (I've tried loads of variations, such as replacing the 1s with 2s and leaving bits out):

Code:
click text field "Tethering Link" of row 1 of table 1 of scroll area 1 of tab group 1 of window "Wireless Utility"


Do you have any ideas about this one?

Thanks again!
 
Hello again, and thanks for posting back...... I might opt for using the Down arrow key, possibly in combination with the Tab key, depending on what element is active once the Profile tab is open. The idea is to have the scroll area active and then use the Down arrow to reach the second item on the list (I'm assuming judging from your screenshot that Tethering Link is the second item).

If the scroll area is active (highlighted) once the Profile tab is open, fine. If not, use your Tab key and count the number of times you need to tab in order to make the scroll area active -- you should see a square or rectangular highlight ring surrounding the scroll area to indicate it's active. Then count the number of times you need to press the Down arrow (ASCII character 31) to reach the second item. If the Profile opens with the first item (Home) already highlighted, you'd hit the down arrow only once, otherwise twice.

Let's say you need to tab twice to highlight the scroll area, and then hit the Down arrow twice to reach Tethering Link. The code you would use might look like this:

keystroke tab
keystroke tab
keystroke (ASCII character 31)
keystroke (ASCII character 31)


If "Activate" is the default button when you reach Tethering Link, you might need only to add the keystroke Return command to simulate the pressing of this button:

keystroke tab
keystroke tab
keystroke (ASCII character 31)
keystroke (ASCII character 31)
keystroke Return


With this type of approach, "Delay" commands can be useful, if not necessary, in case a script stalls out. For example, if your script fails to complete the keystroke Return command following the final keystroke (ASCII character 31) command, you might consider including a half-second delay:

keystroke tab
keystroke tab
keystroke (ASCII character 31)
keystroke (ASCII character 31)
delay .5
keystroke Return


Just a few ideas for you. Hope this helps!
 
<snip>
Just a few ideas for you. Hope this helps!

It really does! Thanks again!

It's now almost perfect - the only problem is that it will not automatically direct the keystrokes at the target window, the window isn't 'active', it has the dull grey bar as if it is one of the apps in the background. This means that it ignores the keystrokes that the script runs.

I have managed to get around this by forcing the application to do something that throws back an error (loading a profile without selecting one), and then for it to accept the error and hey presto! the app is now the active window. The problem with this is that it hangs for 5 secs or so on this error.

It's not a real problem as I have a way around it, but do you know of any way to make the window the active window? I've tried repeating the 'activate' command, but that doesn't do anything.

Again, thanks very much for your help!
 
In order to get the tabbing actions described earlier to work, it might be necessary to have Full Keyboard Access enabled. Under System Preferences > Keyboard & Mouse > Keyboard Shortcuts, make sure the "All controls" radio button is selected. Once Full Keyboard Access is enabled, look for a bluish ring to bring focus to the various items as you tab through the UI elements in the Profile window. Count the number of times it takes to tab to the scroll area from the time the Profile window first opens. That's the number of times you would use the keystroke tab command in the script.

However, if you find that Full Keyboard Access is already enabled, I'm not sure what the next step is. I'm happy to know you've got something that works, though. Continued good luck!
 
Hi There,

I'm trying to write a script that will load an application, go to a tab in the application then click a button.

So far, I have this:

Code:
tell application "WirelessUtilityCardbusPCI"
	activate
end tell


tell application "System Events"
	tell process "WirelessUtilityCardbusPCI"
[B]{Insert go to tab code here}
[/B]		click button "Radio Off" of tab group 1 of window "Wireless Utility"
		click button "Radio On" of tab group 1 of window "Wireless Utility"
		
	end tell
end tell

The problem is that the app does not load on the correct tab, so it cannot click the button.

Here is a screenshot of the menu/tab bar:

81953853.png


Does anyone have any idea of the code required to get me to the 'Advanced' tab?

I know that I haven't explained this well, but hopefully someone will understand.

hi, would u mind sharing the code you made for this, as i'm looking to try and do the same.

many thanks

David
 
Here is my working code

thanks to the OP for putting this out there btw.

I was able to get the first segment of code working below. I haven't tried to do the stuff with profiles and such, just using it to turn the radio on and off in the wireless utility. I'm using this little hack so that when I bring my mac back from sleep, the wireless card gets turned off, then back on (reset it a little bit).

Code:
tell application "WirelessUtilityCardbusPCI"
	activate
end tell


tell application "System Events"
	tell process "WirelessUtilityCardbusPCI"
		click radio button "Advanced" of tab group 1 of window "Wireless Utility"
		click button "Radio Off" of tab group 1 of window "Wireless Utility"
		click button "Radio On" of tab group 1 of window "Wireless Utility"
	end tell
end tell

I hope that helps, it helped me a lot
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.