Things · AppleScripts

Add Creation Date to Notes

    The purpose of this script is to add the creation dates to the notes of the selected to dos in Cultured Code's Things without any user interaction.

Already present creation dates are detected and not overwritten or multiplied.

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.

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

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:    Dienstag, 24. Februar 2010, 23:30:54
--   Created by:        ljr_nbg (http://applescript.bratis-lover.net)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
--c-                                                                                                     SETTINGS
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

property myName : "ToDo · Add creation date to notes"
property myVersion : "1.0"

--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"
-- must end with "\n" (linefeed) to get its own line
-- if notes are initially empty no separator is used

--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 add the creation dates to the notes of the selected
to dos in Cultured Code's Things (http://culturedcode.com/things) without any
user interaction.

Already present creation dates are detected and not overwritten or multiplied.

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.

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

WWW: http://applescript.bratis-lover.net/applescripts/things/creation-date-to-notes/
*)

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
--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
                repeat with i from 1 to len

                        --c--- add creation date to notes
                        set thisToDoProps to (my toDoLst's item i)'s properties
                        set crtdStr to cdPrefix & my fmtDate(thisToDoProps's creation date)
                        set toDoNotes to thisToDoProps's notes

                        if toDoNotes does not contain crtdStr then
                                -- do not multiply existing creation dates

                                if toDoNotes ≠ "" and appendCreationDate then
                                        set notes of (my toDoLst's item i) to ¬
                                                thisToDoProps's notes & lf & cdSep & crtdStr

                                else if toDoNotes ≠ "" and not appendCreationDate then
                                        set notes of (my toDoLst's item i) to ¬
                                                crtdStr & lf & cdSep & thisToDoProps's notes

                                else
                                        set notes of (my toDoLst's item i) to crtdStr
                                end if

                        end if

                end repeat
        end tell

        --c-- error
on error eMsg number eNum
        my errorHandler("Hmmm... Something went wrong...", 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.
*)