Opening Base from the Terminal

I’ve recently been asked if there’s a way to open a database in Base from the Terminal.

You can use the open command for this. This opens a file in the same way as double-clicking it in the Finder. You do need to have Base installed first, though (get a copy here).

Say I have a file on my desktop called contacts.sqlite3.

If Base is already the default app for opening SQLite databases, you can run:

open ~/Desktop/contacts.sqlite3

If Base isn’t the default app for opening database files, you can specify that you want to use Base by running:

open -b uk.co.menial.Base3 ~/Desktop/contacts.sqlite3

Finally, if you want a handy shortcut for this, you can create a function in your terminal profile. I use zsh (the macOS default these days), and I’ve added a line to my ~/.zshrc file:

base3() { open -b uk.co.menial.Base3 "$1"; }

So I can type:

base3 ~/Desktop/contacts.sqlite3

And the file will open in Base.