GithubHelp home page GithubHelp logo

fn-lang-switcher's Introduction

THE PROBLEM:

ezgif-5-86271457e6

Not only its slow, but when mouse cursor happens to be in the center of the screen, it selects the wrong language for you!

      

THE SOLUTION (get rid of the pop up):

Install "issw" a small utility for macos to switch input sources from a command line.

git clone https://github.com/norflin321/input-source-switcher.git
cd input-source-switcher
mkdir build && cd build
cmake ..
make
make install

By default executable will be installed as /usr/local/bin/issw

Create fn.py file in ~/. Or clone the repository.

import os
from pynput import keyboard

def on_press(key):
    key_str = '{0}'.format(key)
    if (key_str == '<179>'):
        stream = os.popen('/usr/local/bin/issw')
        output = stream.read().strip() 
        if (output == 'com.apple.keylayout.ABC'):
            os.system('/usr/local/bin/issw com.apple.keylayout.Russian')
        else:
            os.system('/usr/local/bin/issw com.apple.keylayout.ABC')


with keyboard.Listener(on_press=on_press, on_release=None) as listener:
    listener.join()

<179> is key code for fn. Don't forget to run issw -l in terminal to get list of available input sources and modify script above if needed!

Set this to "Do Nothing"

ezgif-5-aeb126ae5e

Setup auto run of the script every time you log in (python3 should be installed).

  1. Install pynput python module: /usr/bin/python3 -m pip install pynput or, if you are using your own python installation: /your/python3/executable/path -m pip install pynput
  2. Inside fn.plist file, change paths to the python executable (if you are using custom python installation) and the script file. Mine is /Users/norflin/fn.py. Paths should be full.
  3. Copy the plist file to special directory: cp -R fn.plist ~/Library/LaunchAgents/.
  4. Then run this command: launchctl load ~/Library/LaunchAgents/fn.plist - it will tell mac to run this file every time you log in. If you want to stop it run launchctl unload ~/Library/LaunchAgents/fn.plist and remove the file rm -rf ~/Library/LaunchAgents/fn.plist.
  5. Mac might ask you to grant permission for python to monitor input from your keyboard and Accessibility. Generally macOS asking about Input Monitoring, add your python3 executable to Accessibility if no popup with this showed.
  6. Restart. Log in. It should work.

P.S. Don't forget to reinstall pynput after upgrades. Also see issue #2.

      

RESULT:

You can toggle input source with "fn" button, but without showing the pop up!

fn-lang-switcher's People

Contributors

norflin321 avatar saba-sabato avatar daverk avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.