The Omni Group
These forums are now read-only. Please visit our new forums to participate in discussion. A new account will be required to post in the new forums. For more info on the switch, see this post. Thank you!

Go Back   The Omni Group Forums > Developer > AppleScripting Omni Apps
FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
Exportation in pdf with an applescript Thread Tools Search this Thread Display Modes
Hi,

I would like to create a bash script with an enclosed applescript. I need that because I have a NAS and I want to share pdf versions with people. I edit every days dozens of .oo3 so It would be more convenient to be able to include that process within my rsync script. I've try to do that but I don't know how to solve the issues :
Code:
set myDoc to "/Users/Pamphile/Desktop/notes.oo3"
set pdfSavePath to "/Users/Pamphile/Desktop/"

tell application "OmniOutliner Professional"
	activate
	open myDoc
end tell

tell application "System Events"
	tell process "OmniOutliner pro"
		-- Press command+p to open our print dialog
		keystroke "p" using command down
		
		-- Let's make sure our print dialog is up
		repeat until exists window "Print"
		end repeat
		
		-- Click the PDF menu button
		click menu button "PDF" of window "Print"
		
		-- Make sure the menu is up
		repeat until exists menu item "Save as PDF…" of menu 1 of menu button "PDF" of window "Print"
		end repeat
		-- Select the "Save as PDF" menu item
		click menu item "Save as PDF…" of menu 1 of menu button "PDF" of window "Print"
		
		-- Make sure the save dialog is visible
		repeat until exists window "Save"
		end repeat
		
		-- Press command+shift+g to show the "Go" drop down sheet
		keystroke "g" using {command down, shift down}
		-- Set our location field to our pdfSavePath
		set value of text field 1 of sheet of window "Save" to pdfSavePath
		-- Now click the Go button
		click button "Go" of sheet of window "Save"
		
		-- Now that we are in our desired folder, set the file name and save
		set value of text field 1 of window "Save" to "Notes.pdf"
		
		click button "Save" of window "Save"
	end tell
end tell
Thanks for your help !!!!

Last edited by pamplemousseman; 2011-08-29 at 01:28 PM..
 
Can you describe the issues you're running into? It'll be easier to try and help if we know what the problems are. :-)
 
Hi, thanks for this fast answer !
When I launch the script I have :
exists window "Print" of process "OmniOutliner pro"
--> false

And the same problem with the other command about the control of the buttons
 
It might prove simpler to export to RTF and then convert the RTF to PDF.

An illustrative snippet:

Code:
property pstrConvert : "/System/Library/Printers/Libraries/convert -f "
property pstrDesktop : POSIX path of (path to desktop)
property pstrTempFile : pstrDesktop & "tmp.rtf"

tell application "OmniOutliner Professional"
	-- EXPORT TO RTF
	set oDoc to front document
	export oDoc as "OORTFPboardType" to pstrTempFile
	
	-- CONVERT RTF TO PDF
	do shell script pstrConvert & quoted form of pstrTempFile & ¬
		" -o " & quoted form of (pstrDesktop & name of oDoc & ".pdf")
	
	-- DELETE TMP RTF FILE
	do shell script "rm " & pstrTempFile
end tell
--

Last edited by RobTrew; 2011-08-30 at 12:19 AM.. Reason: add comments to code
 
But beware of a reasonably thermonuclear bug in the OmniOutliner export function.

If you give its output argument the path of a folder rather than a file, it will happily obliterate the folder and all of the data in it ...

My fault, but I managed to lose my Desktop this way this morning :-)
 
thanks for that it works quit good ! and if I want to change the paths (I have a folder with subfolders and lots of .oo3 within) ? because I don't really understand the code (I repeat I'm new with apple scripting). For instance I'll move .oo3 to the desktop and after converted I'll move the .pdf to the nas. Furthermore I don't want to have a lot of .pdf within my folder so I need to remove all of them after the transfer.

Quote:
Originally Posted by RobTrew View Post
It might prove simpler to export to RTF and then convert the RTF to PDF.

An illustrative snippet:

Code:
property pstrConvert : "/System/Library/Printers/Libraries/convert -f "
property pstrDesktop : POSIX path of (path to desktop)
property pstrTempFile : pstrDesktop & "tmp.rtf"

tell application "OmniOutliner Professional"
	-- EXPORT TO RTF
	set oDoc to front document
	export oDoc as "OORTFPboardType" to pstrTempFile
	
	-- CONVERT RTF TO PDF
	do shell script pstrConvert & quoted form of pstrTempFile & ¬
		" -o " & quoted form of (pstrDesktop & name of oDoc & ".pdf")
	
	-- DELETE TMP RTF FILE
	do shell script "rm " & pstrTempFile
end tell
--

Last edited by pamplemousseman; 2011-08-30 at 02:10 AM..
 
You can do it all directly from the shell:

Code:
osascript -e 'tell application id "OOut" to export front document as "OORTFPboardType" to "~/tmp.rtf"' > /dev/null 2>&1
/System/Library/Printers/Libraries/convert -f  ~/tmp.rtf -o output2.pdf > /dev/null 2>&1
 
Ok thanks but how can I specify witch folder I want to use and where I want to save it ?

Quote:
Originally Posted by RobTrew View Post
You can do it all directly from the shell:

Code:
osascript -e 'tell application id "OOut" to export front document as "OORTFPboardType" to "~/tmp.rtf"' > /dev/null 2>&1
/System/Library/Printers/Libraries/convert -f  ~/tmp.rtf -o output2.pdf > /dev/null 2>&1
 
Right there in the command line you supply:

Code:
osascript -e 'tell application id "OOut" to export front document as "OORTFPboardType" to "~/tmp.rtf"' > /dev/null 2>&1
/System/Library/Printers/Libraries/convert -f  ~/tmp.rtf -o output2.pdf > /dev/null 2>&1
the "-o output2.pdf" portion of the convert command tells it to write the output to a file named "output2.pdf" in the current directory. If you want to put it in the directory called "Example" in your home directory, that would be "-o ~/Example/output2.pdf" and so on. Rob's illustrative snippet illustrates the process of building up that command string. To save you the trouble of copying the file to the NAS volume and then deleting the local copy, you could write it directly to the NAS volume. All of this supposes that you've already figured out what the name of the file is going to be, of course...
 
Ok thanks but I way talking about the input directory, how to set it ?
I have a folder with subfolder, the input would be the main folder. Every day there is change with all the .oo3, every day I launch a bash script who save all data to the has. To the has I want the .oo3 and the .pdf. So within the bash script I would like to add an applescript which gonna use the main folder and convert all the file in .pdf and move them to the has. So here in the script I don't know how to change the input, front document.

Quote:
Originally Posted by whpalmer4 View Post
Right there in the command line you supply:

Code:
osascript -e 'tell application id "OOut" to export front document as "OORTFPboardType" to "~/tmp.rtf"' > /dev/null 2>&1
/System/Library/Printers/Libraries/convert -f  ~/tmp.rtf -o output2.pdf > /dev/null 2>&1
the "-o output2.pdf" portion of the convert command tells it to write the output to a file named "output2.pdf" in the current directory. If you want to put it in the directory called "Example" in your home directory, that would be "-o ~/Example/output2.pdf" and so on. Rob's illustrative snippet illustrates the process of building up that command string. To save you the trouble of copying the file to the NAS volume and then deleting the local copy, you could write it directly to the NAS volume. All of this supposes that you've already figured out what the name of the file is going to be, of course...
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
XML and AppleScript seanprice OmniFocus Extras 0 2013-03-14 01:07 PM
Applescript help mojaverat OmniFocus 1 for Mac 1 2011-08-23 03:18 PM
Applescript? dbadev OmniDazzle 0 2011-06-22 05:46 PM
Applescript Help ryan_marsh OmniFocus 1 for Mac 3 2008-11-24 08:51 AM
Applescript, run from USB jem OmniFocus 1 for Mac 4 2007-05-22 02:09 AM


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


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