Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the '10.3: Restore the Key Caps application via AppleScript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.3: Restore the Key Caps application via AppleScript
Authored by: jakacmar on Feb 26, '04 04:52:53PM
Here's an addition to the script which should quit the KeyboardViewerServer Process when the window is closed. For this to work, the app must be saved as "stay open". One caveat, for some reason when the app quits itself (which it doesn't do very well) it must first be activated (very annoying but it's done automatically and I can't figure out a fix right now), also, for the actual "Quitting" to take place, you need to click on another app (any other app, even the Desktop). Once you do this, the icon will be removed form the Dock etc. Give it a try and you'll see what I mean. I know this is ugly script but I just threw it together real quick and don't have time to tinker with it now. Had I been able to figure this out in the first place I would've just included it in the original hint submission. So here goes, just paste this extra code at the very end of the script (after the last end tell) and save it as an app with "stay open" checked.

on idle
	repeat
		tell application "System Events"
			tell process "KeyboardViewerServer"
				if exists window "Keyboard Viewer" then
					set isOpen to true
				else
					set isOpen to false
				end if
			end tell
			if not isOpen then
				try
					quit application "KeyboardViewerServer"
				end try
				exit repeat
			else
				do shell script "sleep 1"
			end if
		end tell
	end repeat
	if not isOpen then
		tell me to activate
		tell application "System Events"
			tell process me
				keystroke "q" using command down
			end tell
		end tell
	end if
end idle


[ Reply to This | # ]