DEV Community

Kenneth Larsen
Kenneth Larsen

Posted on • Originally published at kennethlarsen.org on

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.

Top comments (1)

Collapse
 
evanwaltersdev profile image
Evan Walters

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