Search all outlines or graffle docs for text

I tried doing a grep but doesn’t work. Is there a way to search all omni outliner documents and omni graffle documents for a string, like "David "?

OO and OG documents are zipped bundles containing, inter alia, XML text files.

You may find that you can get somewhere with zgrep

1 Like

mm ok
thank you.

found this

for d in $(find /path/to/dir -maxdepth 1 -type d)
#Do something, the directory is accessible with $d:
echo $d
done >output_file
It searches only the subdirectories of the directory /path/to/dir. Note that the simple example above will fail if the directory names contain whitespace or special characters. A safer approach is:

find /tmp -maxdepth 1 -type d -print0 |
while IFS= read -rd ‘’ dir; do echo “$dir”; done
Or in plain bash:

for d in /path/to/dir/*; do
if [ -d “$d” ]; then
echo “$d”

Omni apps support Spotlight searches, so you can do that search directly from Spotlight (the magnifying glass in the top right) or with a Finder search (if you need more flexibility or want to turn your results into a smart folder).

Or if you’d prefer to stick with the command line, you can use the mdfind command-line interface to Spotlight :

% mdfind David
[Lists all files on your hard drive containing the word David]
% mdfind kind:OmniGraffle David
[Lists all OmniGraffle documents on your hard drive containing the word David]
% mdfind -onlyin . kind:OmniGraffle David
[Lists all OmniGraffle documents in the current folder containing the word David]

For more information, see the mdfind(1) manual page (man mdfind).


This works great, doing through a directory with many omnigraffle docs

find . -iname “*.plist” -print0 | xargs -0 zgrep “mind” *.plist

for the lines of text, or

find . -iname “*.plist” -print0 | xargs -0 zgrep -l “mind” *.plist

for file names only.

thanks. my zgrep works too :-) and I can see the lines.

I have never been able to make spotlight work as you described. I am an iOS software developer since 2008.

Hmm, that’s strange! Spotlight certainly works for me, though of course that’s only true in folders Spotlight knows to index. (It has a built-in exclusion list for some locations like /tmp and some locations in ~/Library, and you can also add your own exclusions using System Preferences. But most places in your account and certainly common locations like Documents and Desktop should generally be indexed. And the index updates immediately as edited documents are saved, as you can see with mdfind -live.)

oh i see. I fiddled with it and it worked.

It’s strange. sometimes the command line lets me cd into a .graffle and sometimes it doesn’t, and Find sometimes does the same thing.

michaels-MacBook-Pro-Early-2015:Omnipresence michaelisbell$ cd “knowledge thought.graffle”
michaels-MacBook-Pro-Early-2015:knowledge thought.graffle michaelisbell$ cd …
michaels-MacBook-Pro-Early-2015:Omnipresence michaelisbell$ cd “TheLTD.graffle”
-bash: cd: TheLTD.graffle: Not a directory

troublesome, because that means Find doesn’t work.

However, now that you have cleared up my understanding of Spotlight, that seems to always work. Thank you very much for that.

Yes, using the Spotlight search helps insulate you from that sort of detail. If you check the Document inspector, you’ll find that you can save an OmniGraffle document as a flat file or as a file package (or let OmniGraffle make that choice for you automatically based on whether or not you have any embedded image attachments), and that you also have a choice as to whether its XML should be compressed or not. (Compressed saves space and thus I/O bandwidth, which is so much more expensive than CPU that it’s generally a pretty big win. But uncompressed makes it easier to review changes when you’re storing a document in a version control system.)

So there are at least four different ways an OmniGraffle document can end up being stored on disk. But our Spotlight plugin abstracts away all that detail (as well as understanding how to correctly parse the embedded RTF content that’s actually used to store your text inside the XML).

(That said, we used a text-based file format with standard compression techniques for a reason! It lets you get at the data stored in our documents even if you don’t have OmniGraffle installed on a system—e.g. if you’re trying to process those documents on a system running Linux or something.)

can you pipe mdfind into a grep or zgrep? to get line output?

I mean for Omnigrafle specifically, of course.

Yes, and I actually have a shell function that I use frequently which does exactly that:

mdgrep () {
	mdfind -onlyin . $* | sed -e "s#^$(pwd -P)#.#" -e 's/\\/\\\\/g' -e 's/"/\\"/g' -e "s/'/\\'/g" -e 's/ /\\ /g' | xargs grep -H $*

Of course, the above function uses grep which is only well-suited for files which are stored uncompressed. But you can replace grep with zgrep to get something like what you were doing before.

1 Like

cool. that syntax breaks my mind but I’ll look at it :-) I’m a fake bash programmer, not a real one hahhah.

Yeah, that sed piece is hard to read. It’s actually pretty simple logic, though; it’s just quoting special characters in the returned paths by adding a backslash prefix to each of them. So:

  • \ becomes \\
  • " becomes \"
  • ' becomes \'
  • [space] becomes \[space]

(But it’s especially unreadable because the backslash characters have to be quoted in the shell so they can reach sed, so the relatively simple \\ becomes \\\\.)

I don’t think this really works, because while find drops into the graffle directory and gives me access to the data.plist file, when it’s behaving well, spotlight doesn’t.

michaels-MacBook-Pro-Early-2015:Omnipresence michaelisbell$ mdfind -onlyin . Leo
/Users/michaelisbell/OmniPresence/bsnt-mapping-outline (conflict 3 from michaelisbell on michaels-MacBook-Pro-Early-2015).ooutline
/Users/michaelisbell/OmniPresence/aug 83.pdf
/Users/michaelisbell/OmniPresence/Playing Americans Beats 2 (conflict from mobile on MPI iPad Air 2015).graffle
/Users/michaelisbell/OmniPresence/bsnt-mapping-outline (conflict 2 from michaelisbell on michaels-MacBook-Pro-Early-2015).ooutline
/Users/michaelisbell/OmniPresence/Playing Americans Beats 2.graffle
/Users/michaelisbell/OmniPresence/bsnt-mapping-outline copy.ooutline

I’m just getting the graffle ‘file’, not the plist file, from mdfind.

I can’t find an mdfind syntax that actually returns the plist file, the way Find does.

mdfind won’t ever return the embedded plist file, because it understands the document as a whole rather than its individual components (which are an implementation detail from its perspective).

Rather than trying to find the data.plist, just pass the -r flag to zgrep so that it recursively searches all files inside any .graffle or .ooutline documents that actually turn out to be stored as file wrappers (UNIX directories).

I’ll see if that works.


mdfind -onlyin . kind:Omnigraffle Leo -0 | xargs -0 zgrep -r “Leo” *.plist

this works brilliantly

wanted to add, FoxTrot Professional is brilliant at this. Highly recommended.