Importing Plain Text into Mountain Lion Reminders App

I have created a new project to enrich the tags in my WordPress blog using the WP Calais Auto Tagger that I mentioned in this previous blog post. To do this I am working on pages of old posts in my WordPress dashboard and so I wanted to track just which pages I had completed and which ones still need my attention. I’ve got 48 pages of blog posts and so this is going to take some time to complete.

The first step was to create a list of text lines going from Page 48 to Page 1 like a countdown. I did that in OpenOffice using the Spreadsheet app. All you need to do here is type in two lines where the number series example can be made and then you can select these two cells and then grab the autonumbering control on the spreadsheet and draw it down, this is a great way to quickly create very repetitive lines where the only thing that changes is a number at the end. With this list, I copied it into a plain text file with each line on it’s own and saved it as “tagging.txt” on my desktop.

The next step is to use AppleScript to tell the Mountain Lion Reminders app to create entires automatically based on the file you just made in OpenOffice. Technically the Reminders app has an import mechanism but that’s only meant for ICS files, and that’s more trouble than it’s worth as far as I care to pursue it as a solution. Here’s the AppleScript:

 

set theFileContents to read file "Users:andy:Desktop:tagging.txt"
set theLines to paragraphs of theFileContents

repeat with eachLine in theLines
tell application "Reminders"
tell list "Tagging Project"
make new reminder with properties {name:eachLine}
end tell
end tell
end repeat

The only part you’d have to fix is the file location part and the list name part. Otherwise it works well. The only gotcha is it doesn’t seem to import the tasks in order, but at least they are in there.

Here are some helpful sites where I got a lot of this code and hints on how to talk to Reminders instead of iCal:

Benguild.com Page

MacScripter Page

I say hello, I say goodbye…

For a few months I’ve used an app called Platypus on my Mac to create a pseudo-app that bundles a bash shell script which instructs my Mac to open various applications that I want to use during the day. What I want is very specific, I want to be able to login quickly to a idle Mac, but I want to have one icon to click on to start an entire host of applications, if I want to. The overall solution would of course be to mark every app as “Open on Login” but I don’t want them all to open each and every time I log-in, I’m picky. The bash script uses the open command to open applications. This command works well enough, but it leaves my screens littered with open application windows. This is not exactly what I want. I want all my applications to be opened, then I want them to be hidden. Cake and eat it too.

This morning, on a lark, I investigated alternatives to using Platypus. I know there is AppleScript, but I never really delved very deeply into the language. A little browsing and some tinkering and I have exactly what I want:

tell application “Mail” to activate
tell application “Firefox” to activate
tell application “iTunes” to activate
tell application “/Applications/Yahoo! Messenger.app” to activate
tell application “Stickies” to activate
tell application “Remote Desktop” to activate
tell application “Server Admin” to activate
tell application “Evernote” to activate
tell application “iCal” to activate
tell application “iChat” to activate
delay 0.5
tell application “Finder” to set visible of process “Mail” to false
tell application “Finder” to set visible of process “iTunes” to false
tell application “Finder” to set visible of process “Yahoo! Messenger” to false
tell application “Finder” to set visible of process “Stickies” to false
tell application “Finder” to set visible of process “Remote Desktop” to false
tell application “Finder” to set visible of process “Server Admin” to false
tell application “Finder” to set visible of process “Evernote” to false
tell application “Finder” to set visible of process “iCal” to false
tell application “iChat”
set minimized of window “bluedepth@gmail.com” to true
set minimized of window “andymchugh@atlas.dev.wmich.edu” to true
set minimized of window “AIM Buddy List” to true
set minimized of window “andy.mchugh@chat.facebook.com” to true
end tell

This script, shoved into an Application icon opens up every app I want in the morning, then hides them, except for iChat, it minimizes every window but my Bonjour list. I discovered that if I accidentally have a volume open when I run the script and there is an application in the volume and I ask that it be activated, the Mac is confused and asks me to pick the application from the list – so for Yahoo I had to explicitly state which one I wanted. Not a bug, just me being lazy.

The flipside of this also occurred to me. In the evenings I want to close all my applications. I could of course rely on the log-out procedure to do all the mopping up but there are some apps I use, like GroupWise and VirtualBox that can upset the log-out sequence. This script unmounts all volumes and then quits all open applications. That way I close all my apps before I log-out. Again, with the lazy:

tell application “Finder”
set bootDisk to name of startup disk
set otherDisks to every disk whose (name is not bootDisk)
repeat with myDisk in otherDisks
try
eject myDisk
end try
end repeat
end tell

tell application “System Events” to set the visible of every process to true
set white_list to {“Finder”}
try
tell application “Finder”
set process_list to the name of every process whose visible is true
end tell
repeat with i from 1 to (number of items in process_list)
set this_process to item i of the process_list
if this_process is not in white_list then
tell application this_process
quit
end tell
end if
end repeat
on error
tell the current application to display dialog “An error has occurred!” & return & “This script will now quit” buttons {“Quit”} default button 1 with icon 0
end try

Yay for Lazy! 🙂