Solved

AppleScript Save Page As with Safari

Posted on 2008-10-16
3
3,376 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

In certain circumstances, a Microsoft Office mac application may fail to save a document to a network server, with the following error message: "There has been a network or file permission error. The network connection may be lost." An article at…
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now