I’m happy to announce the release of sendkeys 2.0. πŸš€πŸŽ‰!

This is a major release and includes the following:

  • Rewrite from JavaScript to Swift.
  • Installable via homebrew.
  • Support for automating mouse events!!!

Installation

brew install socsieng/tap/sendkeys

Example usage

sendkeys --application-name "Notes" --characters "Hello<p:1> world<c:left:option,shift><c:i:command>"

hello world example

Activates the Notes application and types Hello (followed by a 1 second pause) and world, and then selects the word world and changes the font to italics with command + i.

sendkeys -c "<m:100,300,300,300:0.5><p:0.5><m:100,300:0.5>"

mouse move example

Moves the mouse cursor from (100, 300) to (300, 300), pausing for 0.5 seconds and moving back to (100, 300).

Why rewrite?

You might be wondering about why anyone would bother rewriting anything from JavaScript to Swift. In my case, it was to provide mouse automation capabilties and overall simplification. With the rewrite, I was able to unify how keyboard and mouse events are dispatched to macOS using Quartz instead of AppleScript (osascript for keyboard) and Quartz for mouse.

Prerequisites

sendkeys requires macOS 10.11 or later.

When running from the terminal, ensure that the terminal has permission to use accessibility features. This can be done by navigating to System Preferences > Security & Privacy > Privacy > Accessibility and adding your terminal application there.

accessibility settings

What’s next?

There are some additional features and learnings that I got out of this release that I plan to cover in subsequent posts. Keep an eye out for:

  • Recording and replaying mouse events, and
  • Automating releases with GitHub Actions and brew.