But it’s not working well. I have to run 5-10 times the script, to simulate one F1 or F2 push. I think, the script is too fast. The brightness change object (sun :-)) is coming up, but nothing happens.
Can somebody tell me, how can I slow it down? Eg. like this:
key down option
delay 0.3
key up option
key down (key code 113) --this not working
Thanks, but maybe You didn’t understand the problem. If I run this script:
tell application "System Events" to repeat 16 times
key code 113 -- or 107
end repeat
sometimes nothing happen, only the sun come up. Sometimes changes the brightness with 1 step, sometimes 2 or 3 steps. If I using the click at {x,y} command, I have the same problems: Sometimes working, sometimes not.
I want to do this but it’s not working:
tell application "System Events"
key down (key code 113) -- or 107
delay 0.3
key up (key code 113)
end repeat
I’m pretty sure I did, Bachman - although our machines may differ slightly in their responses.
Without the delay that I suggested, the key code commands are almost certainly being sent too quickly for them all to register. Try re-inserting the delay, and then experimenting with the length of it.
Much as I dislike being defeatist about this, I don’t think you’re going to be able to make this work.
The ‘key down’ and ‘key up’ commands are part of System Events’ Hidden Suite, and don’t show up in the AppleScript dictionary. But they generally expect parameters like a string or, more commonly, a modifier key (shift, command, control & option). By contrast, ‘key code’ is a command in its own right. The net result of this is that the ‘key down/up’ commands are issued with the current application as a parameter - and, since this doesn’t make much sense, the commands are ignored. (They may also error on some systems.)
However, if there’s no error, the ‘key code’ part of the statements could still be executed.
As you can see, this means that the brightness level will be changed by only a couple of steps at most.
As far as I’m aware, the bottom line is that you’re pretty much stuck with three options:
Edit: I see that, while I was typing this, you came up with the latter - which is great. However, I hope that the above explanation still helps to clarify the nature of the problems that you were experiencing.