I\'m trying to send the spacebar key to an application without activating it first. The following code almost does what I want but it brings the application to the foregroun
Sending a keystroke can basically be seen as using a keyboard, but the only difference is that the keys that need to be pressed are already predefined. The rest of the process revolving around this doesn't change. This means that the application itself still needs to be opened and activated before you can actually send keystrokes to it.
Depending on the application however, it might be possible to use certain Applescript functions in the application's API to send different inputs to the application without having to activate it first. Take the Messages API for instance:
tell application "Messages"
set theBuddy to buddy "someone@mac.com" of service "iMessage"
send "Hi there" to theBuddy
end tell