I am in the process of sculpting a workflow where I can easily create prototypes relevant for a project and use them to rapidly enter data. I am using this to organize my ideas for writing, and the kinds of objects are “puzzle”, “thinker”, “hypothesis”, etc. For each kind of object, I have one prototype and one agent that watches notes as I type. The “hypothesis” agent, for instance, looks for notes with names that begin with “hy;”, strips this prefix, and adds the appropriate prototype.
Now, I want to create these prototype-agent pairs easily, and I was trying AppleScript (I am new to this, but not to technology). Creating notes works like a charm: I create the note, make it a prototype, and move it to a special folder.
But for agents, I ran into issues galore. It seems that “make new agent” may not be returning the new agent correctly. The code below works fine if you replace “new agent” with “new note”. As it stands though, the code seems to affect the first note in the document rather than the newly created agent.
The code:
set query to "$Name.contains(" & quote & "2" & quote & ")"
tell application "Tinderbox 8"
tell front document
set myAgent to make new agent
tell myAgent
set name to "MyNewAgentName4"
set value of attribute "AgentQuery" to query
set value of attribute "AgentAction" to "$Color=" & quote & "red" & quote
end tell
end tell
end tell
If I run this ten times, I end up with 10 objects. In outline view, the first of this is correctly named and the rest are named “agent”. I tried working around this by looking for notes called agent and using them as myAgent; that sometimes work.
Any suggestions?
One thought: since agents are notes under the hood, can I start with a note (I know that part of the code works and looks robust) and “upgrade” it to an agent? Agenthood seems not to be just another attribute, so this may not work, I suppose.
In my week of using this program, I have come to love it a lot. But I wasted a lot of time on this bug today Thankfully, this scripting business is rare, and soon I will be back to using the tool rather than tooling the tool.
–Abhijit