UI Scripting error

Hi All,

I’m having error System Events got an error: NSReceiverEvaluationScriptError: 4 when using UI Scripting. I did read all other posts on this error and I do have “Enable acces for assistive device” enabled, but still I get this error.

As a desperate attempt to figure out what’s causing this, I took the example of:
http://www.apple.com/applescript/uiscripting/02.html


tell application "Finder"
activate
end tell

tell application "System Events"
tell process "Finder"
tell menu bar 1
tell menu bar item "View"
tell menu "View"
tell menu item "Arrange"
tell menu "Arrange"
click menu item "by Size"
end tell
end tell
end tell
end tell
end tell
end tell
end tell

Looks pretty basic and should work alright? Well it doesn’t… It gives the error highlighting the “click menu item by size” . I checked with UI Inspector and noticed my menu item isn’t called Arragnge , but ‘Arrangged By’ and By Size should be 'Size". Ok changed that still the same…

I stripped the script to see what went wrong and noticed that I can click the ‘View’ menu:


tell application "Finder"
	activate
end tell

tell application "System Events"
	tell process "Finder"
		tell menu bar 1
			tell menu bar item "View"
				tell menu "View"
					click
				end tell
			end tell
		end tell
	end tell
end tell

I noticed the sinngle ‘click’ in stead of ‘click menu item “by Size”’ and I guess I’ve tried all possible combiantion, but :frowning:
Does anyone have an idea???
Eventually I’m just trying to get Safari ‘save to pdf’

I’m using OS X 10.4.2
TIA

Browser: Safari 412.2
Operating System: Mac OS X (10.4)

You can use as helper both PreFab’s UI Browser → visit http://www.prefab.com/uibrowser/
And Apple’s UI Element Inspector → http://www.apple.com/applescript/uiscripting/02.html
These will help you to locate the related elements. You can call they by name or by index. Eg:

click menu item 4 of menu 1 of menu item 7 of menu 1 of menu bar item 5 of menu bar 1

(works fine in my Finder)

  • BTW, I’ve just ordered my desktop items by size, which is not what I was looking for exactly :mad: :lol:

Thanks and you script does work fine…

So how would you do it for safari and ‘save to pdf’? I can open print window fine:


tell application "Safari"
	activate
end tell

tell application "System Events"
	tell process "safari"
		keystroke "p" using {command down}
	end tell
end tell

But how do I get the syntax for the pdf button and how do i select ‘save to pdf’. I’ve googled numerous times and all suggestions end up in this error.

Thanks

No idea, sorry. Seems that such button doesn’t respond to click events… :confused: