Bug in "make new agent": probably wrong return value

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 :frowning: Thankfully, this scripting business is rare, and soon I will be back to using the tool rather than tooling the tool.

–Abhijit

I should mention that I am using 8.2.1 (b416).

Also, all ten items created are agents, and all those named “agent” have empty queries and actions and the first one has the right query and action and works correctly.

We’ll investigate. Thanks.

In 8.5.0 (under 10.14.6) creating agents seems to be entirely broken. Before I could get one named agent set up with query and action, but now none.

For example, I can’t get this to work here. It results in an “empty” agent named “agent.”

tell front document of application "Tinderbox 8"
	set myAgent to make new agent
	tell myAgent
		set name to "MyAgent"
		set value of attribute "AgentQuery" to "$Name.contains" & my parenthQuotes("1")
	end tell
end tell

to parenthQuotes(theStr)
	return "(" & quote & theStr & quote & ")"
end parenthQuotes

Confirmed. Changing the script to create a note, rather than agent, is successful.

Odd thing, though, while testing and debugging the script in Debug mode in Script Debugger, the script was successful about 1 of 50 attempts. I cannot reproduce success however. Maybe a timing issue?