AppleScript for playing Rifftrax

Anyone that knows me, knows that I am a huge fan of Mystery Science Theater 3000 and, an off-shoot of that, Rifftrax. One of the great things about Rifftrax is that they sell some MP3-only commentaries. Since they don’t need to license the movie, they can target summer blockbusters like Star Wars: Rogue One, Twilight, and Harry Potter. The only downside to this is that you have to sync up the audio of the MP3 to the movie’s audio. This isn’t too big a deal, especially with Rifftrax’s new auto-syncing application for your phone. That said, sometimes I prefer to watch Rifftrax on my computer for the convenience of the audio coming from the single source (my laptop speakers).

At the beginning of a Rifftrax commentary, instructions are given for when to pause the MP3 and at what point in the movie to un-pause the MP3. That way, the jokes will line up with the movie audio. I will watch movies using VLC and listen to the commentary using QuickTime. Easy, right? But what happens when you need to pause the movie? You have two separate applications playing and, no matter how fast you are, you will not be able to hit the pause buttons of both applications at the same time.

To deal with this issue, I wrote up an AppleScript to hit pause on both applications when running the script. Compiling this script to an application, I can place it in the Dock of my Macintosh when playing a Rifftrax and click to stop and resume at any time. It is a really simple little script to handle this:

tell application "QuickTime Player"
    if document 1 is playing then
        pause document 1
    else
        play document 1
    end if
end tell
tell application "VLC"
    play
end tell

I think the code is pretty readable. QuickTime needs to be told to play or pause the audio if the file is actually being played or not. VLC will just toggle between the two so we don’t need to bother checking. To use this script, simply paste the code into Script Editor, which should have come with your Macintosh, and Export the script as an Application.

Export as Application

That is all there is to it. “It’s time for Rifftrax.”

Tab Modifier Plus Chrome Extension

As a web developer, I often find myself with local, staging, and live versions of the same website. Obviously, one can tell which environment one they are on by viewing the address in the browser bar. I find it handy to have an additional visual cue, though, to make it even clearer. I have found a neat little extension for Chrome or Opera called Tab Modifier Plus that allows you to set custom favicons for tabs based on the URL.

When adding a new tab rule, you can match the URL by text matching or with regular expressions.

Add New Rule

In my case, my local sites all begin with “http://stirrell.” so I can use that with a “Starts with” rule. Once you have set up the URL match, you can then choose a number of options for the tab:

  1. Choose a favicon.
  2. Pin the tab.
  3. Prevent the tab from being duplicated.
  4. Ask for confirmation before closing the tab.
  5. Mute sounds on the tab.

In my case, I will choose an included favicon available in Tab Modifier Plus, a green circle, to let me know I am on a “safe” site:

Custom favicon

Then, of course, I can use a red circle for live web sites.

Although I use Tab Modifier Plus as a visual clue for “safe” and “dangerous” sites, I can see many other uses for this nicely-made extension. I appreciate that the options page uses Google’s Material look-and-feel. I have also tested in Opera and it seems to work just fine. I definitely recommend this extension.

“Indie Game” – Movie Review

Indie Game posterIt has been a while since I saw the first installment of “Indie Game,” a documentary that showcases independent game developers and their creations. Included in “Indie Game” are Super Meat BoyFezand Braid, which have been recent stand-out games. I noticed on Netflix that a “follow-up” documentary was available for viewing, “Indie Game: After Life.” I really enjoyed the first movie, so I dove right in and was not disappointed.

As a retro gamer, I have a yearning for earlier generations of game creation where a small team, or even a single person, could have inspiration and drive and create an entire game. Obviously the game industry is a lot different now with teams and budgets rivaling those of Hollywood films and while modern blockbuster games are great, there is something special about a single programmer’s vision. It feels much more like a person’s artistic expression. Part of the mystique, of course, was the thought… “maybe I could do that.”

One thing that “Indie Game” makes clear is that creating a game is not a simple endeavor. They are suffering for their art – grueling hours in front of their computers. The persistence and overwhelming amount of work that these creators put into their games is nothing short of amazing. You cannot help but root for their success. It is inspiring to see people so creative and passionate. And it is gratifying to see that there is a market for unconventional entertainment. There are no focus groups here – just a blind faith that what they are making will find an audience.

Watching a movie like this always inspires me. I think that our society has gotten to be incredibly cynical, something touched on in “Life After,” and seeing the passion of the developers is heartwarming. It is easy to be hypercritical without considering the energy put into these projects – years of hard work where the chance of success is slim – and putting a face to the people behind the product is a refreshing change of pace.

“Man vs. Snake” – Movie Review

Man vs. SnakeI just caught “Man vs. Snake – The Long and Twisted Tale of Nibbler” on Netflix and this is the kind of retro and nostalgia that I love. I think that “Man vs. Snake” could almost be a spiritual sequel to the popular video game movie, “King of Kong.” You have some of the same cast of characters – Billy Mitchell and Walter Day are both present as well as a historical rundown of the Twin Galaxies Arcade. For viewers of “King of Kong,” much of this material will be very familiar. That said, the story is very well presented with some fun animation.

Like “King of Kong,” there is competition between multiple players trying to attain the high score for an arcade game, in this case Nibbler. If you’ve played a variation of the game “Snake” on a cellphone or old computer, you have an idea of the gameplay. On this journey, there is some question regarding possible chicanery in the quest for a high score. But, mostly, it is the story of a person challenging himself to try to attain a goal that few people could imagine. Unlike Donkey Kong, Nibbler is a game that people “marathon” for a high score, or play for extremely long periods of time. The players build up a cache of extra lives to allow themselves breaks and play up to and beyond 40 hours in a single high score attempt.

I actually never ran into a Nibbler game when I was growing up – or, if I did, I don’t remember ever seeing it. And there is a humorous part of the movie talking about Nibbler’s dubious claim to fame in video game history. It normally is not thought of when talking about the classics we all remember like PacMan and Asteroids. However, the long play sessions possible in Nibbler allowed for players, for the first time ever, to possibly achieve a billion points on a game. No kill screen here. So, it isn’t fond memories of pumping tokens into Nibbler as a child that makes the story so compelling for me. Instead, it is the general nostalgia for these arcade games and a person’s quest to try to persevere and achieve arcade glory.

I really loved “Man vs. Snake.” It is the story of someone ordinary attempting to accomplish something extraordinary. It is so refreshing to see a celebration of someone “normal” – in so much as someone who can play an arcade game for 40 hours is normal. If you enjoyed “King of Kong” or “Chasing Ghosts” then I think you’ll really enjoy “Man vs. Snake.” And as much as I liked “King of Kong,” this movie didn’t have as much of a “soap opera” feel to it which I appreciated.

Dynamically Overriding a Page’s Template

It is easy to override the template for a post or page in WordPress in a few ways. For example, the naming of page template files can be used to override a single page’s template:

  • page-{id}.php
  • page-{slug}.php

Or, a page template can be chosen in the Page Attributes section when editing a page:

Choose a Template

This works great when you always want a page template to be used for a particular page. But what if you need to change a page’s template based on something that might change? Like the current user’s role, for example? Well, you can use the template_include filter in WordPress to override the normally-used template in a function.

Start out by attaching a function to the filter:

add_filter( 'template_include', 'dynamic_page_template' );

This can be added to your theme’s functions.php file or to a custom plug-in. In this example, the function called dynamic_page_template will be invoked. This function will accept the parameter, $page_template, which is the $page_template that is to be used. If you want the page template defined in a way above (by the template name or the selected template in the Page Attribute area) to work as normal, simply returning $page_template will accomplish this. However, we can also set $page_template to something different and return that instead. Here is a simple example:

function dynamic_page_template( $page_template ){
 global $post;
 if (100 == $post->ID) :
 $page_template = get_template_directory() . "/page-test.php";
 endif;

return $page_template;
 }

In this example, we are pulling in the $post (or page) information by calling it globally. Then, we can check for the post ID value. If the ID is 100, we are setting the page template dynamically to the page-test.php file in our theme. The get_template_directory call gets us the directory for our theme. Now, even if we have a file named page-100.php, our function will take precedence.

“From Bedrooms to Billions” Movie Review

From Bedrooms to BillionsThose who know me know that I am hopelessly mired in the past. I have a working Atari 7800 and an Atari Jaguar (and regret parting with my Atari Lynx and Falcon). I still like 80s music, tv shows and movies. And I make regular pilgrimages to Funspot in New Hampshire, a great classic arcade to scratch that itch periodically.

So, I am really the target audience for a movie like “Bedrooms to Billions,” a documentary about the computer programming renaissance that occurred in the U.K. during the 80s with the introduction of 8 and 16-bit home computers. While I didn’t have any exposure to more European-centric machines like the famous ZX Spectrum, I did get some keyboard time on Atari 8-bits and STs as well as Commodore 64s and Amigas. I was a big fan of the underdog machines and was disappointed to see them disappear when the computer market became boring commoditized PC clones. And, I happen to be a web developer these days so I am still passionate about computers.

Yet, and it pains me to say, I found “Bedrooms to Billions” to be fairly boring. Many of the stories are very matter-of-fact and there wasn’t much depth given to the people behind the software and the machines. I wanted more of a sense of the work environments in those days and some of the inspiration behind the games. Much of the information seemed to be of the variety of how much shipments grew year-over-year. The end of the documentary ends on a discussion of computer science education in the UK today.

Another disappointment for me was that there was very little Atari talk. Obviously, I am biased but I was hoping for more discussion of the Atari ST which was very big in Britain and really led the charge in the 16-bit era before being overtaken by Commodore’s Amiga. The movie seemed to be heavily weighted toward the ZX Spectrum to me and really breezed by later machines.

There certainly is some good things to say about “Bedrooms to Billions.” From the beginning credits, it is obvious that this a well put-together production. Some really cool graphics and chip tunes really got me excited for the movie to begin. And, the few personal stories were interesting. I just couldn’t help but think that Jeff Minter would have a fascinating story or two. It was cool to see folks I really admire like Jeff Minter and Peter Molyneux. I also learned a bit about the ZX Spectrum which, as a kid growing up in the United States, I knew very little about.

In the end, I don’t think I can really recommend “Bedrooms to Billions.” I was hoping for more fun stories like those in Steven Levy’s “Hackers” or Howard Scott Warshaw’s “Once Upon Atari.” I am sure that many people will like this more straightforward run through computer history but, for me, it just didn’t hold my interest.

A Couple Quick Mac Tips

Just a couple of quick Mac tips. First, many programs support using Command-<number> to choose that tab in the program. Some programs are explicit about it and might show the shortcut, like iTerm 2, but this will work in all major browsers I have tried as well as Sublime Text.

Also, most times when you are using a key combination to cycle through something (like tabs in a browser or the Command-Tab program switcher), using Shift will reverse the direction. So if you go past your intended target, you can often go backwards instead of cycling all the way back through.

Quick Macintosh Tips

It is sometimes hard to explain to people why I enjoy working on a Macintosh. It isn’t because they are shinier or I have fallen prey to the “reality distortion field.” Rather, there are a lot of nice tweaks, that are sometimes not so obvious, that make working with the Macintosh such a nice experience.

Quit or hide an application through the app switcher

When using the Command-Tab key combination to cycle through your open applications, you can easily quit or hide the currently selected application. Simply use the standard key combinations of Command-Q to quit the selected application or Command-H to hide it. This is a quick way to get rid of the clutter that can accumulate through a long work session. Just keep one finger pressed down on the Command key and hit Q or H instead of tab to move onto the next application. Oh, and also, to switch direction, hit Shift when Command-tabbing in case you go past the application you wanted.

Getting the folder structure of a file in an application

I love this one and use it all the time. In almost any application, when you are working on a document and you would like to see it in the Finder, Command-click on the application’s title bar.

Title bar

Then, select any of the parent’s folders to jump to it in the Finder.

Most everything is draggable

Speaking of the title bar of an application, often times you can drag the icon to wherever you need it. No need to go to the Finder, get the file and go from there. Just drag the icon from the title bar to your email to attach it or a website to upload it. Oftentimes, if I have a screenshot that I have opened in Preview, I will just drag and drop the icon onto a website like Jira or Zendesk to upload it.

Scroll background items

I really like not having to set the focus to another window to scroll it. For example, if I am working on an Excel document next to an Word window where I am taking notes, I can scroll to view more columns without leaving Word. I simply hover over Excel and use the multi-touch functions to scroll the Excel document to where you need it – vertically or horizontally.

Hiding the categories of a post when it is “uncategorized”

If you’ve ever had some posts on your WordPress blog, you will have noticed that the “Uncategorized” category is displayed with a link to an archive of uncategorized posts.

Uncategorized

The easiest way to solve this, of course, is to categorize every blog post. But, if you don’t want to for some reason, you can use some PHP in your theme to hide the category of these posts. The example below is a customization I did for a theme in Bones but it should be easy to follow for other themes as well. The original line for the display of the categories in Bones is:

<?php printf( __( 'filed under', 'bonestheme' ).': %1$s', get_the_category_list(', ') ); ?>

So, it is just using the WordPress function, get_the_category_list, to list a comma-separated list of categories for the post. How do we hide this if the post is uncategorized? Well, one way to do it is to get a list of categories for the post. If the number of categories is one, and that category is “Uncategorized” then we just won’t use the get_the_category_list display. Here is the code:

$show_categories = true;
$categories = wp_get_post_categories( $post->ID );
// We don't want to show the categories if there is a single category and it is "uncategorized"
if ( count( $categories ) == 1 && in_array( 1, $categories ) ) :
 $show_categories = false;
endif;
if ( has_category( null, $post->ID ) && $show_categories ) :
 echo ' <span class="amp">&amp;</span> ' . __('filed under ', 'bonestheme') . get_the_category_list(', ');
endif;

We start off with the assumption that we’ll display the categories so we set a flag as true to begin with. Then, we retrieve the categories for a post. wp_get_post_categories will return the post’s categories as an array. Terms, or categories, for WordPress are stored in the wp_terms database table. And “Uncategorized” is actually a stored term with the term_id of 1:

Uncategorized term in database

With this knowledge, we check the number of categories of our post (retrieved with wp_get_post_categories) with a count call. If the result is one and the category array contains the “Uncategorized” category (term_id of 1) then we know we don’t have any categories we want to display. So, we’ll set our flag to false.

Finally, we make sure that the post does have categories and that our flag to display categories is set to true. WordPress’s has_category function, if given no category to check against, will just tell us if the post has any categories. If the post has categories and the flag is set to true, then we will use the category display line in our theme and display the post’s categories.

Hiding the WordPress admin bar on certain pages

There may be times when you would like to hide the WordPress admin bar on certain pages. Maybe the admin bar interferes with the design, for example. This can be especially true for things like pages opening up in a lightbox. Fortunately, it is not too difficult to hide the admin bar on certain pages with a filter in WordPress.

There is actually a filter in WordPress named, logically enough, show_admin_bar. This filter will show the admin bar if true is returned but not show the admin bar if the returned value is false. You pass the $bool value in which is WordPress’s own determination if the admin bar should be shown or not. So, in your theme’s functions.php file, you can add the following code:

function my_theme_hide_admin_bar($bool) {
if ( is_page_template( 'page-pop-up.php' ) ) :
return false;
else :
return $bool;
endif;
}
add_filter('show_admin_bar', 'my_theme_hide_admin_bar');

In the code above, we are simply checking to see if the page we’re on is using the template file, page-pop-up.php. This is a theme file that I used to display pages opening up in a lightbox. If the page is using that template, we return false to suppress the showing of the admin bar. If not, we return the usual $bool value set in WordPress and it will act as normal. Of course, the template conditional is just one example. You could also use other WordPress conditionals to turn the admin bar off for a myriad of other circumstances.