Shell script to hit command/control keys?

Is it possible to send a unix command that will tell a program to hit certain control keys? I’m testing some software on lots of machines at the same time, and hitting cntrl-u will automatically resize all the windows to the screen, but because all the machines came from the same image, the screen sizes aren’t all the same so I have to resize all of them. Unfortunately the name of the app keeps changing based on the version number so I can’t just do something simple like:

tell application “programname”
tell application “System Events”
keystroke “u” using control down
end tell
end tell

which would probably work fine if I was always using the same program name… I suppose I could actually use an apple script to do this and have it detect the name based on the highest version number or something (not that I have a clue how to do this) but it seems like it should be relatively simple to just have the OS hit control-u when I tell it to, regardless of what app is open at the time… Any thoughts?

anyone?

Unix doesn’t have a GUI. Why would it want to send keystrokes and modifier keys in its normal course of business? You can run applescripts from the terminal and have script code executed in the terminal:

See this, for example: AppleScript and the Command Line

Look at man osascript too.

I figured out another way to do what I wanted, but what I was trying to do was send a gui script to an app that isn’t scriptable without bringing it to the foreground. I ended up bringing it to the foreground, sending the command and then bringing the other app back to the top. I was just hoping there might be a way to reduce the ammount of lines in the script. Not that it really matters all that much. Anyway, thanks!

Here’s a ridiculous example of osascript:


do shell script "osascript -e  'tell application \"Finder\" to activate' -e 'tell application \"Finder\" to display dialog \"hello world\"'"

So in your shell script:

osascript -e ‘tell application myApp to activate’ -e ‘tell application “System Events” to keystroke “u” using {command down}’

might do it.