• 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: GUI Scripting - Print/Save PDF As Postscript
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: GUI Scripting - Print/Save PDF As Postscript


  • Subject: Re: GUI Scripting - Print/Save PDF As Postscript
  • From: Jeff Porten <email@hidden>
  • Date: Tue, 16 Aug 2005 02:16:31 -0400

Your wish is my command. Got this working over the weekend for PDF printing; add an extra key code 125 to do Postscript.

The evil PDF button click was solved by calculating the xy coordinates from the size of the panel in relation to the window. This works with Safari, where the window is expected to be wider than the panel. If you use it with TextEdit and the panel causes the whole window to shift, YMMV, and I'd be interested to hear about the fascinating ways in which this breaks.

Other clever bits:

1) the script will copy the selection to the clipboard and paste it in as the name of the saved file. If you don't want that, kill the Command-C and Command-V lines and add your own keystrokes.

2) after the script proper is a second bit of code that can be added for resiliency. I noted that sometimes the xy click doesn't take, so in the web parsing script where I incorporated this code, I added a looping test to make sure the UI keeps clicking until it finds the PDF submenu.

This script is slated to go up on my site as part of the donationware offerings. AS-U users not obligated, thanks to all of the help I get here, but if anyone feels so moved you won't catch me complaining. On the other hand, just being able to say I helped Bill Cheeseman with an AppleScript is a giant step on the road to dying happy.

Best,
Jeff


tell application "Safari"
set winbounds to bounds of window 1
set winwidth to (item 3 of winbounds) - (item 1 of winbounds)
set xcoord to (item 1 of winbounds) + winwidth / 2 - 291 + 49 + 41 as integer -- 291, 1/2 of panel width; 49, x from left edge; 41, 1/2 of PDF button
set ycoord to (item 2 of winbounds) + 262


    activate
    tell application "System Events"
        tell process "Safari"
            keystroke "c" using command down
            delay 0.2
            keystroke "p" using command down
            delay 1
            click at {xcoord, ycoord}
            delay 0.2
            key code 125
            delay 0.2
            keystroke return
            delay 0.2
            keystroke "v" using command down
        end tell
    end tell
end tell


(* loop to fix problems where click to open PDF menu is missed *) set needClick to true set loopcounter to 0 repeat until exists window "Save" if needClick then click at {xcoord, ycoord} delay 0.2 key code 125 delay 0.2 keystroke return

                        set needClick to false
                    end if
                    delay 0.2
                    set loopcounter to loopcounter + 1
                    if loopcounter = 5 then
                        set needClick to true
                        set loopcounter to 0
                    end if
                end repeat
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >GUI Scripting - Print/Save PDF As Postscript (From: <email@hidden>)

  • Prev by Date: Re: Vote!
  • Next by Date: Re: Simple InDesign Script
  • Previous by thread: Re: GUI Scripting - Print/Save PDF As Postscript
  • Next by thread: RE: GUI Scripting - Print/Save PDF As Postscript
  • Index(es):
    • Date
    • Thread