applescript

Timestamps in AppleScript

AppleScript is easy for most basic file manipulations on the Mac. For example, I can get a files modification timestamp with the following bit of AppleScript: set modificationDate to modification date of this_item where "this_item" is a reference to a file. "modificationDate" now contains a value like "Wednesday, December 21, 2011 7:24:22 PM" But that's a pretty awkward timestamp if I want to use it to name a file. In AppleScript, reformatting a timestamp is awkward and tedious.

Great AppleScript Collection Link

There's some very high quality AppleScript functions and tools on Brati's Lover. Just look at this nicely compiled list of file handlers. The site is worth a visit just for the cute Mac-like design.

Finder Push and Pop

This might make the bash people out there smile a little bit. If you love the push and pop functions on unix, this pair of macros bring both to the OS X Finder. The core of each macro is an AppleScript, so these could easily be ported to LaunchBar or Alfred. Macro 1 - Push The Push macro grabs the currently viewed folder path and saves it to a Keyboard Maestro macro.

Keyboard Maestro Variables Remember Current Application

I was recently wasting some time playing with an idea. I wanted an easy and quick way to grab some text in any arbitrary application and pop over to MultiMarkdown Composer to do some editing. I also wanted a way to pop the text back into the original app when I was done. You might be yelling at the screen right now telling me to just use the cmd-tab to switch back and paste the text.

Omnifocus to Text Link

A nice little script by Wolf Rentzsch for extracting actions from Omnifocus to plain text. Applescript may be showing its age, but it sure is readable. That script almost looks like instructions you would provide to a person to perform the same action.

Resize Images in AppleScript

I really like Dr. Drang’s method of using sips for manipulating images. I set out to modify my FTP macro to include an image resize step. After a short bit of playing around I discovered that it’s very easy to manipulate images right in AppleScript. In fact, Apple provides services to add the necessary code to a script just by selecting the variable that points to an image. Here’s the script:

Scratch File - Add to Top

I modified my scratch file script. The new version appends the clipboard to the top of the file rather than the bottom. That way the scratch file is in chronological order. WARNING: This script overwrites the contents of a file. [cc lang="AppleScript"]do shell script "pbpaste '/tmp/qqq_Scratch.txt' echo '/tmp/qqq_Scratch.txt' cat '/Volumes/Macintosh HD 2/Dropbox/Notes/qqq_Scratch.txt' '/tmp/qqq_Scratch.txt' cat '/tmp/qqq_Scratch.txt' '/Volumes/Macintosh HD 2/Dropbox/Notes/qqq_Scratch.txt'"[/cc] Just as a Unix reminder, the double angle bracket "

Scratch File

I keep a scratch file in my NVAlt library. I use it to keep random bits of information that I want to out live the clipboard. It's not meant to be permanent just a stop-over to some other destination. My clipboard is pretty volatile since I have a number of macros and scripts that temporarily hold bits of information on the clipboard. If it's something I might need later, then I better get it into something a bit more permanent.

Upload File Selection Via Transmit

In the never-ending pursuit of hard-won laziness, I often develop scripts to do simple tasks. Sometimes the joy is in the problem solving and sometimes it's in the final product. In this case it was in both. Yesterday I was working on an as yet to be published post that has a large number of images. My typical workflow is to make an annotation in the text of the image I want to insert.

Keyboard Maestro Macro Alphabetize a List

Here's another quick macro that comes in handy. I often will create a list of items and later I will want the list to be in alphabetical or numerical order. I do it enough that I created a Keyboard Maestro macro for the function. Given a list like this: Item 3 Item 1 Something borrowed Something blue Something Blue Alphabetical would be better I can select the items, trigger the macro, and get back this list: