Color to indicate DateModified


(Katherine Derbyshire) #1

I have a note which contains a log of activities. I have made DateModified a Key Attribute for this note.

I would like, in Map view, to change the color of the note based on the recentness of the modification date. “Hey! You haven’t looked at this topic in a week. Time to get back to it.” And then I would like to change it back to the base color when the modification date is today. Sort of like the “aging” of notes in Outline view.

I’ve figured out how to use an Agent to change the color of notes with a given attribute, but not how to change it back when the attribute is reset.

Suggestions?

Katherine


(James Fallows) #2

One of the experts can give you the details, but conceptually I would think these are the options:

  • Have an agent that works on if / else principles, That is, it could change the color of the note if it had not been updated in a while [eg, $DateModified<(today - 7 days) ] – or else would change it back to some other color. Eg you could have the notes turn red if they hadn’t been modified in the past seven days, or else (if they had been modified) they would turn back to green. So as soon as you updated an item that had turned red, the agent would, on its next pass, turn it back to green and re-start the seven-day clock. I don’t see the aTbRef page that refers to the exact syntax for If/Else, but that would give you the details.

  • Have a Rule or Edict to do the same thing, again on if/else principles. The logic you’d apply for an agent, rule, or edict is fundamentally similar. The main difference is that the edict doesn’t run as often as a rule (or agent) – although that matters in processing burden only if you have quite a big file.

  • As an alternative to the if/else structure, you could have a group of agents, rules, or edicts working off a series of Ifs. That is: If the item is 0 to 7 days old, leave it in green; if the item is 8 to 15 days old, turn it orange. If it’s 16 days old or older, turn it red. The main caution there is to make sure the If conditions don’t overlap, so the program would get into a loop of changing it one way and then back the other.

Good luck!


(Mark Anderson) #3

Is this ‘reset’ to the default (i.e. never) or to some other date value?


(Paul Walters) #4

(As @JFallows mentioned) Your query could use an if/then/else test – here’s an example that doesn’t do a date test, but you can use this pattern with your own test. More info on this syntax is here.

if{$MyBoolean} {$Color="green"} else {$Color="red"}


Is it possible for you to post the action code you’ve used in your Agent?


(Katherine Derbyshire) #5

In this case, it’s reset to the current date: I update the note with new log information, the DateModified value changes.


(Katherine Derbyshire) #6

I think this is closest to what I want the note to do. Now to figure out how to code it! Thanks. – Katherine


(Katherine Derbyshire) #7

This is an agent for a different purpose, not quite what I’m trying to accomplish in this thread:

Query:
$DueDate < date(today+7days)

Action:
$Color = red

Katherine


(Galen Menzel) #8

Hi Katherine,

Here’s some action code that might do what you’re looking for:

var maxAge;
maxAge=14;
var age;
age=min(list(maxAge, days($ModifiedDate, now)));
var colorOffset;
colorOffset = (255/maxAge)*age;
$Color=rgb(colorOffset,255-colorOffset,0);

This calculates the age of the note by taking the number of days between now and the $ModifiedDate attribute. It then sets the colors of notes on the red-green spectrum, with proportionally more red and less green as the note gets older. This code takes 14 days as the oldest a note gets before its redness is maxed out, but you can adjust that by changing the maxAge variable.

Here’s a short document with an agent that colors the notes with this action code:

Color notes by date.tbx (57.8 KB)

As you can see, notes with older ModifiedDates are colored progressively more red up to two weeks old. When the ModifiedDate is set to now, the notes are colored green again.

Perhaps a bit too cute for its own good, but it might be useful.

Best,

Galen


(James Fallows) #9

I understand that the goal you have in mind is changing the color back away from red, if for instance you change the DueDate so the deadline is further away.

A simple low-tech way to do that would be adding another agent:

Query:
$DueDate > date(today+7days)

Action:
$Color = green  (or Color=; to reset it to default color)

That would leave the edge case of times when the due date is exactly seven days away. But others can tell you the fine-tuning for that. Or just live with it, knowing that the color will stay whatever it is but then switch when the deadline gets nearer (or the due date gets changed).

Update: just saw the elegant variable-color solution by @Galen. Very nice! The comparison between the refinement of that, and the bluntness of my proposal, illustrates the range of TB approaches.


(Katherine Derbyshire) #10

Thank you all for the suggestions. I’ll give these ideas a shot and report back if I need further guidance.


(Katherine Derbyshire) #11

Okay, this seems like it should be obvious, but it isn’t. Where do I put the code that @Galen so helpfully provided?

The Agent/Action field for the note in question is grayed out. Tinderbox won’t let me put anything there. I can type into the AgentAction attribute, but nothing happens. Do I need to create a separate Agent?


(Paul Walters) #12

You create an Agent. Note > Create Agent.

An Agent could look like this:

You access the dialog shown by right-clicking the agent and choosing Get Info.

In this example the Query is looking inside a container named “My Container” and the notes you want to apply the action to are children of that container.

The action code @galen suggested is pasted into the Agent Action section.

For more information on Agents, Queries and Action code see

Help > Tinderbox Help
Help > Getting Started with Tinderbox
Help > Actions and Dashboards
Help > The Tinderbox Way
Actions & Rules
Agents and Queries


(Katherine Derbyshire) #13

Useful information: notes and agents are separate things. It is not possible to add an agent to an existing note. Thanks!


(Mark Anderson) #14

For clarification: notes, agents, adornments and picture adornments are all things that can’t be turned into any of the others and must be created deliberately for that purpose.

Separator notes (available/visible only in Outline view) can be toggled to/from normal notes.


(Katherine Derbyshire) #15

I’ve now had a chance to look at this in a little more detail. Thanks to all for helpful suggestions.

I needed to make one small change, in that the built-in modification date attribute is just $Modified, not $ModifiedDate. But with that done, and a little tweaking to the Query, it works like a charm.

Katherine


(Galen Menzel) #16

Glad that you’ve got something working!

Yes, I used ModifiedDate rather than the built-in Modified in my example because you had used DateModified in your OP, and I didn’t know if you had some special meaning for “modified” that would make the build-in attribute not work for you.


(James Fallows) #17

Yes, indeed, glad to hear that things are working out! Congrats.

(And, like @galen, had followed your lead in talking about $DateModified. Hadn’t stopped to look up whether that was the official built-in attribute, $Modified, which of course automatically updates whenever you deal with the note. Glad that you found your way through that.)


(Katherine Derbyshire) #18

As it turned out, doing so was very helpful, since I was able to change the user-created ModifiedDate attribute at will to experiment. Not so easy to change the built-in Modified attribute.

Katherine


(Paul Walters) #19

Hmmm. Looks like there’a s bug. We shouldn’t be able to change $Modified – but we can, temporarily.

$Modified is defined in the Inspector as “the time a note’s text was last modified (read only)”. In other words, it’s supposed to be maintained by the system and not by us.

Turns out it is not read only – you can change the value of $Modified. Eventually, if you change $Text for that note, the system takes over and will change $Modified to the $Text-change date and time.


(Galen Menzel) #20

Yes, I see the same behavior.

You can even change the value of a note’s ID. Tinderbox will accept the edit, and agents querying for the new value of ID will find the note. But in examining the TBX file, you will find that the ID of the note has not changed.

Changing other read-only attributes seems to propagate to the saved file, however.