View Single Post
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
Attached Files
File Type: zip Omni-PDFView-Dropbox-1.0.scpt.zip (23.2 KB, 911 views)

Last edited by Yury; 2013-04-25 at 10:25 PM..