Mori Diagram

Tags ( )

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.

Version: .2
AttachmentSize
GTDchart.png77.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.

Cool, this has been on my

Cool, this has been on my long term to-do list for a long time. Nice use of applescript, I'm glad that someone finally did this. When you have a chance I think it would be good to attach a screen shot to this post, and also it might be good to attach the applescript as a separate file so people don't need to copy and past. Thanks again for this contribution. Nice!

Nice idea

I added a path (home folder) to the temp file name as otherwise it would throw a "network access" error. Possibly becuase I don't use an admin account.

I found no way to attach files, so:
http://www.celvina.de/tmp/moriviz.applescript
http://www.celvina.de/tmp/moriviz.png

With more than one notebook open the results are rather erratic (smart folders are preferred even if no longer selected), which may be related to http://www.hogbaysoftware.com/node/941

Run from the script menu (not editor) it somehow doesn't do anything.

BTW everybody should have http://www.pixelglow.com/graphviz/

I don't use an admin account either

I never tried selecting a smart folder. I don't know what that would do. Can you access a smart folder as a normal entry through applescript? As for the confusion with multiple notebooks, it should in theory, use the front one I think. But its not like I have tested this thing more than 3 times:)

I also noticed some

I also noticed some bugginess when there were many Mori docs open.

It might help to add lines to explicitly direct calls to the front document

tell application "Mori"
set theDoc to front document
tell theDoc
...
...
end tell
end tell

It's a cool script, by the way. I like the that it gives me a new way to view my Mori data.

Hello! Found lots of entertaining posts at this website.

Hello! Found lots of entertaining posts at this website. Read most of the archive. Thank for your work!

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.