How to turn a bash script into a Mac app
Kenneth Larsen
Posted on April 19, 2019
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
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:
- Edit Info.plist to contain your name and info.
- Add your bash script to main.command
- Replace cmd.icns with your own icon
That's it! Now you can zip
it and send it to your friends.
Posted on April 19, 2019
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.