Set compressOnDiskKey via AppleScript

I need all OmniGraffle files to be stored uncompressed in order to enable better diffs with git/GitHub. For that reason, I would like to write an AppleScript (or use whatever kind of automation tool) to automatically “convert” all OmniGraffle files to set compressOnDiskKey to false.

Is this possible with AppleScript?

Is there a (hidden) preference setting to enforce new files to be saved uncompressed?

OmniGraffle automatically detects whether a document is compressed or not, so the easiest way to automate the decompressing of documents is to use the command line tool “gzip” to decompress them, like so:

% gzip --decompress < CompressedDocument.graffle > UncompressedDocument.graffle

Or, to do everything in the current directory:

% find . -type f -name '*.graffle' -print | while read file; do; mv $file $file.gz; gzip -d -f < $file.gz > $file; rm $file.gz; done

(I was a little lazy here: I didn’t bother checking whether they’re compressed before decompressing, I just used the “force” flag to tell gzip it shouldn’t complain about content that’s not actually compressed.)

From the command line, you can use the file command to tell whether a file is stored compressed or not:

% file *Document.graffle
CompressedDocument.graffle:   gzip compressed data, from FAT filesystem (MS-DOS, OS/2, NT)
UncompressedDocument.graffle: XML 1.0 document text, ASCII text

For new documents, you can set your document template to uncompressed so that any documents you create from that document are uncompressed. But then you have to worry about which documents came from which template and double-check anyway, so I have another suggestion:

Rather than worrying about whether your graffle documents are compressed or not, I’d suggest writing a git pre-commit hook to automatically decompress any graffle documents you’re checking into git before they get committed, so your repository always stores the uncompressed version whether they started out that way or not.

Hope this helps!

Thank you very much for the answer. I wanted to install a commit hook, but only for verification. But of course it is better to automatically convert the files.

Isn’t it a problem of OmniGraffle if the file decompressed but the attribute compressOnDiskKey is true?

No, we don’t actually read that setting (by the time we did it would be too late!), it’s derived from the compression state of the data in the document.

(We’re not supposed to be writing it either; we’ll fix that.)