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

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


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
macrumors newbie
Join Date: Jul 2011

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.

--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

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

You will find what you are looking for here:

also (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

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

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Automator "Save as Script" gone in Lion? japanime Mac Programming 5 Aug 2, 2011 02:44 AM
Print "Save as PDF" broken jjprusk OS X 0 Apr 2, 2011 09:47 AM
"Save as PDF" crashes the application academianut OS X 0 Mar 2, 2009 10:19 AM
Automator "Save as Application" Doesn't work! MacFan25863 Mac Applications and Mac App Store 8 May 23, 2007 11:52 PM
"Save as pdf" orientation theBB OS X 2 May 28, 2006 11:19 PM

All times are GMT -5. The time now is 12:16 AM.

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

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