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

Keyboard Viewer and Character Palette via AppleScript Apps
If you don't like using the Input Menu (System Preferences: International: Input Menu tab) to activate the Keyboard Viewer and Character Palette, here are two AppleScripts that do the same thing:

Keyboard Viewer: Get this script
tell application "Finder"
open item "System:Library:Components:KeyboardViewer.component:
 Contents:SharedSupport:KeyboardViewerServer.app" of the startup disk
end tell
Character Palette: Get this script
tell application "Finder"
open item "System:Library:Components:CharacterPalette.component:
 Contents:SharedSupport:CharPaletteServer" of the startup disk
end tell
Once the scripts are created, you can put them in your Dock, Sidebar, assign a hot key (via your favorite third-party tool), etc.

[robg adds: Please note that in the displayed code for both scripts, the open item line has been broken in two (for a narrower display here) just after component: bit. Remove the line break (and extra spaces) when creating the scripts, or they won't work properly. The easiest thing to do, though, is just click the "Get this script" link for each script to open it directly in your copy of Script Editor.]
    •    
  • Currently 3.00 / 5
  You rated: 2 / 5 (7 votes cast)
 
[29,805 views]  

Keyboard Viewer and Character Palette via AppleScript | 24 comments | Create New Account
Click here to return to the 'Keyboard Viewer and Character Palette via AppleScript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Keyboard Viewer and Character Palette via AppleScript
Authored by: chtito on Oct 27, '05 06:58:05AM

Great tip! I hadn't realised that those were applications. In fact you can simply drag those two applications (CharPaletteServer.app and KeyboardViewerServer.app) onto the dock without bothering to create the applescripts...



[ Reply to This | # ]
Keyboard Viewer and Character Palette via AppleScript
Authored by: JazzJoey on Oct 27, '05 07:33:50AM

The main function of these scripts is
the possibilty of implementing it in
other apps or scripts, simply because
it saves time, dock space, sidebar space,
and is compact handy in your favourite
app like mine.

Thus you could combine both scripts when
you are a writer etc....

But of course you should use it in the
way you want it to be.

---
Joey
headmaster@spymac.com



[ Reply to This | # ]
Help request: Keyboard Viewer and Character Palette Location??
Authored by: Deut3221 on Oct 27, '05 11:51:39AM

where do I find the server.apps so that I can drag them to the dock? thx!!!!



[ Reply to This | # ]
Help request: Keyboard Viewer and Character Palette Location??
Authored by: JazzJoey on Oct 27, '05 12:04:43PM
[b]To get the Keyboard Viewer application:[/b] 1.) Go to Finder 2.) Select Menu "Go" 3.) Choose "Go to Folder... 4.) Paste this Path: System/Library/Components/KeyboardViewer.component/Contents/SharedSupport/ [b]To get the Character Palette:[/b] 1.) Go to Finder 2.) Select Menu "Go" 3.) Choose "Go to Folder... 4.) Paste this Path: System/Library/Components/CharacterPalette.component/Contents/SharedSupport/

---
Joey
headmaster@spymac.com

[ Reply to This | # ]

Great, no more US flag in the menu bar!
Authored by: germ on Oct 27, '05 12:52:07PM
Keyboard Viewer and Character Palette via AppleScript
Authored by: elmimmo on Oct 27, '05 02:53:22PM

Or just navigate to /System/Library/Components/KeyboardViewer.component/Contents/SharedSupport/ and make an alias of KeyboardViewerServer.app wherever you want. ^_-



[ Reply to This | # ]
Keyboard Viewer and Character Palette via AppleScript
Authored by: tobyvoss on Jan 03, '07 09:28:53AM

/System/Library/Components/CharacterPalette.component/Contents/SharedSupport/CharPaletteServer.app
/System/Library/Components/KeyboardViewer.component/Contents/SharedSupport/KeyboardViewerServer.app
and
/System/Library/Components/Ink.component/Contents/SharedSupport/InkServer.app
are the only non-asian-(language/font) "utilitylets" around there. nice that they can be as easily accessed!



[ Reply to This | # ]
Keyboard Viewer and Character Palette via AppleScript
Authored by: chrononaut on Jun 21, '08 04:02:36PM
This works best for me as I can pull it up in Spotlight after it sees the alias. Also, I changed the info.plist file in a similar way to this hint.

i=/System/Library/Components/KeyboardViewer.component/Contents/\
SharedSupport/KeyboardViewerServer.app/Contents/Info.plist
sudo defaults write "${i%.plist}" LSBackgroundOnly 0
sudo defaults write "${i%.plist}" LSUIElement 0
And if you prefer the window-style different I edited the KeyboardViewerServer.app/Contents/Resources/English.lproj/MainMenu.nib file with Interface Builder. I selected 'Keyboard Viewer' from the main window and deselected 'Utility' and 'Non Activating' from the Inspector window.

[ Reply to This | # ]
Keyboard Viewer and Character Palette via AppleScript
Authored by: thellum on Oct 28, '05 09:31:54AM

Why not just enable these two apps in System Prefs > International > Input Menu? This way they are there under the national flag icon in the menu bar - hidden but easily accessable. If you have to travel down to the dock for a click on an applescript, is it not the same to travel up to the flag icon to see either palette?

---
The whatchamacallit has to be whatever
or else the whosits will go hey-hey.
~ Scott Adams



[ Reply to This | # ]
Keyboard Viewer and Character Palette checkboxes missing from Input Menu preferences
Authored by: perrysmotors on Nov 14, '07 05:25:40AM

I can't enable them because they are not there. Is anyone else experiencing this problem?



[ Reply to This | # ]
Keyboard Viewer and Character Palette checkboxes missing from Input Menu preferences
Authored by: perrysmotors on Nov 14, '07 05:31:10AM

I forgot to say that the Edit Menu > "Special Characters..." menu item does nothing when I select it.



[ Reply to This | # ]
Keyboard Viewer and Character Palette via AppleScript
Authored by: loren_ryter on Aug 09, '10 10:40:41AM

Personally, I don't like that menu bar item because it takes up space for something I very occasionally use, while being fuggly. Every other menu bar item is black, and that's a big ugly glaring red white and blue. call me a hater i suppose.



[ Reply to This | # ]
Scripts won't work on relaunch
Authored by: michaeldoc on Oct 29, '05 03:37:31AM

Hi. Thanks for the hint. I love applescript and out of curiousity tried the scripts. The problem I had (OSX 10.39) was that once the palette and the keyboard had been used and closed, the scripts would not reopen the items. Sure enough, activity monitor showed that they were still active as background processes. I had to force quit them for the applescript to work again. I have only occasional need for these scripts, but thought anyone using them should be aware of this.



[ Reply to This | # ]
Keyboard Viewer and Character Palette via AppleScript
Authored by: JazzJoey on Oct 30, '05 01:46:04AM
The main function of this script is to[br /] include it in other scripts/software.[br /] Don`t tell me you like the annoying[br /] input-menu more.[br /] If you are a PowerUser like me, you know[br /] what lies behind such scripts, which by the[br /] way can not be found anywhere else ![br /] Be happy or not, but do not bother somebody[br /] who helped you !!! [b]Damn ![/b] [b]Here is a script that should work with 10.3.9 as well:[br /][/b]

tell application "System Events"
	if exists process "CharPaletteServer" then
		try
			quit application "CharPaletteServer"
		end try
	end if
end tell
tell application "Finder"
	open item "System:Library:Components:CharacterPalette.component:Contents:SharedSupport:CharPaletteServer" of the startup disk
end tell

---
Joey
headmaster@spymac.com

[ Reply to This | # ]

Keyboard Viewer and Character Palette via AppleScript
Authored by: emale on Jan 03, '10 06:12:15AM
This has to be modified to work with 10.6:

tell application "Finder"
open item "System:Library:Input Methods:CharacterPalette.app" of the startup disk
end tell

and

tell application "Finder"
open item "System:Library:Input Methods:KeyboardViewer.app" of the startup disk
end tell


[ Reply to This | # ]
Keyboard Viewer and Character Palette via AppleScript
Authored by: macnai on Jan 06, '10 12:30:46PM

Can't get the Keyboard viewer to launch with this script on 10.6. The character palette one works fine.

Edited on Jan 06, '10 12:31:20PM by macnai



[ Reply to This | # ]
Keyboard Viewer and Character Palette via AppleScript
Authored by: emale on Jan 07, '10 09:54:11AM
I have to admit, that to assume, the KeyboardViewser-script works too, if the CharacterPalette-script works was no good idea.
But I found another, less easy, method to start KeyboardViewer here.

The site contains a download link for a UNIX binary file, the explanation how to install it and an alternative AppleScript, that finally works. Have really tested that ;-)

[ Reply to This | # ]
Keyboard Viewer and Character Palette via AppleScript
Authored by: loren_ryter on Aug 09, '10 10:36:29AM

that worked, thanks. but the applescript has a slight error (at least on 10.6.4) -- the keyboard viewer process should have no space. also the click process method gave an error but a simple quit command worked. here's my mod:

tell application "System Events"
if exists (process "KeyboardViewer") then
tell application "KeyboardViewer" to quit
else
do shell script "~/bin/keyboardViewer"
end if
end tell

(* note that I changed the script path to my preferred location for user domain scripts)




[ Reply to This | # ]
Keyboard Viewer and Character Palette via AppleScript
Authored by: rustach on Jul 22, '10 10:54:59AM

I tried using this with 10.6.4 and it didn't work at first. Playing around with it I learned that you need the Input Methods pull-down menu enabled to use this script to bring up Keyboard Viewer. Anyone else care to confirm or try this?



[ Reply to This | # ]
Keyboard Viewer and Character Palette via AppleScript
Authored by: loren_ryter on Aug 09, '10 10:32:59AM

I was able to use the above for 10.6 (see comments on the Keyboard viewer unix script tho) without the "Language & Text" menu shown in the menu bar.



[ Reply to This | # ]
Keyboard Viewer and Character Palette via AppleScript
Authored by: tolva on Dec 03, '11 10:13:17AM
you guys are just trying to show the character palette, right?

why not just:

tell application "CharacterPalette"
	activate
end tell


[ Reply to This | # ]
Keyboard Viewer and Character Palette via AppleScript
Authored by: robg on Jan 08, '12 08:03:31AM
It seems Apple somewhat fixed this in 10.7; I was able to make this script work with Butler to toggle the viewer via a keyboard shortcut. Note: This did not work in 10.6; it seems there are deeper issues there, and you'll need to use the above-linked Unix binary solution.
tell application "System Events"
  if exists (process "Keyboard Viewer") then
    tell application "KeyboardViewer" to quit
    delay 2
    tell application "KeyboardViewer" to activate
  else
    tell application "KeyboardViewer" to activate
  end if
end tell
Because of the delay, it will take a couple seconds for the viewer to appear if it's previously been launched. However, without the delay, the script didn't work for me.

cheers;
-rob.
---
Now: at Many Tricks, maker of useful apps
http://manytricks.com. Previously: founded this site.


[ Reply to This | # ]
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 | # ]
Keyboard Viewer and Character Palette via AppleScript
Authored by: lsloan on Aug 08, '14 12:40:05PM

I use the following, which I set up as a service so I could assign a keyboard shortcut to it:


on isRunning(applicationName)
	tell application "System Events"
		set appNameIsRunning to exists 
			(processes where name is applicationName)
	end tell
	
	return appNameIsRunning
end isRunning

on run {input, parameters}
	if isRunning("CharacterPalette") then
		tell application "CharacterPalette" to quit
	else
		-- tell application "CharacterPalette" to activate
		tell application "Finder" to open item "System:Library:Input Methods:CharacterPalette.app" of the startup disk
	end if
	
	return input
end run

That works very well to make the palette show or hide. However, if I double click a character in the palette, it doesn't insert that character into my text. On the other hand, if I use the "Show Character Viewer" command from the Input menu, double clicking a character there will insert it into my text. Somehow, the way the viewer is invoked from the menu makes it work. I can't figure out what's different, though. The process list doesn't give me any clues.

Anybody know why the character palette/viewer would behave differently depending upon how it was started?

---
Lance E Sloan


[ Reply to This | # ]