Scripts

Most of the scripts I discuss on this blog is available on github. Typically I make sure the scripts on github have the latest versions. That way even if a blog post is old the source code should be close to what I use. That’s not all the case if it’s a seldom used script and I’ve just not noticed that it breaks under the latest OS.

Many of these still use Appscript, a library for Python giving it extensive Applescript-like Apple Event handling. While Appscript is no longer supported by the author you can find versions on github updated to maintain compatibility with the latest versions of the operating system. Appscript plus Python is, in my opinion, the nicest way to script on OSX.

Most of these scripts were designed to be called via a macro program like Keyboard Maestro or launched via Launchbar.

Here’s a partial summary of scripts on the page. Note this is not exhaustive but does list the ones most people are interested in.

Date Utilities

Scripts dealing with time. I often assign these to text expansion macros in Keyboard Maestro. So I might have ;tomorrow expand into tomorrows date, nicely formatted. The scripts that print dates do so by simulating keystrokes.

yesterday.py Types yesterday’s date using format %m/%d/%Y
tomorrow.py Types yesterday’s date using format %m/%d/%Y
today.py Types yesterday’s date using format %m/%d/%Y
tomorrow.py Types yesterday’s date using format %m/%d/%Y
naturaldate.py Gets a time or date via a dialog box using natural language (like tomorrow at 11:30), converts it to a real date, and then creates an entry in the OSX Calendar for that time. Basically does what Fantastical does on the cheap.

Spreadsheet Utilities

Scripts dealing with spreadsheets. I personally use these as templates to once off problems like printing mailing list labels from a spreadsheet or moving contact information into a spreadsheet. Having a skeleton of code you keep handy and expand from means that many complex jobs can usually be done in 5 minutes.

add2numbers.py Takes the selected contacts in Apple’s Contact app and creates a spreadsheet with them. (Note: designed for Numbers ’09 and has not been updated to the latest version of Numbers more expansive Applescript library. But it should be easy to modify.)
num2fedex.py Given rows of addresses in Numbers creates FedEx mailing slips. (Note: FedEx occasionally changes the appearance of their website breaking this code. But it illustrates the method to fill in fields on an html page from Numbers)

MarsEdit Utilities

Scripts for automating Daniel Jalkut’s must have blogging app, MarsEdit.

marsedit_insert.py Skeleton code with functions I use a lot scripting MarsEdit. Contains functions for typing arrows and other special keys, inserting text, switching between html mode and rich text mode and the like. I often just import this in my scripts and then use the functions.
me_fixspaces.py I learned to type on an honest to goodness mechanical typewriter. I can’t seem to shake lose the habit of typing two spaces after a period. This script goes through the text in an open post in MarsEdit and replaces double spaces with single spaces. Note this uses GUI scripting to script MarsEdit’s Find dialog box and may break on updates of MarsEdit.
safari_to_marsedit.py Creates a post in MarsEdit from the current tab in Safari.
readkit_to_marsedit.py Creates a post in MarsEdit from the current story in ReadKit.
me_quote.py Takes the selection in MarsEdit and surrounds it with smart quotes.
titlefix.py Fixes the title in MarsEdit so that it uses title case.

6 thoughts on “Scripts”

  1. I am looking for an Applescript that I can use in a Mail rule to save automatically in text format emails (the content would suffice actually) from a specific sender. I would like to use the subject of the email and the date/time the email was sent in the txt file name. I saw some old contributions of yours in some blogs on this subject and I am hoping you can direct me to the right resource.
    Thanks,
    Philippe

    1. I would look at Mactech’s article on scripting Mail. It has all the information you’d need. Unfortunately I’m swamped right now so I don’t quite have time to create a prototype as a blog post right now. There’s a slim possibility I could do something this weekend, but honestly you’d be better off reading that article and trying to figure it out from there.

      1. Shazron:Yeah, I actually have the ouptut of both scripts, but I’m not going to post them. Since Apple took steps to change this, I’m going to take that as a hint that things are not firm enough to post yet.

  2. I would appreciate if you could tell me where I am going wrong in the below script? I am trying to save emails from a specific user into a folder, as a txt file.
    Thanks,
    Philippe

    using terms from application “Mail”
    on perform mail action with messages theMessages
    tell application “Finder” to set ptd to “Users:philippe:FOLDER:XXX@YYY.com:” — this is the folder I want the text files to be
    tell application “Mail”
    repeat with theMessage in theMessages
    set theText to content of theMessage
    set theFile to ptd & “Message Number ” & (theMessage’s id as string) & “Message Date ” & (theMessage’s date received as string)
    set theFileID to open for access file theFile with write permission
    write theText to theFileID
    close access theFileID
    end repeat
    end tell
    end perform mail action with messages
    end using terms from

  3. One of the aspects of MarsEdit which apelpas to me is the way it hides much of its power and versatility beneath a relatively simple interface. Shimone Samuel recognized the power of MarsEdit’s scriptability and powerful markup macros, and came up with a pretty cool solution for automating footnote generation.

  4. I used to have my own footnote automation scripts. I ended up abandoning them because I switched to a WP plugin that did them a little better.

Leave a Reply

Your email address will not be published. Required fields are marked *

Trying to figure it all out a post at a time