Home

Awesome

Textinator

<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->

All Contributors

<!-- ALL-CONTRIBUTORS-BADGE:END -->

Simple macOS StatusBar / menu bar app to perform automatic text detection on screenshots.

Overview

Install the app per instructions below. Then, take a screenshot of a region of the screen using ⌘ + ⇧ + 4 (Cmd + Shift + 4). The app will automatically detect any text in the screenshot and copy it to your clipboard.

Watch the screencast

Installation

Download and open the latest installer DMG from the release page then drag the Textinator icon to Applications and follow instructions below to grant Desktop access and optionally grant Full Disk Access.

To launch Textinator the first time you'll need to right-click on the app icon and select "Open" otherwise you may get a warning about unknown developer as the app is not signed with an Apple Developer ID.

Installer DMG

Alternatively, to build from source:

See also Developer Notes below.

Grant Desktop access:

Textinator works by monitoring the file system for new screenshots. The macOS security model prevents apps from accessing files and folders without the user's explicit permission. The first time you launch Textinator, you will be prompted to grant it access to your Desktop.

Desktop access

The default location for new screenshots on your Mac is the Desktop folder so Desktop access should be sufficient in most cases. If you want Textinator to detect screenshots in other locations or if you have changed the default location for new screenshots, you will need to grant Full Disk Access.

Grant Full Disk Access:

System Preferences > Security & Privacy

Upgrading

To upgrade to the latest version, download the latest installer DMG from releases and drag the Textinator icon to Applications. If you have previously granted Textinator Full Disk Access, you will need to remove Textinator from Full Disk Access and re-add it per the instructions above. (This is a limitation of the macOS security model and not something Textinator can control.)

Usage

Menu Bar Icon

Settings

When you first select Start Textinator on login, you will be prompted to allow Textinator to send AppleScript events to the System Events app. This is required to add Textinator to the Login Items list. The screenshot below shows the prompt you will see.

System Events permission

Inspiration

I heard mikeckennedy mention Text Sniper on Python Bytes podcast #284 and thought "That's neat! I bet I could make a clone in Python!" and here it is. You should listen to Python Bytes if you don't already and you should go buy Text Sniper!

This project took a few hours and the whole thing is a few hundred lines of Python. It was fun to show that you can build a really useful macOS native app in just a little bit of Python.

Textinator was featured on Talk Python to Me! Thanks Michael Kennedy for hosting me!

How Textinator Works

Textinator is built with rumps (Ridiculously Uncomplicated macOS Python Statusbar apps) which is a python package for creating simple macOS Statusbar apps.

At startup, Textinator starts a persistent NSMetadataQuery Spotlight query (using the pyobjc Python-to-Objective-C bridge) to detect when a new screenshot is created.

When the user creates screenshot, the NSMetadataQuery query is fired and Textinator performs text detection using a Vision VNRecognizeTextRequest call.

Textinator can also monitor the clipboard and detect text in images copied to the clipboard.

Notes

License

MIT License

See Also

Text Sniper which inspired this project.

Contributors ✨

Thanks goes to these wonderful people (emoji key):

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --> <!-- prettier-ignore-start --> <!-- markdownlint-disable --> <table> <tbody> <tr> <td align="center" valign="top" width="14.28%"><a href="https://github.com/bwagner"><img src="https://avatars.githubusercontent.com/u/447049?v=4?s=75" width="75px;" alt="Bernhard Wagner"/><br /><sub><b>Bernhard Wagner</b></sub></a><br /><a href="#ideas-bwagner" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/RhetTbull/textinator/commits?author=bwagner" title="Code">💻</a> <a href="https://github.com/RhetTbull/textinator/commits?author=bwagner" title="Tests">⚠️</a></td> </tr> </tbody> </table> <!-- markdownlint-restore --> <!-- prettier-ignore-end --> <!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the all-contributors specification. Contributions of any kind welcome!

Developer Notes

If you want to work on Textinator yourself or contribute changes, here are some notes:

Clone the repo and cd into the repo directory.

git clone git@github.com:RhetTbull/textinator.git cd textinator

If you want to contribute back to Textinator, fork the repo and clone your fork instead.

Install requirements and development requirements via pip:

python3 -m pip install -r requirements.txt -r dev_requirements.txt
pre-commit install

See also notes below about Testing.

Building the DMG for distribution requires create-dmg which can be installed with homebrew:

brew install create-dmg

To build Textinator, run the build.sh script:

./build.sh

This script cleans out old build files, builds the app with py2app, signs the app, and builds the DMG.

Textinator stores it's preferences in ~/Library/Application\ Support/Textinator/Textinator.plist. This is non-standard (by convention, apps store their preferences in ~/Library/Preferences/), but RUMPS doesn't provide a method to access the Preferences folder and it does provide a method to access the Application Support folder (rumps.App.open()), so I went with that.

The preferences can be read from the command line with:

defaults read ~/Library/Application\ Support/Textinator/Textinator.plist

For development and debugging it may be helpful to enable the debug log by setting debug=1 in Textinator.plist. You can do this from the command line with:

defaults write ~/Library/Application\ Support/Textinator/Textinator.plist debug -bool true

Similarly, you can disable the debug log with:

defaults write ~/Library/Application\ Support/Textinator/Textinator.plist debug -bool false

When debug is enabled, Textinator will log to ~/Library/Application\ Support/Textinator/Textinator.log. I find this more convenient than using the macOS Console app. Textinator will always log to the Console log as well so you can use Console if you prefer and filter on Textinator.

Most features of the app can be tested by simply running the textinator.py script: python3 src/textinator.py. The Services menu feature requires the app be built and installed because it needs runtime access to information in the app bundle's Info.plist which is built by py2app.

The version number is incremented by bump2version which is installed via python3 -m pip install -r dev_requirements.txt. To increment the version number, run bumpversion patch or bumpversion minor or bumpversion major as appropriate. See bumpversion --help for more information.

I've tried to document the code well so that you can use Textinator as a template for your own apps. Some of the features (such as creating a Services menu item) are not well documented (especially with respect to doing these things in python) and took me a lot of trial and error to figure out. I hope that this project will help others who want to build macOS native apps in python.

Testing

Textinator uses pytest to run unit tests. To run the tests, run pytest from the project root directory. Before running the tests, you'll need to install the development requirements via python3 -m pip install -r dev_requirements.txt. You will also need to enable your Terminal app to control your computer in System Preferences > Security & Privacy > Privacy > Accessibility. This is because the testing uses System Events scripting via applescript to simulate user actions such as clicking menu items. Your Terminal will also need to be granted Full Disk Access in System Preferences > Security & Privacy > Privacy > Full Disk Access.

The test suite requires the built app to be installed in /Applications/Textinator.app. Before running tests, uses ./build.sh to build the app then copy dist/Textinator.app to /Applications/Textinator.app.

The tests will modify the Textinator preferences but will backup your original preferences and restore them when testing is completed. The tests will also modify the clipboard and will create temporary files on the Desktop which will be cleaned up when testing is completed.

The test suite is slow due to required sleeps to allow the app to respond, Spotlight to index new files, etc. (Takes approximately 5 minutes to run on my MacBook Air). Because the test suite interacts with the user interface, it is best not to touch the keyboard or mouse while the tests are running.

The Services menu item is not tested by the test suite so this feature should be tested manually.