Applescript hurdle I can't quite get past...
Dan Lowe
dan at tangledhelix.com
Sun Mar 11 22:16:53 PDT 2007
I've been using PagePacker[1] lately to make pocket booklets. Since
one page in the booklet is a printout of the current month's calendar
from iCal, naturally I turned to Applescript so I wouldn't have to
manually print a PDF of the calendar every time I needed to print a
new booklet. The process of getting the page to PDF is as follows...
[1]: http://weblog.bignerdranch.com/?p=24
* Start iCal
* Cmd-P (print)
* Set "View" pulldown to "Month"
* Set "Paper" pulldown to "US Letter"
* Set "Starts" pulldown to "This Month"
* Check "All-Day Events"
* Check "Timed Events"
* Uncheck "Mini-Months"
* Uncheck "Calendar Keys"
* Uncheck "Black and White"
* Set "Text size" pulldown to "Medium"
* Click "Continue"
* Click "PDF" button, select "Save as PDF..."
* Enter filename, click "Save"
Now I have a script (see below) that will go through the process up
until the "Click PDF button" step just before the end. It gets to the
point where that button is available, but will not click it. Here is
the script I have so far:
========== begin script ==========
tell application "System Events"
tell process "iCal"
activate
set frontmost to true
(* Bring up the print dialog *)
keystroke "p" using command down
tell window "Print"
(* The "View" pulldown *)
if the value of pop up button 1 is not "Month" then
click pop up button 1
tell pop up button 1
keystroke "m"
keystroke return
end tell
end if
(* The "Paper" pulldown *)
if the value of pop up button 2 is not "US Letter" then
click pop up button 2
tell pop up button 2
keystroke "u"
keystroke "s"
keystroke space
keystroke "l"
keystroke "e"
keystroke "t"
keystroke return
end tell
end if
(* The "Starts" pulldown *)
if the value of pop up button 3 is not "This Month" then
click pop up button 3
tell pop up button 3
keystroke "t"
keystroke "h"
keystroke "i"
keystroke "s"
keystroke return
end tell
end if
(* These two checkboxes we want to turn ON *)
if value of checkbox "All-Day Events" is not 1 then
click checkbox "All-Day Events"
end if
if value of checkbox "Timed Events" is not 1 then
click checkbox "Timed Events"
end if
(* These three checkboxes we want to turn OFF *)
if value of checkbox "Mini-Months" is not 0 then
click checkbox "Mini-Months"
end if
if value of checkbox "Calendar Keys" is not 0 then
click checkbox "Calendar Keys"
end if
if value of checkbox "Black and White" is not 0 then
click checkbox "Black and White"
end if
(* The "Text size" pulldown *)
if the value of pop up button 5 is not "Medium" then
click pop up button 5
tell pop up button 5
keystroke "m"
keystroke return
end tell
end if
click button "Continue"
end tell
end tell
end tell
========== end script ==========
I've used the UI Element Inspector to determine that the "PDF" button
is a menu button. I have tried this:
tell application "System Events"
tell process "iCal"
click menu button "PDF"
end tell
end tell
And various other schemes including stuff like:
tell button "PDF"
keystroke "s"
keystroke "a"
keystroke "v"
keystroke "e"
keystroke space
keystroke "a"
keystroke "s"
keystroke space
keystroke "p"
keystroke "d"
keystroke "f"
keystroke "."
keystroke "."
keystroke "."
keystroke return
end tell
But, nothing seems to work. I get various errors when I run this in
Applescript Editor, always at the PDF button step.
Any help will be appreciated. I have this feeling that I am not
seeing the forest for the trees.
-dan
More information about the MacOSX-talk
mailing list