TannieSpace

geekery, drawing and then some

2009 (old posts, page 2)

Create a new task in a project

For completion sake, I decided to post the bit to create a new task in a new or existing project in OmniFocus through AppleScript. I have this in my script that creates tasks from my mail.

If you know a bit of AppleScript, this should help out. If I have the energy, I might post the entire script later and explain the parts.

In this case, it took longest to figure out the following part:

tell MyProject set theTask to make new task with properties¬
{name:MyTaskTopic, context:MyContext, note:ThisNote} end tell

Apparently, when creating a new task you have to tell the project. If you want to set the context, you instead tell the task to set its context property to something.

This does make sense, in the way that you always tell the containing item to do something.

The part I use in my script:

if MyContext is equal to "NONE" and MyProject is equal to "NONE" then
set theTask to make new inbox task ¬
with properties {name:MyTaskTopic, note:ThisNote} set ProjectString to "INBOX"

else
if MyContext is equal to "NONE" and ¬
MyProject is not equal to "NONE" then
tell MyProject
set theTask to make new task ¬
with properties {name:MyTaskTopic, note:ThisNote}
end tell

else
if MyProject is equal to "NONE" and ¬
MyContext is not equal to "NONE" then set theTask to make new inbox task ¬
with properties {name:MyTaskTopic, context:MyContext, note:ThisNote}
set ProjectString to "INBOX"

else
tell MyProject set theTask to make new task ¬
with properties {name:MyTaskTopic, context:MyContext, note:ThisNote}
end tell
end if

try set Datum to setDueDate
set due date of theTask to setDueDate
on error
set due date of theTask to ((current date) + 604800)
end try

tell theTask
set note to return & return
tell note
set theURL to "message://< " & message_id & ">"
set linkText to theURL insert linkText at before first character
set value of attribute "link" of style of paragraph 1 to theURL insert message_content at before last character
end tell
end tell

which works like a charm.


Applescripts for OmniFocus: change the context or project of selected tasks.

I use OmniFocus a lot, and have recently tweaked some more AppleScripts to make my workflow even more smooth. I can add any mail to OmniFocus for replies, add confirmation of orders from mail to OmniFocus which will automatically go into my project-shoebox for orders, with a ‘waiting for’ context and a due date set to 1 week into the future, unless I’ve changed or added MailTags with a project, a keyword and a due date. In that case it’ll take the project, the first keyword and the due date and use them to set up the OmniFocus task. I have a few more scripts:

  • in OmniWeb I can take and add a URL for later reading, it’ll go into my inbox by default
  • in OmniWeb I can take and add a URL to my ‘wish-list’ project (with a start date for at 2 weeks in the future)
  • in OmniFocus I have scripts to easily change the context or the project of selected tasks
  • in Mail I can press a key and have the selected e-mail(s) sent to OmniFocus with a ‘Respond to: ‘ before the subject line, sorting into either a default project or the one specified in MailTags, with the context set to ‘mail’ and the message URL in the note-field
  • in OmniFocus I can select such a task, press a key to run a script that will open the message and immediately create a reply (I have a separate one for just opening, in case I have to read it thoroughly first)

All these scripts make the integration between all these programs very easy. That and FastScripts. I found useful scripts over at Curtis Clifton’s site. His scripts use Growl notification so if you have Growl installed you get a small notification.

I had some trouble putting my own scripts together, so I decided to paste the info here, just in case I need it later on, or someone else runs into similar issues. I found it quite hard to figure out how to add a task to an existing project or to move it from inbox / other project. In the end, it only took a few lines.

First, when I started my script, I wanted a default project or context (I’ll use ‘project’ from now on, but it also applies to the context-script). To do this I created a ‘property’ at the beginning of the script:

property defaultProject : "Miscellaneous" property alertItemNum : ""

I used the alterItemNum for my alerts through this very simple routine:

on notify(alertName, alertTitle, alertText) display dialog alertText as string with icon 1 end notify

That went at the end of my script.

I started by addressing OmniFocus and ‘talking’ to the open document:

tell application "OmniFocus" tell front document tell (first document window whose index is 1)

Then, I checked to see if that document had anything selected, and if not, give an error-dialogue:

            set theSelectedItems to selected trees of content
            set numItems to (count items of theSelectedItems)
            if numItems is 0 then
                set alertName to "Error"
                set alertTitle to "Script failure"
                set alertText to "No valid task(s) selected"
                my notify(alertName, alertTitle, alertText)
                return
            end if

If I have no items selected, the script will call the alert routine from above ( my notify(alertName, alertTitle, alertText) ). Because I created a separate routine, I can use this anywhere in the script.

Next, display a dialogue asking for the project: ` display dialog “Change to what Project? ” default answer defaultProject buttons {“Cancel”, “OK”} default button 2

set theProject to (the text returned of the result) ` The variable ‘theProject’ will now contain the name of the (new) project to move the tasks too.

Next, the loop to go through all the items and move them:

            set selectNum to numItems
            set successTot to 0
            repeat while selectNum > 0
                set selectedItem to value of item selectNum of theSelectedItems
                set succeeded to my ChangeProject(selectedItem, theProject)
                if succeeded then set successTot to successTot + 1
                set selectNum to selectNum - 1
            end repeat

This loop will end as soon as the variable ‘selectNum’ (= numItems which I set to the count of the items in the variable SelectedItems) reaches 0. It calls the routine ‘ChangeProject’ which I’ll get to in a bit, but I first want to wrap up this part. Let me also explain the ‘if succeeded then set successTot to successTot + 1’ line. The line before sets ‘succeeded’ to the result of the ChangeProject routine. This result can mean anything, numbers, letters, whatever. In this case we use it to return a ‘true’ or ‘false’. That way, we only need to use ‘if succeeded’ (which will either be ‘true’ or ‘false’) as a condition. We don’t need to check the actual content of the variable. This can come in handy for various checks, and it took me a while to catch on to that, so I figured I’d mention it here.

To end this main routine, I used:

            set alertName to "General" set alertTitle to "Script complete"
            if successTot > 1 then set alertItemNum to "s"
            set alertText to successTot & " item" & alertItemNum & " changed to Project " & theProject
        end tell
    end tell
    my notify(alertName, alertTitle, alertText)
end tell

Basically, this tells the dialogue box to say the script ran successfully and displays the number of items successfully moved and only to use the ‘s’ after ‘item’ if the count of successful moves is higher than 1.

That wraps up the main part.

The routine to actually move the task to the other project only took 21 lines:

on ChangeProject(selectedItem, theProject)
    set success to false
    tell application "OmniFocus" to tell default document
        if (theProject is not "") then
            set MyProjectArray to null
            set MyProjectArray to complete theProject as project maximum matches 1
            try
                set MyProjectID to id of first item of MyProjectArray
                set theNewProject to project id MyProjectID
            on error
                set theNewProject to (make project with properties {name:theProject})
            end try

            try
                set newtask to selectedItem
                move newtask to end of tasks of theNewProject
                set success to true
            end try
        end if
    end tell
    return success
end ChangeProject

The first line sets the success to ‘false’, because we want to actively, after having our success, set it to ‘true’. We then chat with OmniFocus again, and this time, we’ll just talk to the default document (the one you have open). If the variable ‘theProject’ is not empty, we’ll continue. If it is, the ‘if-end if’ ends, without having set the ‘success’ variable to true (and thus, the script failed). You could technically build in an extra loop to change it to a default project, however, I prefer it this way. If I accidentally emptied that dialogue-box, nothing will happen, just as I like it.

If theProject does contain something (anything), the script continues with its routine. It sets the MyProjectArray to null (makes it empty, just in case). It then used OmniFocus complete option to find the first matching project of OmniFocuses project-list. If you’ve ever only typed the first three letters in one of OmniFocus’s project-areas (to set the project) and it magically came up with the right project, this is the same thing. It means you only have to type the first three or four letters of your project, and the script will find it. If it can’t find the project, it will create it for you (at the end of your project-list).

After that, it will simply try to add the task to the desired project.


Mouse near my house.

A mouse on my balcony.

It storms a bit today. Lots of rain and wind. I’ve decided to stay inside, apart from the quick trips with Nano. When I looked out of my window onto my balcony, I saw this little one. It scurried about, probably looking for either food or shelter. Managed to snap a quick shot of it before it ran of because I scared it with a camera in its face.

It did come back a few minutes later though, trying to access the house. Hmm…


My life, the planning fest.

Cleaning supplies.

On August 15 of this year, I had my birthday. I spent it mostly ill (in bed), as I did most of the other days at HAR2009. Not what I had in mind. I’ve spent most of the days since also mostly ill, either in bed or on the sofa.

It started with tendinitis in my neck, on the right side. Then it went to the left side. Then I had it in both sides. Then my shoulders, my elbows, my thumbs. My knees and feet and recently, my right hip. Mostly not all at the same time, it switches. Just as I think it has gone, it starts somewhere else. I’ve had tendinitis before, and know that the best way to get rid of it means a lot of rest and also a good dose of anti-inflammatories. I’ve taken a lot of rest. But not so many anti-inflammatories. See, they have this nasty habit of irritating your stomach and intestines, and as I don’t have the stomach anymore, my intestines get the full blow. This makes it harder to eat. So for the past 2.5 weeks I’ve juggled with the tendinitis and the rest and the pills and the eating. It slowly seems to improve, very slowly.

One of the contributing factors of my recurring tendinitis, my RA, will hopefully improve somewhat soon. I have started methotrexate injections (no more pills because they, you guessed it, cause gastro-intestinal problems) which should prove more effective and help with my pains. Other factors however, don’t have such an easy solution.

Stress plays a major role and unfortunately, I’ve had a lot of it. I’ve had appointments with my podiatrist for insoles, my RA-nurse for learning how to inject methotrexate and had to go to the pharmacy to get all the stuff. Also had to go buy groceries (a girl’s gotta eat), make at least part of my flat ‘injection-ready’ (the methotrexate requires a bit more care than the B12 injections) and eat. And eating hasn’t really gone well lately, so I had to spend extra time and extra care with the eating. Buying groceries doesn’t help with the tendinitis if I do it in bulk, so I had to do it in bits, which adds more to the stress.

Currently, I have a full-time job taking care of myself and doing all the necessary health related things, and not much, if any, energy left for other things, like say, socializing or ‘fun stuff’. I have tried hard to keep up with what others expected from me, and have found that despite their attempts to understand and to deal with what I go through, they really can’t if I keep on trying to keep up with them. I spend a lot of energy doing (or trying to do) what I think I should do, what I think others expect from me (or what they have expressed) and what I think I can do. But what I think I can do doesn’t equal what I can (and stay sane and relatively healthy). What I think I can do already lies above what I really can do. I spend lots of time reacting to things that happen, trying to make the best of them, trying to keep up, trying to appear normal.

No more, I say! I will not spend my precious little amount of energy feeling lived and not actually living. No more reacting, time to act on my own. No more trying to keep up, if I can’t, I can’t, suck it up! Don’t try and ‘encourage’ me, please. No more pushing myself to eat things I know that don’t work (hello, bread), because they make me feel like crap later on. No more not having control over my life, my self, my sanity. I will not do it anymore.

I’ve grabbed my copy of Getting Things Done by David Allen and I will re-read it to see if I can tweak my system to help me out more with my health-related stuff and possibly the eating. Eating takes up about 90% of my energy (no, not kidding, totally serious unfortunately) and I need to get a better grip on it. I need to think the other things through, before I go out and do them. Yes, this means more planning and less spontaneity, a small price to pay for actually getting more healthy and getting a bit more sane. It may seem (too?) neurotic to most, for me it comes down to a way to survive and actually start living my life again. I’d very much enjoy that.

I wish I could also say ‘No more pain!’, however, I don’t have that much control over my RA. I will do what I can to ease that pain, and wait patiently for that cure, but not holding my breath in the meantime ;)


Birthday gadget :D

Testing birthdaygift (food vacuum sealer) @ #HAR2009

For my birthday I got a Seal-a-meal food-vacuum-sealer. Had to try it out ofcourse, and we only had some green beans to abuse for the goal.

Vacuumed and sealed!

It worked great, turning the beans in a solid package. Now I want to seal up more, but I doubt the neighbours will appreciate the noise in the night. Will try it out tomorrow, probably cook some rice and freeze that in handy packages.