Simple applescript: Help!

0 down vote favorite

Hi, I’m trying to make a simple applescript which doesn the following:

Switch to Microsoft Word
type * button on numeric keypad
press paste (command v)
press return button

I came up with this but it won’t work… Any ideas why??


tell application "System Events"

tell application process "Microsoft Word" to activate
keycode(42)
keycode(118)
keycode(3)

end tell 
end tell

Hi Giel,

First of all welcome to macscripter.

I think you’ve made the mistake and it should be

tell application "System Events"
	
	tell application "Microsoft Word" to activate
	tell process "Microsoft Word"
		key code 42
		key code 118
		key code 3
		
	end tell
end tell

Just some additional information.

I’m working in Europe and almost any language, French, English, German and Dutch have all the same key codes on their keyboard but the character it is representing are different. So key code tells the system that a certain key is pressed. the system asks the keyboard extension which keyboard is set. According to it’s language the right character is given to the system back. So when your script is ran by another character layout on the keyboard your script probably won’t work. So my advise is not to use key code but keystroke instead so you don’t have these problems. Your code would look like this

tell application "Microsoft Word" to activate

tell application "System Events"
	tell process "Microsoft Word"
		keystroke "*"
		keystroke "v" using command down
		keystroke return
	end tell
end tell

Thank guys, you made my day!