-tell application "System Events"- is not working to type text

I have problems in a script with this command typing text in boxes, like a safe window etc.

I have the following script as example:

tell application "Safari"
	activate
	delay 4
	tell application "System Events"
		keystroke "http://192.168.1.90/37"
	end tell
end tell

On My MBP this works a dream, however on my headless server a MM it does not. It refuse to type the text in the bar.

Anybody got any idea as to why?

Model: MM
AppleScript: 2.3 (118)
Browser: Safari 534.52.7
Operating System: Mac OS X (10.6)

First of all, I know that “MBP” stands for “MacBook Pro”, but what does “MM” stand for?

Second of all, what version of Mac OS X is your MacBook Pro running? (Click on “About This Mac” under the Apple Menu.) If it is running Lion (10.7.x), then you should probably rewrite the script for your “MM”, unless you already did that.

Third of all, is access to assistive devices enabled on your “MM”? If not, then this may be your problem. Open System Preferences and click “Universal Access”, then click the check box that says “Enable access for assistive devices”. (You will need to type an administrator password.)

Hi. I’m assuming that you are simply trying to open a page, and that can be done without System Events.

tell application "Safari" to make document with properties {URL:"http://192.168.1.90/37"}

Sorry MacMini

as stated 10.6.8

yes access to assistive devices is enabled

No this was just an example of system events refusing to type anything in a field. but thanks for thinking with me.

Why not :


tell application "Safari"
   activate
   delay 4
   tell application "System Events" to tell process "Safari"
       keystroke "http://192.168.1.90/37"
   end tell
end tell

Yvan KOENIG (VALLAURIS, France) lundi 6 février 2012 17:04:57

Although listed in System Events’s Processes Suite, ‘keystroke’ and ‘key code’ don’t require access for assistive devices to be enabled. Nor do they directly access any part of a process’s GUI, so it makes no difference whether a script includes a reference to a process or not. Keystrokes and key codes are simply generated and land on the frontmost process. What matters is that the target process is frontmost and that its target field is focussed.

OK good info, I have an other look at the script

Thanks this works.

also worked out this:

tell application "Safari" to make document with properties {URL:"http://192.168.1.90/37"}