Skip to content

Instantly share code, notes, and snippets.

@jphalip
Created October 27, 2010 11:04
Show Gist options
  • Save jphalip/648841 to your computer and use it in GitHub Desktop.
Save jphalip/648841 to your computer and use it in GitHub Desktop.
AppleScripts to increment/decrement date values in TaskPaper. Contains improvements made on top of http://www.hogbaysoftware.com/wiki/IncrementDateValue and http://www.hogbaysoftware.com/wiki/DecrementDateValue - Works well with http://gist.github.com/648
on getTextFromDate(vDate)
set dText to ((year of vDate) as text) & "-"
set dayText to (month of vDate as number) as text
if length of dayText is 1 then
set dayText to "0" & dayText
end if
set dText to dText & dayText & "-"
set dayText to (day of vDate as number) as text
if length of dayText is 1 then
set dayText to "0" & dayText
end if
return dText & dayText
end getTextFromDate
on parse_date(s)
return date ((text 9 thru 10 of s) & "/" & (text 6 thru 7 of s) & "/" & (text 1 thru 4 of s))
end parse_date
on valid_date(s)
if s = missing value then return false
try
parse_date(s)
on error
return false
end try
return true
end valid_date
on run
tell application "TaskPaper"
tell selected entry
if (exists tag named "due") and ¬
not my valid_date(value of tag named "due") then
delete tag named "due"
end if
if (exists tag named "due") then
set _date to my parse_date(value of tag named "due")
set _date to _date - (1 * days)
set value of tag named "due" to my getTextFromDate(_date)
else
make tag with properties {name:"due", value:my getTextFromDate(current date)}
end if
end tell
end tell
end run
on getTextFromDate(vDate)
set dText to ((year of vDate) as text) & "-"
set dayText to (month of vDate as number) as text
if length of dayText is 1 then
set dayText to "0" & dayText
end if
set dText to dText & dayText & "-"
set dayText to (day of vDate as number) as text
if length of dayText is 1 then
set dayText to "0" & dayText
end if
return dText & dayText
end getTextFromDate
on parse_date(s)
return date ((text 9 thru 10 of s) & "/" & (text 6 thru 7 of s) & "/" & (text 1 thru 4 of s))
end parse_date
on valid_date(s)
if s = missing value then return false
try
parse_date(s)
on error
return false
end try
return true
end valid_date
on run
tell application "TaskPaper"
tell selected entry
if (exists tag named "due") and ¬
not my valid_date(value of tag named "due") then
delete tag named "due"
end if
if (exists tag named "due") then
set _date to my parse_date(value of tag named "due")
set _date to _date + (1 * days)
set value of tag named "due" to my getTextFromDate(_date)
else
make tag with properties {name:"due", value:my getTextFromDate(current date)}
end if
end tell
end tell
end run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment