OmniOutliner — Auto-Fill Source Column with Filename (without extension) incl Confirmation Dialog

Any sufficiently advanced technology is indistinguishable from magic.
Clarke’s Third Law by Arthur C. Clarke

A while ago a reader send me a really useful AppleScript to automatically fill a column in OmniOutliner with the name of file. Very useful if you put your notes, e.g., about a book or an article, in an OmniOutliner file and then want to tag each line with the source information (you can’t cite it otherwise!).

The script can be improve in many ways, e.g., only filling empty source cells, or being able to type in a name, but so far, it works very well the way it does. Two things did bug me, though. I had to replace the ending (search and replace “.ooutline” by “”). And there was no confirmation dialog. You execute the script, it simply replaces the source information with the file name. Potentially devastating if you have collected information from many different sources in one outline.

So, here’s an updated version. Complete with “remove the file extension” (which was surprisingly hard to do, I guess, I don’t understand the variable types) and a safety question.

-- Rename Columns in OmniOutliner
-- Created by Bruno Conte
-- Replacement function via mindtpi on http://macscripter.net/viewtopic.php?id=18308
-- Confirmation Dialog via karenflower on https://forums.macrumors.com/threads/applescript-dialog-boxes.468933/
-- set text of cell 3 of row i to docName
-- cell 3 is the source column, seems like the notes column isn’t visible yet counted as well

set question to display dialog "Actually replace the source column with the file name?" buttons {"Yes", "No"} default button 2
set answer to button returned of question

if answer is equal to "Yes" then
tell application "OmniOutliner"
set DocumentName to name of front document of application "OmniOutliner"

if DocumentName contains ".ooutline" then
set aCount to count every character of DocumentName
set aCount to aCount - 9
set DocumentName to characters 1 thru aCount of DocumentName as string
set DocumentName to word -1 of DocumentName as string
end if

tell front document
try
set rowCount to count of rows
repeat with i from 1 to rowCount
set text of cell 3 of row i to DocumentName
end repeat
on error errormessage number errornumber
display dialog errormessage buttons {"OK"} default button 1
end try
end tell
end tell
end if

Works like a charm.

(Looks better in the editor, but if you copy-paste it, it should auto-format. As usual, without any warranty.)

1 Trackback / Pingback

  1. What makes a good outliner? | ORGANIZING CREATIVITY

Comments are closed.