Creating year and month groups in DEVONthink Pro Office using AppleScript

In DEVONthink Pro Office I often organize certain content by year and month. To do that, I created a simple AppleScript to build year and month groups in the following format:

DEVONthink year+month

To use the script, you select the parent group in which the year will reside.

--
-- Created by: Alan Duncan
-- Created on: 2018-12-14
--
-- Copyright (c) 2018 Ojisan Seiuchi
-- All Rights Reserved
--

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

set theMonths to {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}

tell application id "DNtp"
   try
      set theSelection to selection
      if theSelection is {} then error "Please select some contents."
      set theYear to display name editor "Year:"
      set theYearGroup to create record with {name:theYear, type:group} in current group
      repeat with i from 1 to 12
         set theMonth to item i of theMonths

         set theMonth to (my add_leading_zeros(i, 1)) & " - " & theMonth
         set theMonthGroup to create record with {name:theMonth, type:group} in theYearGroup
      end repeat
   on error
      display dialog "Error"
   end try
end tell

on add_leading_zeros(this_number, max_leading_zeros)
   set the threshold_number to (10 ^ max_leading_zeros) as integer
   if this_number is less than the threshold_number then
      set the leading_zeros to ""
      set the digit_count to the length of ((this_number div 1) as string)
      set the character_count to (max_leading_zeros + 1) - digit_count
      repeat character_count times
         set the leading_zeros to (the leading_zeros & "0") as string
      end repeat
      return (leading_zeros & (this_number as text)) as string
   else
      return this_number as text
   end if
end add_leading_zeros

Duncan's Law

Opposite day

Trump lawyer and all-around whackadoodle Rudy Guiliani claims he’s the most ethical person ever. Of course, his association with one of the least ethical people ever suggests otherwise. Thus, it prompts me to articulate “Duncan’s Law.” Succinctly stated, if someone claims absolute superiority in some particular characteristic, his actual performance in that characteristic is actually somewhere between average and the least performant.

Tuesday, November 6, 2018. U.S. Election Day

Trumphannity

Yes. Yes, they’ve done a fine job for “you”. But what about the rest of us? Moreover, what about the “us” in perpetuity, those who will have to deal with the erosion of civic norms?

I’m an atheist, but I’m familiar enough with the Christian canon that this photograph of “President” Trump with “journalist” Sean Hannity reminded me of a verse from the Gospel of Matthew (Chapter 16, verse 26):

Monday, October 9, 2018

Hello babies…

“Hello babies. Welcome to Earth. It’s hot in the summer and cold in the winter. It’s round and wet and crowded. On the outside, babies, you’ve got a hundred years here. There’s only one rule that I know of, babies-“God damn it, you’ve got to be kind.”

Kurt Vonnegut
  <cite>God Bless You Mr. Rosewater</cite>

Conservative statistics

I almost never agree with Bret Stephens, but this piece in the Times in one of his more Trumpian abuses of statistics. He argues that we should take false accusations of sexual misconduct seriously because "…false allegations of rape, while relatively rare, are at least five times as common as false accusations of other types of crime, according to academic literature." In the context of false accusation of rape, who cares about the rate of false allegation of arson, for example? The relevant statistic here is the difference between the true allegation of rape and the false allegation of rape. And given that rape and attempted rape is known to be under-reported^[Source U.S. Department of Justice data], an estimate of total true allegations has to be made. His statistical sleight of hand is sadly typical of conservatives.

Scripting thumbnail image file creation on macOS

One of the sites that I manage uses a jQuery-based image gallery to display images in a grid. The script decides which thumbnail to use based on how large and image is needed. A series of suffixes à la Flickr^[Well, sort of. I don’t think this is exactly what Flickr uses; and I made up the _q suffix for the less than 500px image.] is used to signify classes of image size. I wrote the following script to automate the process of scanning a source folder and creating four thumbnail sizes to an output directory.

Friday, October 5, 2018

This article by Christopher Browning published in The New York Review of Books puts the unprecedented polarization of American political life in an eery historical context. As he puts it, “Trump is no Hitler and Trumpism is not Nazism” but certain parallels are inescapable. The article surfaces an old question that I’ve harboured for almost a decade - Is the chaotic concentration of all power the intentional end-game of the Republican party or did they simply provoke the worst darkest tendencies of voters, only later finding they couldn’t control what they started? Whatever the answer to that question, the piece is worth reading if only to observe how beautiful sentences are crafted. The essay is that well-written.

Thursday, October 4, 2018

This piece in The Atlantic by Adam Serwer is a reminder that for Trump’s supporters, cruelty isn’t just a side-effect of Trumpism. It’s a feature. That the current U.S. president chose to mock the victim of a sexual assault by a Supreme Court nominee is hardly surprising. But what little hope I had for Trump supporters, particularly those at the Mississippi rally who joined Trump in his mockery, is gone.