fbpx

Typing Sanskrit diacritics using OSX press-and-hold

There are a few decent methods for entering Sanskrit (and other languages’) diacritical marks (accents, vowel marks, alternate characters, etc), but if you use them daily, you want your method to be as quick and easy as typing itself. All the alternate characters you could want (mostly!) can be found in a dropdown in your menu bar on the upper right. (This is a Mac-only post, because it’s all I know, but if someone wants to write down the process for Windows and post it in the comments, please do). That dropdown says “Show Emoji & Symbols” and is up here:

It opens a window that has all the alternate characters in it, and you can double-click any of them to add it to text. (That’s the cumbersome way to add diacritics, btw.)

So doing that is easy, but totally slows down typing, and if you use them constantly as I do, the best method I’ve found (on Mac) for adding diacritics is to hack the OSX function known as “press-and-hold.” This is the function that gives you a string of alternate characters to choose from if you hold down a key for about a second. Trouble is, the standard strings of alternate characters don’t include the right ones for Sanskrit.

So here’s instructions for modifying the file that governs which characters are in those strings. (I don’t have the programming skill to invent this—I’m using instructions from here and here.) When I first did it some years ago it was easier, because the information was in a preference file that you could just directly modify, but since OSX Sierra, you can’t directly access the file without disabling what’s called “System Integrity Protection,” (SIP) which is also called “Rootless,” which is probably unintentional poetry. This makes the maneuver more dangerous, because SIP does important protective things. Be sure to turn it back on once your mischief is managed.

1. Turn off System Identity Protection

Follow the instructions at this link to turn off SIP. Here’s my shorthand:

Shut down the computer.
Boot your Mac in Recovery Mode (Command-R while starting up),
open the Terminal application from the menu,
type csrutil disable,
then reboot normally.

2. Open & modify the press-and-hold file

Open a Finder window. Navigate to: /System/Library/Input Methods/PressAndHold.app/Contents/PlugIns/PAH_Extension.appex/Contents/Resources/ in the Finder. To go to it quickly, press ⇧⌘G and paste the string in.

Note 1: Remember that there are two different Library folders. You want the one nested inside “System” not the one just nested inside Macintosh HD (or whatever your hard drive is named).

Note 2: As you go through that stack of files, you’ll find that when you get to PressAndHold.app, you can’t go further. 2-finger click on the file name (it’s really a “package”) and click “show package contents.” Do the same thing when you get to PAH_Extension.appex.

When you get to the list of Keyboard preference files (they all start with “Keyboard”, then have a language marker like “-en” and end in “.plist”), find the one you use. If you don’t know which one you’re using, look in System Preferences > Keyboard > Input Sources.

Backup the .plist file you’re going to modify by copying it and saving it somewhere with a useful name (like “Keyboard-en-ORIGINAL.plist”) so you can put it back if you err.

Open the file using a code editor. I use Atom, which you can download for free here. Once it’s open, you’ll see a set of code blocks that look like this:

<dict>
	<key>Roman-Accent-A</key>
	<dict>
		<key>Direction</key>
		<string>right</string>
		<key>Keycaps</key>
		<string>A À Á Â Ä Æ Ã Å Ā</string>
		<key>Strings</key>
		<string>A À Á Â Ä Æ Ã Å Ā</string>
	</dict>

That’s the code for holding down a capital A before I modified it. The plain “A” is first in the string, then all the alternates, in the order they appear. For Sanskrit, I want my most commonly used alternates to appear in this list, and I also want them to be first in the list because I just like that (this is optional). So I modified the code to this, putting the long-vowel version (“Ā”) first:

<dict>
	<key>Roman-Accent-A</key>
	<dict>
		<key>Direction</key>
		<string>right</string>
		<key>Keycaps</key>
		<string>A Ā À Á Â Ä Æ Ã Å</string>
		<key>Strings</key>
		<string>A Ā À Á Â Ä Æ Ã Å</string>
	</dict>

Be sure to put the alternate characters in both “Keycaps” and “Strings” strings. Use the “Show Emoji & Symbols” dropdown to find all the characters you need. Then go down through the file, adding any alternate characters you want. (If you want to just download a text file with the full set of Sanskrit mods I use, here it is. You would then just open it and copy the entire contents over the contents of the .plist file in Atom.) Save the file.

3. Turn SIP/Rootless back on & restart

Test that it works, and once it does, turn Rootless back on using these instructions, as above. Shorthand:

Shut down the computer.
Boot your Mac in Recovery Mode (Command-R while starting up),
open the Terminal application from the menu,
type csrutil enable,
then reboot normally.

That’s it! I hope it works for you and helps your flow as it does mine.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top