Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jul 27, 2011, 12:39 PM   #1
dmgibney
macrumors newbie
 
Join Date: Jul 2011
Applescript to automate "Save as PDF" in print menu

Hello,

I've spent some time searching for a solution but haven't found anything, hence this post. Here's what I would like to do...I often find myself using the "save as PDF" option in the print menu to archive things that I do online (bank receipts, order confirmations, etc...) I save the PDFs to either of two places, a personal records folder for my personal transactions, and a business folder for my business transactions.

I am trying to write an applescript that I could select from the script menu that would:

1 - Open the print menu (cmd+p)
2 - Choose "Save as PDF…" from the print menu
3 - Prompt me to send it to either my personal or business folder
4 - Save the PDF to a subfolder for the current year (HD/users/username/docs/personal_records/2011)

I am new to applescripting, all I've been able to do so far is get the print menu of the current application to open. I did that with this code:

tell application "System Events"
keystroke "p" using {command down} -- activate print menu item
end tell

Any ideas on how to automate the selection of "Save as PDF" or how to dictate the save location based on the current year?

Your help is greatly appreciated!
dmgibney is offline   0 Reply With Quote
Old Jul 29, 2011, 11:07 PM   #2
MacGrunt
macrumors newbie
 
Join Date: Jul 2011
G'day,

It looks like you're still waiting for an answer. Here's a partial one, as I have no idea how to script the Safari part. I haven't done any UI scripting.

Code:
--get the current year 
set ThisYear to year of (current date)

--create a dialog to choose where to store the pdf
set ThisChoice to button returned of (display alert "Where should this be stored?." buttons {"cancel", "business", "personal"} default button "personal")
if ThisChoice is "personal" then
	set TheFolder to "HD:users:username:docs:personal_records:"
else if ThisChoice is "business" then
	set TheFolder to "HD:users:username:docs:business_records:"
else if ThisChoice is "cancel" then
	error -128
end if

--create 'year' folder if it does not already exist
tell application "Finder"
	if (exists folder ThisYear of folder TheFolder) is false then
		make new folder at TheFolder with properties {name:ThisYear}
	end if
end tell

--set the final folder path
set FolderPath to TheFolder & ThisYear & ":" as string

Hope that helps a little

m.
MacGrunt is offline   0 Reply With Quote
Old Jul 27, 2013, 02:04 AM   #3
muchado
macrumors newbie
 
Join Date: Mar 2013
Automating "Print to PDF"

You will find what you are looking for here:

http://www.ehmac.ca/mac-iphone-ipad-...unction-2.html

also

http://www.jaimerios.com/?p=171 (which references the previous script)

[Yes, I know this is a dead thread, but it appeared when I was searching for an answer, so I thought I would post what I found for the next person...]
muchado is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
AppleScript: How do I save multiple Excel sheets to one pdf using Applescript sbtaylor1 Mac Programming 0 Oct 28, 2013 11:38 PM
AppleScript: How do I save multiple Excel sheets to one pdf using Applescript sbtaylor1 Mac Applications and Mac App Store 0 Oct 28, 2013 11:32 PM
PDF file "quick look" into the menu bar? Notawiz OS X 10.8 Mountain Lion 4 Jun 8, 2013 10:12 AM
Automate Print to PDF Receipts folder? newmacuser13 OS X 1 Mar 14, 2013 04:36 PM
Why Mac OS X "Save a pdf" feature always print a pdf with smaller text? satanicsurferz Mac Applications and Mac App Store 1 Jan 31, 2013 11:21 AM

Forum Jump

All times are GMT -5. The time now is 08:31 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC