Click button has no effect on some dialogs

I suffer from a strange thing. As I run the following script:

tell application “System Events”
tell process “Adobe Photoshop CS4”
click button “Cancel” of window “New”
end tell
end tell

I seet that it effects the button to be clicked but nothing happens and the dialog remains on. With some dialogs the script works fine (like Open dialog, which maybe a system dialog not Photoshop). Does not matter if I run it from AppleScript Editor or as an app. Is it maybe an OS bug? I have 10.6.8.
Enabling is chekced in universal access. Thanks if somebody has any idea.

Model: Mac Pro
AppleScript: 2.1.2
Browser: Firefox 24.0
Operating System: Mac OS X (10.6)

Hi giorgio77,

I think some buttons might use some other command like press. Try looking in the System Events library. Also, you can use Accessability Inspector from Xcode. When you move the cursor to the button, the info shows up in the window. It shows what commands you can use to make to do an action.

It might be better to do the commands in the script though. I’m not too good at that.

gl,
kel

Hello

This behavior was frequent in AppleWorks.

Try this edited version :

tell application "System Events"
	tell process "Adobe Photoshop CS4"
		set cancelPosition to position of button "Cancel" of window "New"
	end tell
end tell
tell application "ASObjC Runner" to click button at cancelPosition

KOENIG Yvan (VALLAURIS, France) vendredi 20 septembre 2013 18:39:18

@Kel: I tried the perform action way, but same result…:frowning:
@Yvan: I downloaded the ASObjC Runner and tried the code, but not working. I modified a bit to be sure it clicks on the button, but still not working :frowning:


tell application "System Events"
	tell process "Adobe Photoshop CS4"
		set cancelPosition to position of button "Cancel" of window "New"
		set the first item of cancelPosition to (the first item of cancelPosition) + 10
		set the second item of cancelPosition to (the second item of cancelPosition) + 10
	end tell
end tell

tell application "ASObjC Runner" to click button at cancelPosition

The pointer goes there, but does not perform the click.

Hi.

This may work specifically for “Cancel”:

tell application "System Events"
	set frontmost of application process "Adobe Photoshop CS4" to true
	keystroke "." using {command down}
end tell

I will ask Shane Stanley about that because as far as I remember, this used to work.

At this time, you may try to use the standard shortcut linked to Cancel.


tell application "System Events"
	tell process "Adobe Photoshop CS4"
		keystroke character id 27 # press Esc
	end tell
end tell

KOENIG Yvan (VALLAURIS, France) mardi 24 septembre 2013 13:40:33

The “standard” shortcut for “Cancel” has always been Command-. while I’ve been a Mac user, hence my suggestion in post #5. I see though that pressing the Escape key also works, although Yvan’s script doesn’t on my machine. The Escape key’s better emulated with a ‘key code’ command:

tell application "System Events"
	set frontmost of application process "Adobe Photoshop CS4" to true
	key code 53
end tell

Thanks for the Cancel examples. Actually… I’d like to write a longer script for handling channels like:
Select a spot channel and set its fill color for a Pantone color. In Photoshop scripting reference there is no paramter for Pantone colorization of channels (the possible way is the CMYK, HSB, RGB colorization) but I need the Pantone.

That’s why I have choosen the GUI way to reach the above “Color Libraries” dialog. But it seems that there is problem on almost every CS4 dialog while GUI scripting. (This Cancel stuff was an example only.)
I have just tested on CS6 and everything works fine. But it seems there is a general problem with “click” in CS4 (unfortunatelly I have CS4 only at my workplace).

cmd + dot is fine for English users. On French keyboards it require to press also shift because dot is got by shift + ;

This is why for years, for me the Cancel shortcut is Escape.

I tested the sample script with TextEdit and it behaved flawlessly running os X 10.8.5

KOENIG Yvan (VALLAURIS, France) mardi 24 septembre 2013 19:07:34