DEV Community

Cover image for How I used macOS Accessibility API to fix my VSCode workflow
Eric
Eric

Posted on

How I used macOS Accessibility API to fix my VSCode workflow

There is something that used to break my "flow" daily as a developer, and I bet it happens to you too.

You are deep in debugging mode. You find a suspicious line of code in an obscure file. You take a screenshot (Cmd+Shift+4) to send it to a colleague on Slack or to attach it to a Jira ticket.

Two minutes later, the inevitable question arrives:

"Which file is this in?"

And boom. You have to switch back to your editor, find the file again, copy the relative path (src/components/utils/helper.ts), switch back to Slack, and paste it.

It’s a 10-second friction, but repeated 20 times a day, it becomes a useless mental load.

I looked for tools to solve this. Shottr is great but doesn't read context. CleanShot X is powerful but too expensive and complex for this simple need.

So, as any stubborn developer would do... I decided to code my own solution.

The Technical Challenge: Reading VSCode's Mind

I wanted a simple tool: I capture an area, and boom, the file path and line number are copied to my clipboard, ready to be pasted with the image.

But how do you get that path from outside the editor?

The answer lies in a misunderstood (and sometimes tricky) macOS API: The Accessibility API.

Most modern code editors (VSCode, Zed, Cursor) display the active file path in the window title. Using Swift and the ApplicationServices framework, I built a small "parser" that:

  1. Detects the active application at the moment of the screenshot.
  2. Queries the kAXTitleAttribute of the window.
  3. Cleans the string to properly extract the path and filename.

The result is PastScreen.

Open Source by Conviction, Paid for Convenience

I coded this tool for myself, in native Swift to keep it ultra-lightweight (no Electron here!).

I decided on a hybrid distribution model, inspired by the "Fair Code" movement:

  1. The Code is 100% Open Source: Everything is on GitHub. If you are a developer, you can audit the code, see how I use the capture API, and even compile the app yourself for free. That’s my contribution to the community.
  2. The App Store for Convenience: For those who want to support the project, get automatic updates, and have a signed/notarized app without the hassle, I put it on the Mac App Store for the price of a coffee ($2.99).

Why try it?

If you use VSCode, Zed, or Cursor, PastScreen will change how you document bugs.

  • 📸 Capture an area.
  • 📋 Paste into GitHub/Jira/Slack.
  • ✅ The image appears AND the file path is written right below it.

No more "Which file is this?". No more lost context.

The project is young, and I'm constantly adding support for new IDEs. I would love your technical feedback or Pull Requests on GitHub!


🔗 Links

👉 Check the code on GitHub:
https://github.com/augiefra/PastScreen

👉 Get it on the Mac App Store:
https://apps.apple.com/fr/app/pastscreen/id6755425479

Top comments (0)