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

0004838

Suspended
Original poster
Oct 1, 2014
193
64
Here's the script. It's purpose is to create an ad-hoc wifi network on Mavericks 10.9.5. It fails because the final "Create" button remains greyed-out and can't be pressed by the script.
Code:
property CreateMenuName : "Create Network…"
property NetworkName : "foo"
property NetworkPassword : "bar"
property WifiType : "128-bit WEP"

tell application "System Events"
	tell process "SystemUIServer"
		tell menu bar item 4 of menu bar 1
			click
			click menu item CreateMenuName of menu 1
		end tell
		tell window 1
			click pop up button 2
			click menu item WifiType of menu 1 of pop up button 2
			set value of text field 2 to NetworkPassword
			delay 1
			set value of text field 3 to NetworkPassword
			delay 1
			set value of text field 1 to NetworkName
			delay 1
			(*click button 1*)
		end tell
	end tell
end tell

The delays are present only so that I could see what was happening while the script ran. I realise that specifying the precise menu bar item location is fragile but it works in my case. You will probably have to adjust this if you want to test this script yourself. Count the menu bar items from left to right, and ignore 3rd-party menu bar items.

I've commented out the final, problematic "click button 1" command. Everything up to this point works just fine. One of the last things the script does is enter the passwords for the network. However, despite both passwords being entered and both obviously matching, the "Create" button remains greyed out. If you select either password field after the script has run, delete the last letter and then enter it manually, ie. delete the "r" from "bar", and then re-enter it, the button becomes active.

Anyone know what's causing this, and how to get round it?
 
When I do the procedure manually (but not on Mavericks), the password length must meet the WEP-128 constraint. That is, it must be exactly 13 ASCII characters or 26 hex digits.

The code you posted shows a password "bar" which is only 3 characters.


I also think it's odd that you enter the network name last. Consider rearranging the scripted commands so the network name is entered before the two passwords. In short, like a real person would do interactively.
 
lol, you got me, that's obviously not the real password. In the actual script I use a full 13 character password. As for re-arranging the commands: I did try that, various combinations, but the problem unfortunately still remains. The webpage I culled that script from had some comments that explained why the order of commands was in some way important, but it was for an earlier version of OS X so I don't think it applied in my case.

Some further info: when you watch the script do its thing, it looks as though it never actually selects the second of the two password fields. It seems to fill in the field without requiring this step. Perhaps if I were to find some way of having the script enter the first password and then "tab" to the next field, as a user would, and then fill in that password, it would be successful?

I'm not sure how I could do that though.
 
I was right, tabbing to the second password field allows the script to succeed and press the "Create" button. The Applescript command is:

keystroke tab
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.