The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniFocus Extras (http://forums.omnigroup.com/forumdisplay.php?f=44)
-   -   OmniFocus -> PagePacker Script [Python] (http://forums.omnigroup.com/showthread.php?t=5324)

erik_westra 2007-10-28 11:21 AM

OmniFocus -> PagePacker Script [Python]
 
1 Attachment(s)
Hi folks,

The [URL="http://weblog.bignerdranch.com/?p=24"]PagePacker[/URL] application looks like a great way to carry your context lists with you. It's fully scriptable, so I started looking at ways to link it into OmniFocus.

Unfortunately, there's no straightward way of scripting the "Save to PDF" functionality within OSX, so it's not easy to get the context lists out of OmniFocus in a nicely-formatted way. Fortunately, though, PagePacker handles plain-text files, so I decided to knock something together that pulls the context lists out of OmniFocus, and imports them into PagePacker as a series of plain text files.

The result is a bit ugly, but it seems to work fine. I'm not keen on writing AppleScript, so I implemented this in Python -- it should work on any copy of OSX, as Python comes pre-installed.

I've even added the ability to add your own PDF files to the PagePacker document (to add a custom title page, or whatever). Ultimately, I'd like to extend this using a toolkit I'm familiar with (a thing called ReportLab) that can create PDF files programmatically. With that, we'd get nicely-formatted context lists which could be imported into PagePacker directly -- assuming, of course, that Omni don't beat me to it by adding the functionality directly into OmniFocus (which would be the ideal way to handle this).

Anyway, I've attached my first cut at this script. There are instructions in the script itself, so if you open it in your favourite text editor, you should have everything you need to get going.

- Erik.

[Edited to upload newer version of script]

Craig 2007-10-28 01:33 PM

I get
[CODE]Traceback (most recent call last):
File "contexts_to_pagePacker.py", line 304, in ?
main()
File "contexts_to_pagePacker.py", line 251, in main
task,project = line.split("\t")
ValueError: need more than 1 value to unpack[/CODE]

dhm2006 2007-10-28 03:59 PM

[QUOTE=erik_westra;23562]The result is a bit ugly, but it seems to work fine. I'm not keen on writing AppleScript, so I implemented this in Python -- it should work on any copy of OSX, as Python comes pre-installed.
[/QUOTE]

I don't know much about Python. Do you *have* to run the script in terminal? What I mean to ask if whether running it in terminal is the only way to run it.

erik_westra 2007-10-28 04:41 PM

Hi Craig,

[QUOTE=Craig;23572]I get
[CODE]Traceback (most recent call last):
File "contexts_to_pagePacker.py", line 304, in ?
main()
File "contexts_to_pagePacker.py", line 251, in main
task,project = line.split("\t")
ValueError: need more than 1 value to unpack[/CODE][/QUOTE]

Strange...that should be impossible in theory. The Applescript used to extract the tasks must be returning a value without a project included.

This doesn't happen on my machine -- I suspect there's something about your set of tasks that is causing the script to crash.

I've just uploaded a new version of the script, which checks to see if a project name was included in the task's text extracted from OmniFocus. If not, is just leaves the project name blank, rather than crashing.

Please try re-downloading the newer version (I've called this version 0.2), and let me know if it works or not.

Thank,

- Erik

erik_westra 2007-10-28 04:47 PM

Hi dhm2006,

[QUOTE=dhm2006;23576]I don't know much about Python. Do you *have* to run the script in terminal? What I mean to ask if whether running it in terminal is the only way to run it.[/QUOTE]

Good question. In theory, I ought to be able to convert this to an "applet" that can be double-clicked from the Finder. I haven't done this myself, because in my work we create standalone applications from the Python source rather than applets. These standalone applications include the entire Python interpreter, as well as a bunch of 3rd party libraries, which makes for a 20mb download. That's hardly needed for something as simple a this!

I'll let you know if I can figure something out for you.

- Erik.

erik_westra 2007-10-28 05:42 PM

1 Attachment(s)
Hi dhm2006,

[QUOTE=dhm2006;23576]I don't know much about Python. Do you *have* to run the script in terminal? What I mean to ask if whether running it in terminal is the only way to run it.[/QUOTE]

I think I have a workaround to this -- I've created a simple shell script that should do what you want, and bundled it into a double-clickable application using a tool called "Platypus".

I've attached a zip archive which contains a small application called "Run Script". Place this application in the same directory as the "contexts_to_pagePacker.py" file, along with any PDF files you may want to add to the output (as described in the documentation at the top of the script). You can then double-click the application to run the script.

If you want to put this elsewhere, make an alias -- it's important that the application itself stays in the same directory as the Python script.

Hope this helps...

- Erik.

Craig 2007-10-28 06:27 PM

[QUOTE=erik_westra;23577]Please try re-downloading the newer version (I've called this version 0.2), and let me know if it works or not.[/QUOTE]

Nope, same problem (though this time with references to line 310 and line 257 respectively).

erik_westra 2007-10-28 07:42 PM

Hi Craig,

[QUOTE=Craig;23581]Nope, same problem (though this time with references to line 310 and line 257 respectively).[/QUOTE]

Oops! Sorry about that -- I'd added the error-check, but forgot to delete the original line which caused the crash. Try v0.3...

- Erik.

Craig 2007-10-29 03:35 AM

[QUOTE=erik_westra;23582]Try v0.3...[/QUOTE]

Now I get
[CODE]53:66: execution error: OmniFocus got an error: NSReceiverEvaluationScriptError: 4 (1)
Error running Applescript: 256[/CODE]

EDIT: Ignore the above - I have it working now.

dhm2006 2007-10-29 04:56 AM

[QUOTE=erik_westra;23580]I think I have a workaround to this -- I've created a simple shell script that should do what you want, and bundled it into a double-clickable application using a tool called "Platypus".

I've attached a zip archive which contains a small application called "Run Script". Place this application in the same directory as the "contexts_to_pagePacker.py" file, along with any PDF files you may want to add to the output (as described in the documentation at the top of the script). You can then double-click the application to run the script.

If you want to put this elsewhere, make an alias -- it's important that the application itself stays in the same directory as the Python script.[/QUOTE]

Thank you. I had already been looking at the original script in Platypus, but could not find a "Run Script" command (like there is in Applescript Script Editor). I appreciate your creating this extra script for me (I hope others can use it as well -- I can't be the only person that doesn't like to muck around in the terminal).


All times are GMT -8. The time now is 02:34 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.