Skip to content
Advertisement

How to type text in Russian from clipboard using applescript without changing the system language on the Mac?

I automate the filling of forms in Latin alphabet, but in one place there is a field where i need to type the text in Russian.

Before filling in, I copy the desired word in Russian and I want to type it from the clipboard without changing system language / encoding / charset.

In other words. Just type a word from the clipboard in Russian letters and continue working with the Latin alphabet.

How can this be done using applescript?

JavaScript

Shell i use this part like that or something?

JavaScript

The solution to just copy and paste the word in Russian does not work. It needs to be written.

Please, direct which way to dig. Any ideas?

Advertisement

Answer

This solution uses code written by jackjr300 in his answer: Is it possible to keystroke special characters in AppleScript?

Using Xcode, I created the command line tool TypeCharacters and copied it to /usr/local/bin/

I then incorporated it into the following example AppleScript code:

JavaScript

The output of which was:

enter image description here


Notes:

I used Google Translate to translate “Russian characters” to Russian, Русские персонажи, and “Japanese characters” to Japanese, 日本語の文字.

Testing by writing to Safari at this website into an answer text box the results were the same regardless of what the input source was set to.

The example AppleScript code, shown above, was tested in Script Editor under macOS Catalina with Language & Region settings in System Preferences set to English (US) — Primary and two input sources in System Preferences > Keyboard > Input Sources, U.S. and Russian, and worked for me without issue1.

  • 1 Assumes necessary and appropriate settings in System Preferences > Security & Privacy > Privacy have been set/addressed as needed.

Code used from the linked answer to create the command line tool TypeCharacters in Xcode:

JavaScript


Note: The example AppleScript code is just that and sans any included error handling does not contain any additional error handling as may be appropriate. The onus is upon the user to add any error handling as may be appropriate, needed or wanted. Have a look at the try statement and error statement in the AppleScript Language Guide. See also, Working with Errors. Additionally, the use of the delay command may be necessary between events where appropriate, e.g. delay 0.5, with the value of the delay set appropriately.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement