The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniFocus Extras (http://forums.omnigroup.com/forumdisplay.php?f=44)
-   -   Omni Focus Perspective Print to Dropbox (http://forums.omnigroup.com/showthread.php?t=27649)

Yury 2013-01-03 07:14 PM

Omni Focus Perspective Print to Dropbox
 
Hello All,

I got this idea from a member of the forums since I was in a dilema, I love OmniFocus but needed a nice way to keep track of it on my Android Phone (mini Tablet / Samsung Galaxy Note 2).

I was having a hard time with this, and then whpalmer4 just told me to use perspectives. Unfortunately I was using them on my Mac and my iPad but never used them to print things out so when I was doing a regular print was disappointed.

Having played with perspectives I was able to accomplish what I wanted, but hated the manual print options, or the automater. So I created this applescript to automate the selection of various perspectives and printing of them to a Dropbox folder.

Requirements for this script:
1. Your Dropbox folder must be in /Users/username/Dropbox
2. You want to create a Folder there called OmniFocus
3. You need to modify the applescript and change the perspective names you use in variable [B]"theListPerspectives"[/B]

The Perspective List goes in quotes and is separated by a comma.
(example: "List1", "List2", etc) - In the scripts are some of the ideas for the perspectives that I have but you either name your perspective like mine or change the names.

It does not matter how many perspectives you have, the script will print them all.

Please be aware, that I have to delete the PDF files in the OmniFocus directory before creating a new one.

Yury 2013-01-03 07:19 PM

1 Attachment(s)
Version 1.0 of the script

[CODE]
-- OmniFocus Perspective Print to Dropbox
-- Written by Yury German <yury (at) technologysecure.com>
-- Version: 1.00
-- Date of Change: 2013-01-03
--
-- About this script:
-- This takes a number of perspectives taht are defined in the List below and creates
-- a PDF export for each of them to a Dropbox folder for viewing on other devices
-- You can do this manually, but this does it fast and all at once, so no matter what views/perspectives
--
-- Credit:
-- Credit for the idea behind the script goes to whpalmer4 on omni Forums.
-- I was complaining about the PDF view looked bad, and it was because I was not using perspectives
-- So now I created this script do do this.
set userName to short user name of (system info)
set pdfSavePath to "/Users/" & userName & "/Dropbox/OmniFocus"
set theListPerspectives to {"Active-Projects", "Active-Context", "OnHold-Projects", "OnHold-Context", "Work-Projects", "Work-Context", "Personal-Project", "Personal-Context"}

-- Need to delete files if exist as GUI scripting is not that great with replace.
set myFilePath to "Macintosh HD:Users:" & userName & ":Dropbox:OmniFocus"

repeat with theCurrentValue in theListPerspectives
set myFile to (myFilePath & ":" & theCurrentValue & ".pdf")
tell application "Finder"
if exists file myFile then
delete file myFile
end if
end tell
end repeat


-- Now for the script
tell application "OmniFocus"
activate
end tell
tell application "System Events"
tell process "OmniFocus"
repeat with theCurrentValue in theListPerspectives
-- This Prints out Current Name of Perspective from Perspective List and names it With PerspectiveName.pdf
click menu item theCurrentValue of menu "Perspectives" of menu bar item "Perspectives" of menu bar 1
click menu item "Print…" of menu "File" of menu bar item "File" of menu bar 1
-- Click the PDF menu button
repeat until exists sheet 1 of window 1
delay 0.2
end repeat
tell sheet 1 of window 1
click menu button "PDF"
repeat until exists menu 1 of menu button "PDF"
delay 0.2
end repeat
click menu item "Save as PDF…" of menu 1 of menu button "PDF"
end tell
repeat until exists (sheet 1 of sheet 1 of window 1)
delay 0.2
end repeat
set myFileName to (theCurrentValue & ".pdf")
keystroke myFileName
delay 0.2
keystroke "g" using {command down, shift down}
repeat until exists sheet 1 of sheet 1 of sheet 1 of window 1
delay 0.2
end repeat
tell sheet 1 of sheet 1 of sheet 1 of window 1
set value of text field 1 to pdfSavePath
delay 0.4
click button "Go"
end tell
repeat while exists sheet 1 of sheet 1 of sheet 1 of window 1
delay 0.2
end repeat
tell sheet 1 of sheet 1 of window 1
click button "Save"
end tell
repeat while exists sheet 1 of sheet 1 of window 1
delay 0.2
end repeat
repeat while exists sheet 1 of window 1
delay 0.2
end repeat
end repeat


end tell
end tell





[/CODE]

johnwin 2013-01-13 11:14 AM

Yury, thank you so much for this script. I'm Windows at work and Android tablet. Just yesterday I thought of pdf-ing my lists to Dropbox so I can access them elsewhere. I tried to create an Automator 'script' but with no success.

Your script ran first time. Now I need to figure out a way to set a chron job to run this at 5am everyday and remove the previous versions of the .pdfs.

johnwin 2013-01-13 11:53 AM

One question Yury please.

If I run the script and the pdfs from a previous run are still in the Dropbox folder the mac waits for me to confirm the 'replace' requirement.

Is there a way that the script could either:

- accept the replace IF it occurs
- delete the old pdfs before printing the new ones
- add unique data to the file name, such as today's date in the format YYYYMMDD

Any ideas? Thanks again

[B]EDIT:[/B]

Found a workaround using Text Expander but a scripted solution would be better

Yury 2013-04-25 03:14 PM

[QUOTE=johnwin;119195]Yury, thank you so much for this script. I'm Windows at work and Android tablet. Just yesterday I thought of pdf-ing my lists to Dropbox so I can access them elsewhere. I tried to create an Automator 'script' but with no success.

Your script ran first time. Now I need to figure out a way to set a chron job to run this at 5am everyday and remove the previous versions of the .pdfs.[/QUOTE]

Sorry took some time to respond... WORK is extremely busy.

The script does this automatically, it should delete the previous version of the PDF and then create the new ones. Please let me know if it is not working for you.

The first part of the script is to Delete the PDF's, they should automatically be deleted. But I did find an error in that I duplicated the path for the script ....

Just make sure that there is only one line
set theListPerspectives to {"Active Projects", ... }

Cypher 2013-04-28 07:58 AM

Just spotted this one and will give it a try.

I have manually create my pdf's for a long time now mainly due to be stuck on windows at work. I often forgot to update the pdf's in my dropbox account and it was a real pain at time. Recently I changed my phone to an iphone mainly so I could have my OF database with me all the time.

Regarding removing the old pdf's another option if you have Hazel would be to have hazel monitor the pdf folder and move them automatically. ie. have the applescript generate them to your Mac's document folder and then have hazel move them to dropbox.


All times are GMT -8. The time now is 09:28 AM.

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