Solved

AppleScript Save Page As with Safari

Posted on 2008-10-16
3
3,437 Views
Last Modified: 2013-11-12
Goal:  Save pdf to local directory with scripting on OS 10.5.

Scenario:
When I visit:
http://www.domainname.com/directory/generatereportpdf.aspx?VIUEoYx7fvmJJgtoX2bOw2+bHMUSd9JTe39xjuWnj+lCqxiwPX6JWbEYIq%2fIKvi1etUQkfRAaMBKmokWcUfYRWYxL93jpHV%2fd+YgP+%2f20Br6RFQmqJ5Bb1

It generates a PDF report for me on which I can right click in Safari and save it to my Desktop.  I used to have a process in FileMaker Pro using SuperContainer where I would pass the URL to supercontainer and it would upload it to your servers for document storage.  The provider of the pdf changed their site and now encrypt it as seen above and this process no longer works. The solution to my problem as I see it to have applescript save page as in Safari and save the PDF to a local directory and then have supercontainer retrieve the file from that location.

Current sticking point:
I have not found an applescript example of how to do this.
Thank you for your help
0
Comment
Question by:ppeiris
3 Comments
 
LVL 39

Expert Comment

by:Eoin OSullivan
ID: 22738216
Why don't you use the Print to PDF option inside the print dialog in OSX?

You have some access to scripting this with Automator

See this article on how to create a PDF printer .. which you can send the current web page to.
http://www.macgeekery.com/gspot/2005-12/how_to_mass-print_to_pdf

This article contains an applescript that automates the process
http://www.ehmac.ca/mac-ipod-help-troubleshooting/48924-applescript-code-request-print-pdf-function-2.html


0
 
LVL 28

Expert Comment

by:lesouef
ID: 22738298
depends what you want to save, but if a screen capture is enough, using the web viewer, you can display this page in a filemaker layout and save it as pdf using the pdf export from fm. You would be left with the former solution (supercontainer) to upload it.
0
 
LVL 1

Accepted Solution

by:
ppeiris earned 0 total points
ID: 22766899
Thanks for the help.  Here is the solution I came up with.
-- Remove the current copy of the file example.pdf  The try prevents the error when the file does not exist.
try
	do shell script "rm ~/Desktop/example.pdf"
end try
 
activate application "Safari"
 
-- Get the current URL and set it into a variable.
tell application "Safari"
	set urlpdf to URL of document 1
end tell
 
-- The next is UI scripting that goes to the Safari menu and performs a Save As with and then clicks the save button.
tell application "System Events"
	tell process "Safari"
		click menu item "Save As&" of menu 1 of menu bar item "File" of menu bar 1
		click button "Save" of sheet 1 of window urlpdf
	end tell
end tell

Open in new window

0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The error "There was an error performing the update" occurred on a Mac OS X client workstation running  Symantec AntiVirus for Mac (http://www.symantec.com/business/products/purchasing.jsp?pcid=pcat_security&pvid=825_1) - the Enterprise product vers…
In this article we have discussed about the OS X EI Capitan and how to fix Wi-Fi issue in OS X El Capitan. We have explained how to delete system level preferences and create a new Wi-Fi location to resolve Wi-Fi issue.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

806 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question