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: autoxr on Feb 26, '04 06:26:22PM
Here's an enhancement of the original application to handle the window closing as well as better handling of the app already running (I found that it took two launches to get the keyboard viewer app back running after closing the window). Create an applescript and paste the following code into that. Save the script as an Application and check the "Stay Open" checkbox. Then other than an annoying progress cursor every time it polls for the window being open, it'll behave just as if it was the KeyCaps application itself. Closing the window will quit both apps and quitting the script application will quit the keyboard viewer app. Paste a nice pretty icon onto the script application and I bet that you'd fool people into thinking that it was the old KeyCaps updated for panther :-)

on run
	tell application "System Events"
		if exists process "KeyboardViewerServer" then
			try
				quit application "KeyboardViewerServer"
				repeat until exists process "KeyboardViewerServer" is false
					delay 1
				end repeat
			end try
		end if
	end tell
	
	tell application "Finder"
		open item "System:Library:Components:KeyboardViewer.component:Contents:SharedSupport:KeyboardViewerServer.app" of the startup disk
	end tell
	
	tell application "System Events"
		repeat until exists process "KeyboardViewerServer"
			delay 1
		end repeat
	end tell
	
	set frontmost to false
end run

on idle
	tell application "System Events"
		if exists process "KeyboardViewerServer" then
			set windList to every window of application process "KeyboardViewerServer"
			if (count of windList) is 0 then
				quit me
			end if
		end if
	end tell
	return 1
end idle

on quit
	tell application "System Events"
		if exists process "KeyboardViewerServer" then
			try
				quit application "KeyboardViewerServer"
			end try
		end if
	end tell
	continue quit
end quit


[ Reply to This | # ]
10.3: Restore the Key Caps application via AppleScript
Authored by: workerB on Feb 26, '04 06:59:16PM

Trying autoxr's script I keep getting the same error/notice:

"can't set frontmost to false"

What's up?



[ Reply to This | # ]
10.3: Restore the Key Caps application via AppleScript
Authored by: Eanes03WFU on Jul 24, '04 02:45:41PM

I get the same error message, and know virtually nothing about AppleScript so I've been unable to edit the script... a little help?



[ Reply to This | # ]