Things · AppleScripts

Task Info

    The purpose of this script is to display some additional information (e.g. creation date) on the selected to do(s) in Cultured Code's Things.

Screenshot of Task Info

If multiple to dos are selected, the infos are displayed one after the other.

A button is provided to add the creation date of the to do to its notes. The format, the position (at the top or at the end of the original notes) and the separator (e.g. "--\n") of the creation date can be modified in the first section of the script. Already present creation dates are detected and not overwritten.

Note: For some reason, this only works if the to do is not active for editing.

In the first section of the script there are also extra options like loop around if multiple tasks are selected or display notes.

Save the script to '~/Library/Scripts/Applications/Things/' and run it via the AppleScript Menu or use a third-party application like FastScripts to easily assign a keyboard shortcut to the script.


show source AppleScript Editor open download
--   Creation date:    Mittwoch, 23. Februar 2010, 21:23:27
--   Created by:        ljr_nbg (http://applescript.bratis-lover.net)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
--c-                                                                                                     SETTINGS
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

property myName : "Task · Info"
property myVersion : "1.0"


--c-- extra options
property loopAround : false -- loop around or exit after last selected to do
property displayNotes : false -- display notes too?


--c-- insert creation date

--c--- insert where?
property appendCreationDate : true
-- true: creation date is inserted at end of notes
-- false: creation date is inserted at top of notes

--c--- prefix to creation date
property cdPrefix : "Created: "

--c--- separator between creation date and original notes
property cdSep : "--\n" -- should end with '\n' (linefeed) to get its own line

--c--- format of date
on fmtDate(theDate)
        local theDate
        return short date string of theDate & " " & time string of theDate
end fmtDate


-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
--c-                                                                                               DESCRIPTION
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

(*
The purpose of this script is to display some additional information (e.g. creation 
date) on the selected to do(s) in Cultured Code's Things.
http://culturedcode.com/things

If multiple to dos are selected, the infos are displayed one after the other.

A button is provided to add the creation date of the to do to its notes. The format, 
the position (at the top or at the end of the original notes) and the separator 
(e.g. "--\n") of the creation date can be modified in the first section of the script. 
Already present creation dates are detected and not overwritten.

NOTE: For some reason, this only works if the to do is not active for editing.

In the first section of the script there are also extra options like loop around if 
multiple tasks are selected or display notes.

WWW: http://applescript.bratis-lover.net/applescripts/things/task-info/
*)

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
--c-                                                                                                            MAIN
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

property lf : linefeed -- line endings to use
property toDoLst : {}
try
        tell application "Things"
                
                --c-- get to dos
                set my toDoLst to selected to dos
                set len to count my toDoLst
                if len = 0 then display dialog "No ToDo selected" with icon 2 buttons ¬
                        {"OK"} default button 1 cancel button 1 with title myName
                
                --c-- loop trough to dos
                set idx to 0
                repeat
                        set idx to idx + 1
                        
                        --c--- restart if already looped thru
                        if idx > len then
                                if not loopAround then exit repeat
                                set idx to 1
                        end if
                        
                        --c--- build display string
                        set thisToDoProps to (my toDoLst's item idx)'s properties
                        set str to ""
                        
                        --c--- delegate & name
                        if thisToDoProps's delegate is not missing value then
                                set str to str & character id 9821 & " " & ¬
                                        (thisToDoProps's delegate)'s name & ": "
                        end if
                        set str to str & "" & thisToDoProps's name & lf & lf
                        
                        --c--- status 
                        set str to str & "Status:\t\t" & thisToDoProps's status & lf & lf
                        
                        --c--- due date
                        if thisToDoProps's due date is not missing value then
                                set str to str & "Due:\t\t" & ¬
                                        (my fmtDate(thisToDoProps's due date)) & lf
                        end if
                        
                        --c--- creation date
                        set str to str & "Created:\t\t" & ¬
                                (my fmtDate(thisToDoProps's creation date)) & lf
                        
                        --c--- completion date
                        if thisToDoProps's completion datemissing value then
                                set str to str & "Completed:\t" & ¬
                                        (my fmtDate(thisToDoProps's completion date)) & lf
                        end if
                        
                        --c--- canceled date
                        if thisToDoProps's completion datemissing value then
                                set str to str & "Canceled:\t" & ¬
                                        (my fmtDate(thisToDoProps's cancellation date)) & lf
                        end if
                        
                        --c--- notes
                        set toDoNotes to thisToDoProps's notes
                        if not displayNotes then set toDoNotes to ""
                        
                        --c--- display to do info
                        set butLst to {"Exit", "Creation date to notes", "Next"}
                        if toDoNotes ≠ "" then set str to str & "\nNotes:"
                        
                        set but_ to button returned of (display dialog str & "\n" & ¬
                                toDoNotes with icon 1 buttons butLst cancel button 1 ¬
                                default button 3 with title (myName & " · " & idx & " of " & len & ""))
                        
                        --c--- add creation date to notes
                        if but_ is butLst's item 2 then
                                set crtdStr to cdPrefix & my fmtDate(thisToDoProps's creation date)
                                
                                set toDoNotes to thisToDoProps's notes
                                if toDoNotes does not contain crtdStr then
                                        if toDoNotes ≠ "" and appendCreationDate then
                                                set notes of (my toDoLst's item idx) to ¬
                                                        thisToDoProps's notes & lf & cdSep & crtdStr
                                        else if toDoNotes ≠ "" and not appendCreationDate then
                                                set notes of (my toDoLst's item idx) to ¬
                                                        crtdStr & lf & cdSep & thisToDoProps's notes
                                        else
                                                set notes of (my toDoLst's item idx) to crtdStr
                                        end if
                                end if
                        end if
                        
                end repeat
        end tell
        
        --c-- error
on error eMsg number eNum
        my errorHandler("Hmmm... What's this?", eMsg, eNum)
end try

on errorHandler(customMsg, eMsg, eNum)
        if eNum ≠ -128 then
                display dialog customMsg & "\r\rError: " & eNum default answer eMsg ¬
                        buttons {"Cancel"} default button 1 cancel button 1 with icon 0 ¬
                        with title myName giving up after 15
                error number -128
        end if
end errorHandler


-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
--c-                                                                                              TERMS OF USE
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

(*
This script was written by ljr_nbg (http://applescript.bratis-lover.net).

It is released under the following terms:

Permission is hereby granted, free of charge, to any person obtaining a copy of this
software and associated documentation files (the "Software"), to deal in the Software
without restriction, including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies
or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*)