1

I have 100+ save file of omnigraffle, need to write a script to read then change its content.

Example one:
https://www.dropbox.com/s/97cec5err3qubgq/test.graffle?dl=0

I can open it by TextMate, file's content is in xml format

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
 <key>ActiveLayerIndex</key>
 <integer>0</integer>
 <key>ApplicationVersion</key>
 <array>
 <string>com.omnigroup.OmniGraffle6</string>
 <string>163.7.0.243167</string>
 </array>
 <key>AutoAdjust</key>
 <true/>
 <key>BackgroundGraphic</key>
 <dict>...

So i write code to read and write that file in Python

contents = open(filename).read()
print contents

Result is

?]Ys?8~N~?֯IxgO?Gbg}?%?;)Wm?$sB
4???=?z?;F.??l??h?O????q??ش7~?z???ݓ???{??s#?8=?><?il4??Nx?????6N??o???;?hl?0?o????[XP???VF?Ӑ$d????&?????&i=????????o6??ǭN??w???????Ͷ?+/t}FF$?????
?yװ5???aWT??pT?ۥ??v??r???O??Û?u٣GR?)?I!o?~MK??|7??)[)c?'2;|@g#1?J/?!??Jo?X;ؿ??I??t%L?2Jy&?]?;)ЧC^?D????ܑ_`
????{?l?????h????]?7.?y?]7 ?&?

So how can we read that file in Python/PHP?

asked Mar 13, 2016 at 0:23
1
  • seems like you need to mess with string encoding Commented Mar 13, 2016 at 0:37

1 Answer 1

4

The file in the link you give is compressed with gzip, either as it is stored, or compressed by dropbox when being downloaded to save space.

Either run the gunzip command on the file before using it, or use the python gzip module:

import gzip
with gzip.open(filename) as f:
 contents = f.read()
answered Mar 13, 2016 at 0:28
Sign up to request clarification or add additional context in comments.

1 Comment

Perfect! Thank @Simon Fraser . I should try to unzip that first : |

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.