• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Print to PDF
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Print to PDF


  • Subject: Re: Print to PDF
  • From: Joe <email@hidden>
  • Date: Mon, 09 Jan 2012 18:37:43 -0800

On Jan 9, 2012, at 2:38 PM, Bill Cheeseman wrote:

Every once in a while I like to show off what GUI Scripting can do.

Open a test window in TextEdit, then run this script:

activate application "TextEdit"
tell application "System Events"
tell process "TextEdit"
-- insert GUI Scripting statements here
keystroke "p" using command down
set PDFButton to menu button "PDF" of sheet 1 of window 1
click PDFButton
click menu item "Save As PDF…" of menu 1 of PDFButton
delay 1
click button "Save" of window 1
end tell
end tell

The ellipsis in "Save as PDF..." is the ellipsis character, not three periods.

Filling in the Name field of the Save dialog is left as an exercise.

This runs on Mac OS X 10.7.2 Lion. I vaguely recall that I wrote a script just like this once before, so it probably works on earlier versions, too.


Thank you for that little gem Bill. It works in many applications, so I added a line to make it work from the Scripts menu and assigned it a hotkey with FastScripts.

Now I can generate a PDF from any application (that I've tested so far) that supports printing with a keystroke combo.

tell application "System Events"
set appname to name of first process whose frontmost is true
end tell

activate application appname
tell application "System Events"
tell process appname
keystroke "p" using command down
set PDFButton to menu button "PDF" of sheet 1 of window 1
click PDFButton
click menu item "Save As PDF…" of menu 1 of PDFButton
delay 1
click button "Save" of window 1
end tell
end tell



Joe
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Print to PDF
      • From: Alex Zavatone <email@hidden>
References: 
 >Print to PDF (From: "R. Nelson Byrne" <email@hidden>)
 >Re: Print to PDF (From: Bill Cheeseman <email@hidden>)

  • Prev by Date: Re: Print to PDF
  • Next by Date: Re: Print to PDF
  • Previous by thread: Re: Print to PDF
  • Next by thread: Re: Print to PDF
  • Index(es):
    • Date
    • Thread