Category Archives: General

macOS Notification Center Scripts

After listening to a recent Mac Power Users episode on notifications, I decided it was finally time to reduce the flood of notifications I get on my Mac. I realized that the biggest obstacle for me with notifications on the Mac is the inconsistent behavior when I two-finger-edge-swipe to open the notification center: sometimes I get the Today view, and sometimes I get the Notifications view, depending on what I was last looking at it.

There doesn’t seem to be a keyboard shortcut you can use to toggle between the Today and Notifications tabs, so I decided to script it. As a starting point, I found this Stack Overflow answer, but the Applescript didn’t work on Sierra. This answer provided the information I needed to debug the first script; it turns out that the "Notification Center" item moved from menu bar 2 to menu bar 1 with an OS update.

This is the script I ended up with to show the Today tab:

tell application "System Events" to tell process "SystemUIServer"
    click menu bar item "Notification Center" of menu bar 1
end tell

tell application "System Events" to tell process "NotificationCenter"
    click radio button "Today" of radio group 1 of window "NotificationTableWindow"
end tell

And this is the script for the Notifications tab:

tell application "System Events" to tell process "SystemUIServer"
    click menu bar item "Notification Center" of menu bar 1
end tell

tell application "System Events" to tell process "NotificationCenter"
    click radio button "Notifications" of radio group 1 of window "NotificationTableWindow"
end tell

I’ve tied these gestures in Better Touch Tool, and I can also fire them off from LaunchBar.

Child Theme Modifications for Micro.blog

Manton launched Micro.blog this past week, and as a Kickstarter backer I received my invitation (you can fine me at jeff)!

In order to validate an externally-hosted micro blog, like the one I host on this site, Micro.blog requires a rel="me" header link:

<head>
  <link href="https://micro.blog/jeff" rel="me" />
  ...
</head>

I’ve modified my WordPress Child Theme to include this link; here’s the commit.

Fixing the Mastered for iTunes Droplet

Sleep Studies, the band I play with, is in the process of finishing up our next EP. One of the (many) things I’m neurotic about is making sure the masters will translate as well as possible. I’ve written about how I use afclip to examine the master audio files for headroom; another thing I do is run the masters through the Apple’s Master for iTunes Droplet. This is distributed as part of the Mastered for iTunes program.

The Master for iTunes Droplet accepts your lossless files and returns .m4a files that mirror the files the iTunes backend will generate, so you can preview what your content in the store will sound like.

Well, it used to do this until Mac OS X 10.10 Yosemite was released.

The droplet is just a wrapper around an AppleScript file, and it’s easy to examine the script by dragging the entire droplet to the Script Editor application. The problem, it turns out, is just a trivial bug. On lines 62 and 109 you’ll find this chunk of code:

set systemVersion to system version of (get system info)
if systemVersion is less than "10.6" then
    log ("ITUNESMASTERINGDROPLET: incompatible system version")
    display alert SYSTEM_CHECK_ERROR_TITLE message SYSTEM_CHECK_ERROR_MESSAGE as warning buttons {CANCEL_BUTTON_TITLE} default button 1
    log ("ITUNESMASTERINGDROPLET: shutting down")
    error number -128
end if

It’s the if systemVersion is less than "10.6" then part that is troublesome — this is just a string comparison, not a numeric comparison. Starting with Yosemite (10.10), this conditional started doing the wrong thing. “10.10” is in fact less than “10.6” when comparing as strings. The fix is pretty easy, too. The incomparable Michael Tsai laid out a solution on Stack Overflow, which I’ve implemented here:

set systemVersion to system version of (get system info)
considering numeric strings
    set systemVersionNewEnough to systemVersion ≥ 10.6
end considering
if systemVersionNewEnough is false then
    log ("ITUNESMASTERINGDROPLET: incompatible system version")
    display alert SYSTEM_CHECK_ERROR_TITLE message SYSTEM_CHECK_ERROR_MESSAGE as warning buttons {CANCEL_BUTTON_TITLE} default button 1
    log ("ITUNESMASTERINGDROPLET: shutting down")
    error number -128
end if

While I was at it, I wanted to fix the other issue with the Apple-distributed version of the droplet: it isn’t code signed. Because of this, when you download the droplet, Gatekeeper informs you that the application can’t be run.

Sal Soghoian’s MacOSXAutomation site has instructions for signing AppleScript Droplets. They’re easy to follow — the only snag I ran into was that I tried to use my iPhone developer certificate to sign the droplet, and that doesn’t help with Gatekeeper. I had to request a new “Developer ID Application”1 certificate to get things working.

With that, the version of the droplet linked below includes fixes for:

  • Droplet returning an error on Mac OS X 10.10 and later
  • Gatekeeper returning an issue with an unknown developer

I’ve filed a bug report with Apple reflecting these issues — it would be ideal if they fixed the versions they’re distributing. It’s rdar://30067799 if you’re interested in reading it.

Download the fixed Master for iTunes Droplet

On May 22, 2017, Apple released an update for the Master for iTunes Droplet that resolves these bugs. You can read more here, or download the new version here. Now that there’s an official version from Apple, I’ve removed the download link to my unofficial release.


  1. I did this via Xcode 8.2.1 — from the Preferences -> Accounts -> View Details screen, I used the Create button to get the certificate. 

A Custom Recent Posts Widget

One consequence of adding a Microblog feed to this site was that a lot of post IDs were showing up in the Recent Posts widget. It turns out that if a post is missing a title, the widget falls back to just displaying the ID number. Sad!

It turns out that customizing the widget was fairly straightforward. Since I already have a child theme set up, all I had to do was copy the widget class into the child theme, make my tweaks, and add a few lines to my functions.php file.

The functions.php changes were incredibly straightforward. I added the following lines:

// Include Recent Posts Excluding Category widget
include("class-wp-widget-recent-posts-exclude-cat.php");
add_action( 'widgets_init', function(){
    register_widget( 'WP_Widget_Recent_Posts_Exclude_Cat' );
});

… where class-wp-widget-recent-posts-exclude-cat.php is the class of my new widget.

You can see the custom version of the widget on Github. The essence of the changes I made was to add one more filter to the code that retrieves the list of posts:

$r = new WP_Query( apply_filters( 'widget_posts_args', array(
            'posts_per_page'      => $number,
            'no_found_rows'       => true,
            'post_status'         => 'publish',
            'ignore_sticky_posts' => true,
            'cat'                 => $exclude_cat
        ) ) );

The last condition, 'cat' => $exclude_cat, is the one I added. If you pass a negative value to the cat filter, that becomes a category exclusion. In my case, I want to exclude the Micro category, which has an ID of 104, so $exclude_cat = -104.

WordPress Child Theme

Just under a year ago, I wrote about the changes I made to the WordPress TwentyTwelve theme to remove the comment RSS feeds from the site headers. As I was adding the new Microblog RSS feed to the header, I decided to see if I could migrate my modifications into a child theme.

The big advantage of creating a child theme, instead of modifying the parent (original) theme, is that when there is an update available to the parent theme your modifications won’t be lost.

My original modifications required changes to two files:

  1. functions.php:

    • Comment out the line that adds in all feeds:

      // add_theme_support( 'automatic-feed-links' );
      
    • Add in a filter to remove the post comment feeds:

      function disablePostCommentsFeedLink($for_comments) {
          return;
      }
      add_filter('post_comments_feed_link','disablePostCommentsFeedLink');
      
  2. header.php:

    • Added in links to the main RSS feed (since they were removed from functions.php).

To migrate the changes to a child theme, I reverted my version of the TwentyTwelve theme to its original state. You can find my child theme on Github, and you can see the torturous path I took to develop it in the commit history.

My first attempt involved duplicating the entire header.php file, with my changes, into the child theme, and I gave up on figuring out how to comment out add_theme_support( 'automatic-feed-links' ); from the child.

For the second attempt, I tried to achieve the commenting out of add_theme_support( 'automatic-feed-links' ); by removing the function calling it from the after_theme_setup hook. I struggled with figuring out what hook to attach the removal to, and consulted the Actions Run During a Typical Request list in the Codex. Ultimately I attached the removal function to the same after_theme_setup hook, but with a priority of 0:

add_action( 'after_setup_theme', 'child_remove_parent_function_twentytwelve_setup', 0 );

Once I had that working, I stumbled onto the feed_links_show_comments_feed filter, which greatly simplified the whole endeavor. The filter removes both the master comment feed and post comment feeds, which was my entire original objective. I was able to strike both the header.php file and the effort to comment out add_theme_support( 'automatic-feed-links' ); in functions.php.

I was able to accomplish the removal of the comment RSS feeds in my child theme with just this in my functions.php file1:

// disable comment feeds (this seems to disable main and post comment feeds)
add_filter( 'feed_links_show_comments_feed', '__return_false' );

The only thing left to do was add back in the Microblog RSS feed, which I injected into the wp_head hook2 (this, too, is in functions.php):

// Add in microblog feed to header
function microblog_feed() {
    echo '
<link rel="alternate" type="application/rss+xml" title="Jeff Vautin &raquo; Microblog Feed" href="/micro.xml" />
';
}
add_action('wp_head', 'microblog_feed');

I ended up with the same functionality I had before, but in just a handle of lines of code, nicely contained in a child theme. Feel free to fork it for your own use!


  1. Beyond the boilerplate needed to create a child theme

  2. I took inspiration from this Stack Overflow answer