As I’ve written about in the past, I use Don Melton’s video transcoding tools to rip Blu-Ray discs. I also use Homebrew to install some of the transcode video dependencies, as well as other Unix tools.
Keeping these tools current isn’t overly difficult; it only requires a few commands in Terminal:
$ brew update
$ brew upgrade
$ sudo gem update video_transcoding
My problem is that I often forget to do this, because—unlike most GUI Mac apps and the Mac App Store—there’s no built-in “hey, there’s an update!” system. Suddenly, two months and many revisions later, I finally remember (usually when I see a tweet about a new version of something.) So I thought I’d try to write my own simple update reminder.
I didn’t really want a scheduled task, like a launchd agent—it’s not like these tools need to stay current on a daily basis. (And one of them needs to run with admin privileges, which complicates things.) I just wanted something that would remind me if it’d been a while since I last checked for updates, and then install the updates if I wanted it to do so.
After mulling it over, I came up with a script that runs each time I open a Terminal window (which I do daily). The referenced script looks at the date on a check file, and asks me if I’d like to check for updates if that date is more than a week older than today’s date. This is perfect for my needs: The reminder is automatic, but I can choose when to install the updates based on what I’m doing at the time. If it’s been under a week since I last checked, nothing at all is different about my Terminal launch.
Read on for the script and implementation details. (Note: This is not written for a Terminal beginner, as it assumes some knowledge about how the shell works in macOS.)
To make my script run every Time I open Terminal, I just called it on the last line of my user’s .profile file:
The .profile file runs each time you open Terminal, so that took care of the “automatic” part of the problem. The script itself handles the time issue and checks for updates. Here’s how that looks:
# Update Homebrew and transcode-video based on time since last check
# Run touch /path/to/checkfile/.DateOfLastVidToolsCheck once
# before using this script for the first time.
# This command returns a lot of data, including a file's modification
# time formatted for use as a variable named st_mtime.
eval `stat -s /path/to/checkfile/.DateOfLastVidToolsCheck`
time_gap=$((curr_time - st_mtime))
# Time values for check
# One day = 86400
# One week = 604800
# Two weeks = 1209600
# One month = 4838400
if [ "$time_gap" -gt "604800" ]; then
read -p "Check for Homebrew/transcode-video updates? It's been a while… " answer
case $answer in
[yY]* ) brew update
sudo gem update video_transcoding
echo "Please reply YyNn only."; break ;;
To use this script (remember to make it excecutable, and store it on your path), you’ll need a file named .DateOfLastVidToolsCheck saved somewhere; the leading dot makes it invisible in Finder. I saved mine in my user’s bin folder, where I keep all my scripts. The easiest way to create the file is to just touch it:
This creates a file with the current time as the modification timestamp. Edit the script as necessary to change the paths (lines 10 and 31), and perhaps change the update interval on line 21—it’s stated in seconds, and some additional values are shown in the comments above.
Now when I open a Terminal window, nothing’s different…unless it’s been over a week since I last checked for updates. If that’s the case, my script kicks in, presenting a prompt that I need to reply to in order to continue:
Check for Homebrew/transcode-video updates? It's been a while… y Already up-to-date. Password: Updating installed gems Nothing to update
While this isn’t a fully automatic system, it’s more than good enough for my needs: It’ll help me stay current with my video transcoding tools with very little work on my part. (I’m sure there are other solutions to this problem, and/or improvements that could be made to my script…if you have any to share, please comment!)