Saving a PDF from Safari via Applescript

Hello. I’m an Applescript neophyte and have run into a problem I cannot seem to solve and no amount of Google searches has found an answer for me. It seems a simple thing to do, but I cannot get Safari (5.1, Lion) to save a PDF that is loaded as the result of a script. The relevant portion of the script is this
tell application "Safari"
  save document 2 in file pdfDLNAME
end tell
In this example pdfDLNAME is a fully specified path, something like this:
Sarkany:Users:fenevad:Dropbox:Personal:Heenan_book:downloads:1776-07-18_New-York -Journal_page-3_4.pdf
Every time I try this it fails, regardless of whether the file exists or not. I get this error (allowing for changes in the variable value) in Safari:
The document “New-York, July 18” could not be saved as “1776-07-18_New-York-Journal_page-3_4.pdf”. The file doesn’t exist.
This result then causes problems for the AppleScript, which cannot procede as it should.
So the question I have is how simply to save a PDF loaded in Safari to a specified path location. I've seen some people suggest scripting the UI, but that is a pain when I have to determine the location for the download based on the script’s results.
Apologies if the answer is obvious to scripters, but it isn't obvious to me or to someone with more experience helping me.
Best regards,
Arle Lommel

arle lommel wrote:
That would probably be fine except that I need to save the file to a specified location based on other factors in the script and that location is not the same each time. I.e., saving to the desktop isn't really an option.
The previous script can easily be modified in order to do what you are asking for. Let's suppose for example that you want to save the PDF file to a folder named "Downloaded PDFs" in your Documents folder, under the name "A new PDF file.pdf":
set theFileName to "A new PDF file.pdf"
set theDestination to ((path to home folder) as text) & "Documents:Downloaded PDFs" as alias
tell application "Safari"
    activate
    tell application "System Events" to tell process "Safari"
        keystroke "s" using command down -- save as…
        delay 0.5
        keystroke theFileName
        delay 0.5
        keystroke "d" using command down -- save on desktop
        keystroke return -- save
        delay 0.5
        if sheet 1 of sheet 1 of window 1 exists then
            click button 1 of sheet 1 of sheet 1 of window 1 -- replace
        end if
    end tell
end tell
tell application "Finder" to move file theFileName of desktop to theDestination with replacing
Is there a reason why Safari can't use the save action?
Safari is only partially scriptable. It's not impossible that it can use the save action though. I just don't know how to do it.

Similar Messages

  • I'm trying to open a PDF from Safari with iBooks, but when I choose "Open with ..." in Safari, only Pages and Dropbox show as options.  I'm running iOS 7.1.2 and iBooks 3.2.  Thanks for any ideas!

    On my iPad, I'm trying to open a PDF from Safari with iBooks, but when I choose "Open with ..." in Safari, only Pages and Dropbox show as options.  I'm running iOS 7.1.2 and iBooks 3.2.  I have rebooted the iPad and that did not help, and reinstalled iBooks, which also changed nothing.  Thanks for any ideas!

    Yup, it was uploaded to our school Wiki as a PDF, and Pages did open it.  I was then able to move it to iBooks, but I'd rather avoid the extra steps.

  • When saving a PDF from a FrameMaker book, is it possible to set document filenames as bookmarks in the PDF?

    When saving a PDF from a FrameMaker book, is it possible to set document filenames as bookmarks in the PDF? Currently when I have a Framemaker book that I want to save as a PDF, I choose Save Book As and then choose PDF for the file format. A dialog box comes up in which I can choose the Bookmarks tab and choose which tagged content I want to be made into bookmarks in the PDF file. What if I would rather have the filename of a document rather than the chapter title be a bookmark in the PDF? Is that possible? Where would I choose that option? Thanks!

    There are two ways that you could do this. You can either use postscript text frames and enter the correct pdfmark entries to show the file name with the corresponding actions (i.e. where to go in the PDF) or you can use hidden text in FM and the "Filename (Short) " variable in a unique paratag to be picked up by FM's bookmark creation.
    To go the pdfmark route, see http://www.pdflib.com/fileadmin/pdflib/pdf/pdfmark_primer.pdf for details and also consult the Adobe Pdfmark Reference manual (http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/pdfmark_reference.pdf).
    The hidden text route would use FM's Color Views to specify a colour as Invisible. This will make the content visually disappear from the screen (and any output), but FM will still be able to read the contents of any text that is coloured with the Invisible colour(s).
    1. Pick or create a colour that you want to be invisible. [Magenta is usually a good bet and stands out visually].
    2. Set that colour to be invisible in View 1 and visible in View 6. [you can use the shortcut <esc> v 1 and <esc> v 6 to toggle between the views.]
    3. Create a paratag to use for the filename and set the font colour to use the invisible colour.
    3. In the title of each chapter file, drop an anchored frame that is set to be outside of the text frame [so it won't interfere with any other content].
    4. In that AFrame, insert a text frame and use the invisible paratag defined in step 3.
    5. Insert the Filename (Short) variable in that text frame.
    6. Repeat steps for all files to be included in the bookmarks.
    When creating the PDF bookmarks, select only the paratag used for the invisible colour.
    Don't forget to toggle the View to be invisible (i.e. <esc> v 1  - this also works at the book level for all files in the book).

  • Preview won't open PDFs from Safari

    If I try to open a PDF from Safari in Preview, the Preview icon just bounces in the dock. However, if I open a PDF that is already on my computer Preview opens with no issues.
    Also, I can't get PDFs to download from Safari.
    I checked settings and did a few searches but I found nothing. Have suggestions?

    With Safari open click on 'Help' at the top of the screen.
    Then click on installed plugins. Look for adobe or acrobat.
    It may be that with safari, it is not trying to use preview?
    Just a guess.

  • Pdf from safari won't open

    When I save as a pdf from Safari, I get a file that "Acrobat could not open because it is either not a supported file type or because the file has been damaged (for example, it was sent as an email attachment and wasn't correctly decoded).

    Back up all data before making any changes. Please take each of the following steps until the problem is resolved.
    Step 1
    If Adobe Reader or Acrobat is installed, and the problem is just that you can't print PDF's displayed in Safari, you may be able to print by moving the cursor to the the bottom edge of the page, somewhere near the middle. A black toolbar may appear under the cursor. Click the printer icon.
    Step 2
    There should be a setting in its preferences of the Adobe application such as Display PDF in Browser. I don't use those applications myself, so I can't be more precise. Deselect that setting, if it's selected.
    Step 3
    If you get a message such as ""Adobe Reader blocked for this website," then from the Safari menu bar, select
    Safari ▹ Preferences... ▹ Security
    and check the box marked
    Allow Plug-ins
    Then click
    Manage Website Settings...
    and make any required changes to the security settings for the Adobe PDF plugin.
    Step 4
    Triple-click anywhere in the line of text below on this page to select it, the copy the selected text to the Clipboard by pressing the key combination command-C:
    /Library/Internet Plug-ins
    In the Finder, select
    Go ▹ Go to Folder
    from the menu bar, or press the key combination shift-command-G. Paste into the text box that opens (command-V), then press return.
    From the folder that opens, move to the Trash any items that have "Adobe" or “PDF” in the name. You may be prompted for your login password. Then quit and relaunch Safari.
    Step 5
    The "Silverlight" web plugin distributed by Microsoft can interfere with PDF display in Safari, so you may need to remove it, if it's present. The same goes for a plugin called "iGetter," and perhaps others — I don't have a complete list. Don't remove Silverlight if you use the "Netflix" video-streaming service.
    Step 6
    Do as in Step 4 with this line:
    ~/Library/Internet Plug-ins
    If you don’t like the results of this procedure, restore the items from the backup you made before you started. Relaunch Safari.

  • After saving a pdf in safari and trying to open I get an error

    After saving a pdf in safari and trying to open I get this error: There was an error opening this document. Acrobat cannot open this file because a task is still active in Acrobat. Please return to Acrobat and end the task before opening this file.

    Remove Acrobat and use Preview instead of the Adobe disease

  • Trouble saving a pdf from In Design with Illustrator files linked.

    I have trouble saving a pdf from In Design. Most of the files i've linked are Illustrator files with size up to 70mb.
    I am getting out of memory message   The In Design file isn't that big - about 9mb.
    HELP!!!!!!

    It did not help to close and reopen it.
    Not sure what you mean with exporting in chunks but if you mean exporting page for page , so it didn't work either.
    I think that i'll try to reduce the size of Illustrator files , but I 'm not sure what will be the optimum size for that In Design won't crush again.
    Or maybe i should make the presentation in illustrator instead? It take some time to save pdf from illustrator when the original file is about 90mb, but still it works.

  • Printing to pdf from Safari 5.1.4, last 16 lines compressed leaving blank space at bottom of pg.  No prob. wD/ IE or Word. Running Win 7, Dell Laptop.

    When I print to “Adobe PDF” from Safari, the last several lines are compressed leaving blank space at the bottom of the page where the normal size lines would normally be. This does not occur when printing from Internet Explorer or MS Word.  I am running Windows 7 on a Dell Laptop.  Anyone know of a solution?

    When I print to “Adobe PDF” from Safari, the last several lines are compressed leaving blank space at the bottom of the page where the normal size lines would normally be. This does not occur when printing from Internet Explorer or MS Word.  I am running Windows 7 on a Dell Laptop.  Anyone know of a solution?

  • Printing pdf from Safari

    Now, when I try to print a pdf from Safari, the print window shows nothing to print, and subsequently, nothing prints. Does anyone know what's happening? It worked fine for years.

    Hi
    Don't rely on an HP updater to work. They don't quite understand a Mac mentality.
    You can find the latest HP driver for your printer here.
    Yes, a faulty printer driver will affect Safari's printing.
    After you install the driver, "repair permissions" using Disk Utility found in your Finder's Applications>Utilities folder.

  • Safari hijacked by Adobe Reader - cant open pdfs from Safari

    I would greatly appreciate any help cant seem to find this exact problem elsewhere.
    I have a Macpro (new tower) running  10.9.4
    A few days ago I received an email from a trusted friend which included a link. I followed the link which asked me to download Adobe Reader which i foolishly did. Since then when I try to open a PDF from Safari I get the following message "Before viewing PDF documents in this browser you must launch Adobe Reader and accept the End User Licence Agreement, then Quit and relaunch the browser"
    Please note I can still open PDFs from the Finder and other browser's (e.g. Opera) also allow me to download
    I went to the Adobe site and downloaded Reader but it wont let me complete the installation. I fear my Mac has been infected by a trojan etc and can't seem to find out how to get around this.
    So far I have tried
    1) went to /Library/Internet Plug-ins - but nothing there
    2) reinstall of Mavericks
    Any help appreciated. I suppose a clean reinstall would help but don't want to do that just yet

    Open a Finder Window.
    Click on the Go in the menu bar.
    Press on option on the keyboard, "Library" will appear. Click on that.
    In the new Finder Window that it opens up, or the one that you have opened already. It'll show that particular folder. In that folder is Internet Plug-ins.
    Check to see if Adobe is in there. If so, delete it and reboot.
    I honestly thought it was in the same folder that you tried, but I don't remember at the moment. So my instructions are just a shot in the dark.
    KOT

  • Can't Download a PDF from Safari

    I can't down load a PDf file from Safari on my home computer. I have figured out that If I change the location that the file is being saved to, and hold down the control key while clicking the link, and choose save PDF, I can do it, but why can't I just click the link and have it save to my desktop. I can also open internet explorer and simply click the link and it saves to the desktop.
    These 2 options are to complicated for my husband who is not as familiar with computers in general, and he wants to know what I did to make it not work!
    I thought it had something to do with the permissions, because for some reason they are all grayed out, but the permissions are grayed out on my computer at work too and I can save a file to the desktop there.
    Any ideas?

    nibashki,
    Are you logged in with an Admin account?
    Navigate to HD > Users > Your Home Folder > Library > Preferences.
    In that folder, click on com.apple.desktop.plist, to highlight.
    Depress the Command and i (eye, not el) keys, to Get Info.
    Click on the disclosure triangle for Ownership & Permissions.
    Does is say: You can Read & Write?
    Click on the disclosure triangle for Details.
    Is the Owner your account, with Access: Read & Write?
    Is the Padlock open or closed?
    ali b

  • When I save a pdf from Safari 7, the file is empty

    Before I upgraded to MAvericks and Safari 7 I used to be able to save pdfs to my desktop with no problem. However, when I save now, all I get is an icon. When I try to open it, I get the message that the file is empty, and sure enough when I go to info the size of the file is zero.
    As far as I can tell I am doing exactly the same as I was doing before upgrading.
    What is wrong? And idea how I can fix this?

    Better to save files to a designated folder in the Finder then the desktop.
    Desktop preferences may be corrupted.
    Open the Finder. From the Finder menu bar click Go > Go to Folder
    Type or copy paste the following:
    ~/Library/Preferences/com.apple.desktop.plist
    Click Go then move the com.apple.desktop.plist file to the Trash
    Try saving a PDF file.

  • Reset PDF bookmarks when saving as PDF from structured FM - Book 11.0 with fm components (*.book).

    Hi,
    I've read the forum discussions/solutions on setting PDF bookmarks, but I'm afraid the various solutions appear to only work if you are consistently working in .fm book files, not if your source files are in structured .fm format.
    For example, I have to constantly reset the bookmark settings in FrameMaker when I follow our PDF process of saving the structured FM files via the File -> Save Ditamap As -> Book 11.0 with fm components (*.book) route. I can set the bookmarks in the first file of the book, and/or set them using the Format -> Document -> PDF Setup menu options. But an hour later, if I discover I need to make a change in our source material (.ditamap/.xml) and create a new PDF again, I must make the same exact bookmark settings at the .fm level in this process (i.e. creating new .fm files from the .ditamap/xml files overwrites the previous .fm files, requiring bookmark setting, again).
    I think the only possible solution for a short-cut in this situation is to write a script to set those bookmarks each time we go from .xml to .fm. Does anyone see another way around this?
    Thanks!
    Diana

    Hi Diana...
    You're right that only FM binary files can store PDF setup information (in theory XML files could store this data, but that's not the way it's currently set up). In order to have this data available in files generated from XML, you'll need to set it up in the structure application template(s). You also need to make sure that all files in the book use the same tag names. The following topic was written for DITA-FMx users, but the concept should apply to regular FM-DITA as well ..
    http://docs.leximation.com/dita-fmx/2.0/?ditafmx_setuppdfbookmarks.html
    I hope that helps.
    …scott

  • Saving a PDF from a site

    Hello,
    When I save a PDF from the web and click "Save As", there is a line in the box that says "save to online account". There is no option to remove that (check box etc.).  Does this mean that my files are being saved somewhere online?  I do not want that at all (still refusing the Cloud )! 
    Thank you so much in advance for the help!

    You can save the file to local disc. You don't need use a online account.

  • Can't print pdf from safari

    Ive been having this issue forever
    When I need to print a PDF file, I cannot do so from Safari.  It just comes up blank pages.
    If I go to another browser like Chrome, I have no problems.
    Anyone know why or what I can do?
    It seems Safari causes so many problems in addition to this one that I seem to have to use other browsers more and more

    Also, the little printing window that usually pops up on the dock when you print something and then quits itself after printing doesn't quit itself anymore. I have to actually select it and quit it myself. It's very annoying.
    Try this thread:
    http://discussions.apple.com/message.jspa?messageID=5650720#5650720
    Hope this helps.

Maybe you are looking for

  • How do I reduce the file size of a pdf to email?

    I have a 260 MB pdf file generated from Photoshop 6.  I can't seem to reduce the size in Photoshop.  Is there anyway to reduce the pdf outside of Photoshop?  Thanks in advance for any help.

  • How insert Enterprise portal in Solution Manager

    Hi guys, Can anyone explane me how can I insert an enterprise portal in Solution Manager? I have execute this steps: - transaction smsy - landscape components -> Systems -> Create New System With Assistant - Choose SAP Enterprise portal After that I

  • Doesn't even turn on

    I woke up this morning to find that the light on my express would go from amber>green>flash green once>amber>black/blank. I still have my warranty on it but I was wondering if there is any way I can fix it... PLEASE HELP!   Mac OS X (10.4.7)   iBook

  • Custom cursor not applied to body

    I have the following code which I run `onload` on the body tag in a HTML/JavaScript application: var mcd = new window.runtime.flash.ui.MouseCursorData(); mcd.hotSpot = new air.Point(0,0); mcd.frameRate = 24; var loader = new air.Loader(); loader.cont

  • Is boot camp the answer to run scottrader streaming quotes?

    is boot camp the answer to run scottrader streaming quotes?