RE: applescript-users digest, Vol 3 #1654 - 19 msgs 17. Creating PDF files from a browser (Michael R Johnston)
RE: applescript-users digest, Vol 3 #1654 - 19 msgs 17. Creating PDF files from a browser (Michael R Johnston)
- Subject: RE: applescript-users digest, Vol 3 #1654 - 19 msgs 17. Creating PDF files from a browser (Michael R Johnston)
- From: email@hidden
- Date: Mon, 12 May 2003 12:49:16 +0100
I have written the following Applescript to create PDF files from Internet
Explorer - any comments welcome. You'll need to load the Apple GUI Scripting
Extensions
http://www.apple.com/applescript/GUI/ and I'm sure there is a
more efficient way to do it.
(*
html2pdf <URL> <output folder name> <output file name>
loads a URL and saves it in Portable Document Format
Kevin Jordan, BT Global Services, 23 April 2003
*)
html2pdf(URLname, foldername, filename)
on html2pdf(URLname, foldername, filename)
-- Don't want Internet Explorer already running - make it start
fresh so we know its state
----------------------------------------------------------------------------
----------------------------
closeIE()
-- open up URL in Internet Explorer and call print dialogue
-------------------------------------------------------------------
tell application "Internet Explorer"
Activate -- put IE in the front window
OpenURL URLname -- load the URL
PrintBrowserWindow -- fire up the print dialogue
delay 5 -- wait for it
end tell
-- print window is a system event so we need control it
-----------------------------------------------------------------
tell application "System Events"
tell process "Internet Explorer"
tell window "Print"
tell UI element 5
click button "Save As PDF..."
delay 5 -- wait for it
end tell
end tell
-- Save as PDF is a system event so we need to
control it
-------------------------------------------------------------------
(* can't work out how to change folder and file name
in this dialogue
so just accept what we get and sort it out
later with movePDF
There are two kinds of Save As File dialogue
so we need to account
for both to be on the safe side *)
tell window 1
try -- if it is the big Save dialogue that
appears
tell UI element 10 -- Apple didn;t
bother to name this group
get value of text field 1 --
whatever the file name ie wants to use
copy result to pdfname --
this is the default name we'll change later
end tell
on error -- didn't work so assume the little
Save dialogue has appeared
tell UI element 8 --
get value of text field 1 --
whatever the file name ie wants to use
copy result to pdfname --
this is the default name we'll change later
end tell
end try
click button 2 -- save
end tell
end tell
end tell
-- Don't want Internet Explorer hanging around
------------------------------------------------------
closeIE()
-- hopefully by this time we have a pdf file called <pdfname> on the
desktop
-- so let's call it what we want and put it where we want
----------------------------------------------------------------------------
-------------
movePDF(pdfname, filename, foldername)
end html2pdf
(*
Simply closes Internet Explorer despite any protests it might make
gives us a fresh start when using IE and tidies up afterwards
Kevin Jordan, BT Global Services, 23 April 2003
*)
on closeIE()
ignoring application responses
tell application "Internet Explorer"
Activate
quit
delay 5
end tell
end ignoring
end closeIE
(*
movePDF moves a PDF file from the current users desktop to a preferred
place with a preferred name>
Kevin Jordan, BT Global Services, 23 April 2003
*)
on movePDF(oldName, newName, destination)
copy ".pdf" to postfix -- PDF Extension
copy "Users:" & {do shell script "echo $USER"} to MyHome -- get
MacOS Path to home
copy MyHome & ":Desktop:" to MyDesktop -- record MacOS path to
desktop
copy MyDesktop & oldName to MyFile -- record fully qualified file
name using old name
tell application "Finder"
set fileref to a reference to file MyFile -- make pointer to
file using old name
set name of fileref to newName & postfix -- rename file
copy MyDesktop & newName to MyFile -- re-record fully
qualified file name using new name
set fileref to a reference to file MyFile -- remake pointer
to file using new name
move fileref to folder destination -- move file to a better
place by far
end tell
end movePDF
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.