key code 24 using control down - no longer works in 10.6

I have a script that should open a dialog box to make a picture using Copernicus. the command I try to invoke is ‘Control =’.

here is the script.

tell application “Copernicus”
activate
delay 2
tell application “System Events”
key code 24 using control down
end tell
end tell

or alternative I tried:

tell application “Copernicus”
activate
delay 2
tell application “System Events” to keystroke “=” using control down
delay 5

end tell
However both do not work, it does do nothing on - key code 24 using control down -.

If I do a manual ‘Control =’ it works regardless if the Application is active or in the background.

Has anything changed in 10.6 that this sort of code no longer works? How do I set it up for this to work?

Maybe this…

tell application "Copernicus"
	activate
	delay 2
	tell application "System Events" to tell process "Copernicus"
		keystroke (ASCII character 61) using {control down}
		delay 5
	end tell
end tell

Tom

thanks Tom, but no it did not.

Forgive the question, but I don’t have Copernicus. It’s quite rare (but not unheard of) for the Control key to be the sole modifier in a keyboard shortcut. Are you sure it’s not the Command key that’s meant?

Nigel you are right, however I have set it up this way (you can do in control panel of the app.). and I have tried other combinations to no avail. thanks for thinking with me however, I remain puzzled as to why it does not work…

anybody have any idea as to why

tell application “System Events”
key code 24 using control down

does not work? any suggestions as to how to solve this?

wild guesses?

I don’t have Copernicus either.

But have a look at the Command Line Interface checkModifierKeys posted by StefanK at

http://macscripter.net/viewtopic.php?pid=114469. It works in 10.6.

You might be able to bring up your dialog box this way.

Val

thanks val, I do not understand how checkModifierKeys would help me?

Ok.

Perhaps this might do.

(only if you have still got your “Previous Systems” folder on your machine.)

KeyboardViewerServer*** appears to be the previous Leopard implementation of the current Snow Leopard app KeyboardViewer - /System/Library/InputMethods/KeyboardViewer (I can’t get KeyboardViewer to do anything)

(i.e. KeyboardViewerServer appears to have been replaced in Snow Leopard)

So if you don’t have the “Previous Systems” folder on your machine please disregard this post.

Otherwise try this. It should allow you to get a dialog to display if you press just the ctrl key.

Save this script as a stay open application and run it. Then press the ctrl key and see if the dialog comes up.

The Symbol is Technical Symbol Up arrowhead.

on run
	try
		tell application "System Events"
			if not ((some process whose name contains "KeyboardViewerServer") exists) then
				tell application "KeyboardViewerServer" to activate
			end if
		end tell
	on error
		tell application "KeyboardViewerServer" to activate
	end try
end run


on idle
	tell application "System Events"
		if ((get value of checkbox "⌃" of first window of application process "KeyboardViewerServer") as number) = 1 then
			activate me
			tell application "TextEdit" --------- replace with whatever
				activate
				display dialog "Is this weird or what ?" with title "Would this help?"
				tell me to quit
			end tell
		end if
	end tell
	return 0.05
end idle

This qualifies as a wild guess !

Val

*** The Path to KeyboardViewerServe is

Your HD
Previous Systems
System
Library
Components
KeyboardViewer.component ------- (you have to open package)
Contents
SharedSupport
KeyboardViewerServer.app

btw

if you only want the dialog to come up when ctrl = (both) are pressed

use

if ((get value of checkbox "⌃" of first window of application process "KeyboardViewerServer") as number) = 1 and ((get value of checkbox "=" of first window of application process "KeyboardViewerServer") as number) = 1 then

Val

I’ve just downloaded Copernicus for a quick look. I set Control-= as the preference for “Show Main Window” and can confirm that, while it works manually, it doesn’t do anything when scripted.

I suspect (but don’t know) that it’s because it’s linked into some background system that can invoke hidden applications, whereas the System Events commands are for delivering keystroke information to the GUI of the frontmost process.

If, by any chance, it’s Copernicus’s main Tool Window you’re trying to get, there’s a GUI shortcut for it shown in the “Window” menu: Command-1.


tell application "Copernicus" to activate
tell application "System Events" to keystroke "1" using command down

KeyboardViewerServer

Thanks Delpucci, as I wrote before, I do not understand how checkModifierKeys would help me? I also do not have a old system on my Mac. in 10.6, if I am not mistaken, it is replaced with the application keyboardSee, this too would not help me or?

anyway thanks for thinking with me. Eric

Nigel thanks, I did see this as I tried to script the Tool Window, as it would be a workaround. however no luck there either, unless you are able to do so I can not see it to be of any help.

Eric

Another wild guess.

tell application "Copernicus"
	activate
	repeat 3 times
		tell application "System Events" to tell process "Copernicus"
			key code 24 using {control down}
		end tell
	end repeat
end tell

Val

Like Nigel I downloaded Copernicus.

It appears to me that the problem is with “Coperinicus” and not key code 24 or control which responds to a script in keyboardviewer (10.6)

Coperincus will respond to the command above but it could take minutes - which is probably unacceptable.

Val

hi delpucci, this script does hang, nothing happens within 10 minutes so I canceled it.

when I execute the command via the keyboard it indeed takes several seconds before the save box comes up (I set it to do that). however via the script nothing happens. are you saying it works, with a time laps, for you using the script?

Eric

I thought I had. But no, I can’t repeat it. (left the machine and when i returned a screenshot was on upper left of screen – but i must have… )

However just to see if key code 24 using {control down} was scriptable in 10.6 I performed this test.

  1. activate “System Preferences”

  2. activate “Keyboard” pane

  3. activate " KeyBoard Shortcuts"

  4. in Left Hand Window of pane activate “Application Shortcuts”

  5. Press the “+” button

  6. Add application “TextEdit” with “Zoom” as “Menu Title” and “ctrl =” as Keyboard Shortcut – appears as ⌃=.

  7. Quit “TextEdit” if open.

  8. Then Run the script below. TexEdit window “untitled” will zoom. at least on my machine it does every time so far.

tell application "TextEdit"
	activate
	tell application "System Events" to key code 24 using {control down}
end tell

—Thus it appears that key code 24 using {control down} reacts to scripts in Mac OS 10.6.

So perhaps the problem is not with key code 24 using {control down}

Val

last test

and it did work !

tell application "Copernicus"
	activate
	repeat 1000 times
		tell application "System Events" to key code 24 using {control down}
	end repeat
end tell

Val

not for me val, but I did solve it.

Not sure as to what is not working with the other scripts in the background, but this does it.

tell application "Copernicus"
	activate
	delay 3
	tell application "System Events"
		key down control
		key down "1"
		delay 2
		key up control
		key up "1"
	end tell
end tell

Of course I set the command in Copernicus preferences to ‘Control 1 (1 on the numerical pad!)’. Using the same code with ‘Control =’ or ‘Control I’ etc did not work. this does. strange.

anyway, thanks for thinking with me everybody!