delay on pop up button

i have a virtual numbers pad, it seems when using keystrokes or key code values from the popup buttons, there is a small delay until the button is ready to be pressed again, which slows down input. Any Ideas ?
thanks in advance

Hello John,

AppleScript is single threaded which makes AppleScript-Studio also single threaded. During executing the code behind the button, it remains in a “pressed” state. When the process is finished the button is available again. If the button need to run code synchronously this isn’t an issue (just change button behavior) but when the code needs to be executed asynchronously you should dispatch the code to another process using osascript (AppleScript-Studio application are 100% scriptable application internal as external).

Not too sure about this. I use the following code in my AppleScript Studios-based project:

set uses threaded animation of progress indicator "progress" to true

:slight_smile: that has nothing to do with threading.

AppleScript is using Apple Events, which are similar to keyboard and mouse events. Keyboard and mouse events are triggered by external hardware while Apple Events are fired by software. Unlike mouse and keyboard events, the event listener for Apple Events needs to run on the main thread of the application/process. Because Apple Events can only be handled on the main thread it’s called single threaded. When someone tries to execute AppleScript on another thread it’s forced back to the main thread again, at least the event listener.

So back to the button. When an on-click-event is fired, the code is executed and puts the Apple Event listener in a busy state and makes your application’s interface freeze for a short while (depending on size of the code behind it). During the firing of an event you can’t fire another event and the up coming events are queued or ignored, depending on the type of events.

Example: Open in script editor two documents and do a sleep using a do shell script in one document, now every do shell script command is on hold in the other document because it waits for the event listener to be ready (after the sleep is complete). The exact same thing happens when pressing a button in Apple-Studio.

Reason: The reason for this behavior is the way Apple Events are handled. Apple Events are send to the Apple Event manager, which is responsible to send the event to the right process for interprocess communication. Like many messaging systems, once a message has been send the software waits for an reply. This applies for the event listener in the system as inside the application (process). During the time of sending and receiving an event the application’s interface seems to freeze. The code that is firing the event needs to wait for a response because sometimes the return value is important like the “should” handlers in AppleScript-Studio.

thanks guys for your reply’s

hello dj

“If the button need to run code synchronously this isn’t an issue (just change button behavior)”

so I thought about what you said, so i placed the script in a mouse up event, it definitely runs quicker, also I changed the mode of the button to momentary change. then i changed the double click settings in system preferences to fast. now five repeated clicks of of the same button, will put four characters in my text field.

on mouse up theObject event theEvent
tell application “System Events”
tell process “keyPad”
keystroke “1”
end tell
end tell
end mouse up

i am definitely more happy with the result but its still not a quick as keyboard viewers input

now i will look up a little about osascript, would this be a better approach ? or is it not possible with applescript to match the speed of keyboard viewer (i assume its written in objc)