This script takes the selected part of an outline and makes a DOT file. The file can then be opened in graphviz (free, open source cocoa diagram maker) as well as others. Graphviz will automatically update the graph if you change the selection and rerun the script. There is an example output attached below.
property graph_str : ""
tell application "Mori"
set graph_str to "digraph {" & return
set selected_entries to selection as list
repeat with each in selected_entries
set graph_str to my build_graph(each, graph_str)
end repeat
set graph_str to graph_str & "}"
my write_to_file(graph_str, (((path to desktop folder) as rich text) & "mori.dot"), false)
return graph_str
end tell
on build_graph(this_entry, this_graph)
using terms from application "Mori"
repeat with each_child in entries of this_entry
set name_of_each to name of this_entry
set this_graph to this_graph & "\"" & (name of this_entry as string) & "\"" & "->" & "\"" & (name of each_child as string) & "\";" & return
set this_graph to my build_graph(each_child, this_graph)
end repeat
end using terms from
return this_graph
end build_graph
on write_to_file(this_data, target_file, append_data)
try
set the target_file to the target_file as text
set the open_target_file to ¬
open for access file target_file with write permission
if append_data is false then ¬
set eof of the open_target_file to 0
write this_data to the open_target_file starting at eof
close access the open_target_file
return true
on error
try
close access file target_file
end try
return false
end try
end write_to_file
Updated by Jesse For some reason the original version of this stopped working. Not sure why (I just love how easy applescript is to debug!!!:)), but moving the file writing code into a separate event handler seems to make it work.
Updated 2 by Jesse More problems. The strings returned by Mori's 'name of' are unicode strings. And either they were not being written out correctly, or Graphvis doesn't understand unicode text files. In anycase i've fixed the problem by casing everyting to to string using "as string", and not it seems to work again on OS X 10.4.
| Attachment | Size |
|---|---|
| GTDchart.png | 77.94 KB |
Looks interesting Joe. I'll
Looks interesting Joe. I'll try it as soon as I download graphviz. I had wanted to experiment with something like this a while back, but never got around to it.
You might also want to post a file version of the script (.scpt). I have noticed that a some people, who don't use applescript, will generally request that. As long as you zip it, you should be able to attach it to your original post.