Learn Python with Talk Python's 270 hours of courses

Textinator and Building macOS Apps with Python

Episode #383, published Wed, Sep 28, 2022, recorded Sun, Sep 25, 2022

For all the amazing powers of Python, deploying packaged apps that leverage native OS-level capabilities isn't one of them. But it can be done and we have a great guest, Rhet Turnbull, here to tell us how he built his distributable macOS app Textinator that uses macOS's native vision recognition framework through Python.

Watch this episode on YouTube
Play on YouTube
Watch the live stream version

Episode Deep Dive

Guest Introduction and Background

Rhett Turnbull is a seasoned Mac user and software developer with a longtime passion for self-taught programming. Professionally, he serves as an officer in the U.S. Space Force, applying his astronautical engineering background to support critical space systems. In his spare time, Rhett works on Python projects, including “Textinator” — a macOS menu bar app built with Python. His journey from a TRS-80 Model 3 computer, through Perl and Fortran, to Python demonstrates his lifelong interest in learning new technology and building tools that bring together community, creativity, and function.

What to Know If You're New to Python

If you're newer to Python, here are some pointers from this episode before you dive deeper:

  • Understand Python’s basic packaging story: pip, virtual environments, or pipx for command-line tools.
  • Know how Python can hook into system-level libraries (e.g., macOS frameworks) through bridging layers like PyObjC.
  • Be comfortable with simple Python scripts before taking on GUI or OS integration projects.
  • Consider that distributing Python applications to non-developers takes extra steps (such as py2app or code signing) so users can run them easily.

Key Points and Takeaways

  1. Building and Distributing Native macOS Apps with Python Textinator’s example proves you can distribute a “real” Mac app, complete with an icon and menu bar presence, using Python as your primary language. By combining tools like PyObjC and py2app, you can bundle Python and supporting libraries into a single .app bundle for end-users.
  2. Leveraging macOS Frameworks via PyObjC PyObjC is a Python-to-Objective-C bridge that exposes Apple’s native APIs—like the file system, notifications, and advanced ML frameworks—to Python developers. It uses a direct translation approach, keeping Objective-C method names and letting you effectively “call in” to macOS-level features, saving you from writing Swift or Objective-C yourself.
  3. Incorporating Apple’s Vision Framework for OCR and Beyond Textinator uses Apple’s Vision framework to automatically detect text in screenshots, harnessing the Mac’s built-in machine learning for OCR in just a few lines of Python. This approach simplifies code (no big external models to download) while tapping into GPU or Apple’s neural engine for speedy, accurate recognition.
  4. Rumps for Quick and “Ridiculously Uncomplicated” Menu Bar Apps Rumps (Ridiculously Uncomplicated macOS Python Statusbar apps) offers a streamlined way to write Python code that appears as an icon in the Mac menu bar. The framework handles the boilerplate around menu items, event handling, and notifications, allowing you to focus on your app’s core logic in just a few lines of code.
  5. Balancing Mac Security and User Experience macOS requires permissions and code signing to protect user data. Developers must include certain entitlements (e.g., reading files on the desktop) and handle prompts or code-signing steps that build trust with end users. Taking the time to configure an Info.plist file and signing the app can greatly smooth the user’s installation experience.
  6. Setting Up Python on macOS: Choosing the Right Installation Rhett discusses potential pitfalls installing Python via system-level packages like Homebrew. For stability, you can download direct from python.org or compile your own to prevent conflicts with Homebrew updates. Tools like pyenv or pipx also help manage Python versions and dependencies in a more controlled environment.
  7. Python’s Role in the U.S. Space Force Rhett’s background in astronomics and the Space Force highlights how Python is used in scripting, data processing, and building cloud-native applications in defense contexts. Although they rely on many custom or specialized systems, Python’s approachability and ecosystem add significant value for analyzing and automating satellite and network operations.
  8. Pipx for Command-Line Tool Distribution For non-GUI Python apps, pipx provides a simple way to install and run command-line applications in an isolated environment. It’s especially handy for distributing small command-line scripts to coworkers or clients, as it reduces conflicts and keeps system dependencies clean.
  9. The Use Case for Automated Text Recognition in Screenshots Textinator was inspired by other OCR/snippet apps, but Rhett chose to write his own to harness the built-in ML on macOS. Whether you’re copying text from a video or capturing a QR code from a screenshot, such an app cuts out manual typing and helps with daily productivity tasks.
  10. Practical Advice for Building Your Own Python Tools Rhett’s experience shows that you don’t need thousands of lines of code to build a functional, native-like tool—Textinator was initially just a few hundred lines. If you have a practical itch to scratch, start small with Python scripts, leverage the OS bridging libraries, and wrap up your creation with a distribution tool like py2app or pipx for a polished end-user experience.

Interesting Quotes and Stories

“All I wanted was for my screenshot to instantly give me the text on my clipboard. It turns out it was only a few hundred lines in Python once I knew the right frameworks.” — Rhett Turnbull, on coding Textinator in a weekend.

“The Space Force is all about digital fluency… we operate everything through a piece of glass and a network.” — Rhett, on how Python’s practicality fits well with space operations’ requirements.

Key Definitions and Terms

  • PyObjC: A Python-to-Objective-C bridge allowing direct calls into macOS frameworks and system APIs.
  • py2app: A Python package that bundles your Python code and runtime into a distributable .app for macOS.
  • Rumps: A lightweight library for creating menu bar (status bar) applications on macOS with minimal boilerplate.
  • Vision Framework: Apple’s machine learning toolkit that offers OCR, object detection, and more, callable from Objective-C or bridging frameworks like PyObjC.

Learning Resources

Below are recommended resources for listeners who want to build or sharpen their Python skills. Here are some curated links.

  • Python for Absolute Beginners: A comprehensive start to Python, covering core data types, loops, functions, and the fundamentals of programming. Perfect for brand-new developers or anyone looking to strengthen their Python base.

Overall Takeaway

Building native macOS apps with Python is not only possible but can be surprisingly straightforward by combining the right open-source tools and Apple’s built-in frameworks. Rhett Turnbull’s Textinator showcases how just a few hundred lines of Python can leverage powerful machine learning, file system events, and a familiar Mac-native user experience. Whether you’re automating screenshot OCR or exploring an idea for a menu bar tool, Python’s flexibility and approachable ecosystem offer a terrific springboard.

Links from the show

Rhet Turnbull on Twitter: @RhetTurnbull
Textinator app: github.com
Homebrew Python Is Not For You: justinmayer.com
asdf: asdf-vm.com
Space Force: spaceforce.com
TextSniper app: textsniper.app
Apple's Natural Language ML: developer.apple.com
Apple's Vision ML: developer.apple.com
py2app: py2app.readthedocs.io
py2exe: pypi.org
pyinstaller: pyinstaller.org
RUMPS: github.com
Michael's RUMPS app - URLify: github.com
Home Brew: brew.sh
pipx: github.com
Gooey: github.com
PLS CLI: github.com
textX: pypi.org
Join Space Force: spaceforce.com
Beeware: beeware.org
Watch this episode on YouTube: youtube.com
Episode transcripts: talkpython.fm

--- Stay in touch with us ---
Subscribe to Talk Python on YouTube: youtube.com
Talk Python on Bluesky: @talkpython.fm at bsky.app
Talk Python on Mastodon: talkpython
Michael on Bluesky: @mkennedy.codes at bsky.app
Michael on Mastodon: mkennedy

Talk Python's Mastodon Michael Kennedy's Mastodon