DEV Community

Kenneth Larsen
Kenneth Larsen

Posted on • Originally published at kennethlarsen.org on

7 2

How to turn a bash script into a Mac app

My dad joke app in the Mac dock

I had this stupid idea: At work, we love to share dad jokes. And I know that there is a site called https://icanhazdadjoke.com/ which when I curl it returns a dad joke. So why not make a mac app that fetches a dad joke and reads it out loud?

But I didn't even know where to start building a Mac app. I've built a lot of things, but never a Mac app. So I decided to start making a bash script instead. It looks like this:

JOKE=$(curl https://icanhazdadjoke.com)

say -v Daniel "$JOKE"

exit 0
Enter fullscreen mode Exit fullscreen mode

This script will assign the dad joke from the website to a variable called JOKE. Then I call the say command which is a native Mac OS command that reads a string out loud. I pick the voice named Daniel to have a consistent British feel to the delivery of the joke.

I could easily run this and have a lot of fun. But, I wanted to share this with my colleagues. I wanted to turn the bash script into a Mac app.

It turns out that if you create the folder structure of a Mac app and use the bash script as the main.command it actually works. You can see the result here: https://github.com/kennethlarsen/dadjoke.app

Create Your Own App

If you have your own bash script you would like to turn into a Mac app then start by forking my dad joke app. Then:

  1. Edit Info.plist to contain your name and info.
  2. Add your bash script to main.command
  3. Replace cmd.icns with your own icon

That's it! Now you can zip it and send it to your friends.

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (1)

Collapse
 
evanwaltersdev profile image
Evan Walters

This is super awesome. Going to do it now :)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay