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


Click here to return to the 'Toggle KeyboardViewer (tested on Lion Mac OS X v10.7.2)' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Toggle KeyboardViewer (tested on Lion Mac OS X v10.7.2)
Authored by: mistersquid on Feb 09, '12 10:50:35AM

This should turn the trick. Save it as an app to

~/Library/Scripts
and assign it a keyboard shortcut using your favorite global shortcuts utility.

property KeyboardViewerIsRunning : ""
try
	tell application "System Events"
		if ((count (every process whose name is "KeyboardViewer")) is 0) then
			tell application "Finder"
				open item ":System:Library:Input Methods:KeyboardViewer.app" of the startup disk
			end tell
			set KeyboardViewerIsRunning to false
		else
			set KeyboardViewerIsRunning to true
		end if
	end tell
	if (KeyboardViewerIsRunning) then
		tell application "KeyboardViewer" to quit
	else
		tell application "KeyboardViewer" to activate
	end if
on error msg number errNum
	displayError(msg, errNum)
	quit
end try

-- Error Messaging 

on displayError(msg, errNum)
	set msg to styleMsg(msg)
	display dialog "\"Cannot toggle KeyboardViewer\" " & msg & " Error number " & errNum & "."
end displayError

on styleMsg(msg)
	set firstLetter to character 1 of msg
	considering case
		if firstLetter is not in "abcdefghijklmnopqrstuvwxyz" then set firstLetter to makelower(firstLetter)
	end considering
	if length of msg > 1 then
		set msgRemainder to text 2 thru (length of msg) of msg
	end if
	set msg to firstLetter & msgRemainder
	return msg
end styleMsg

on makelower(theText)
	set newText to ""
	repeat with i from 1 to (length of theText)
		set newText to newText & lower(character i of theText)
	end repeat
	return newText
end makelower

on lower(_letter)
	considering case
		set myChar to offset of _letter in "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
		if myChar > 0 then
			return character myChar of "abcdefghijklmnopqrstuvwxyz"
		else
			return _letter
		end if
	end considering
end lower
Edited on Feb 09, '12 11:06:10AM by mistersquid


[ Reply to This | # ]