James Fator

Touch grass using the Macbook Touch Bar

28 December 2022

Even though we can all admit the Touch Bar was a failure, I've always wanted to make something using it.

After watching a "grass touching" video by Your Average Tech Bro, I wanted to take it a step further and make the grass interactive. I made a quick little app that allows you to brush your finger across simulated grass using the Macbook Pro Touch Bar.

Check out the GitHub repository here.

Last time I touched XCode was years ago before Swift was created, so this was a fun little intro to Swift as well. I prioritized just getting this concept made, not making it good, so I'm sure there's subpar Mac/Swift practices here.

Basically this is a new XCode project with a NSWindowController to create a NSTouchBar. We then give the NSTouchBar an NSCustomTouchBarItem with a custom NSView. I made some grass blades in Photoshop which our NSView loads ~800 instances of.

There's a background loop that moves the blades left to right in a sine wave to mimic wind. Then when someone touches the Touch Bar, we receive an event of where they're touching, so depending on the direction of their movement, we can add an extra force onto the blades within reach.

This isn't the most realistic way of moving grass with your hands; ideally we'd have some rotation added as well, but given I only wanted to spend a little bit of time on this, it works for me. Throw some nature music in the background and you've got a nice, calming app to absolutely slaughter any stress you had previously.