0

I have an AppleScript to open move a Safari webpage into Reader view and then to Save As a PDF.

I would like it to Save As the PDF with default filename, but always in the same specific location. I'm not sure how to do this.

Currently the AppleScript runs as:

tell application "System Events"
tell application process "Safari"
    set frontmost to true

    repeat until window 1 exists
    end repeat

    # Render page in Safari Reader
    keystroke "r" using {command down, shift down}

    delay 0.02

    -- Print; wait until the sheet is visible   
    click menu item "Print…" of menu 1 of menu bar item "File" of menu bar 1

    repeat until sheet 1 of window 1 exists
    end repeat

    set thePopUp to first pop up button of sheet 1 of window 1 whose description is "Presets"
    click thePopUp
    click menu item "Default Settings" of menu 1 of thePopUp --replace if desired with your preferred preset

    click menu button "PDF" of sheet 1 of window 1
    click menu item "Save as PDF…" of menu 1 of menu button "PDF" of sheet 1 of window 1 -- Save as PDF...
    tell application "Finder"
        set filesavepath to "/Users/Ariel/Google Drive/To print"
    end tell
end tell

The final bits of the AppleScript, from 'tell application finder' do not actually make the Page save in my desired location. Please could you help me to this. Thank you for any help.

1

Here's how you'd do this:

  1. Go into the finder, and drag whichever folder you want to use for this into the "Favorites" section in the sidebar (enable the sidebar in the view menu if it isn't showing).
  2. Run this script, but replace menu item "Xcode" of click menu item "Xcode" of menu 1 of pop up button "Where:" with the name of the folder you added to your favorites.

    tell application "System Events"
        tell application process "Safari"
            set frontmost to true
            tell menu bar 1
                click menu item "Show Reader" of menu "View" of menu bar item "View"
                click menu item "Save As…" of menu "File" of menu bar item "File"
            end tell
            tell window 1
                repeat until sheet 1 exists
                end repeat
                tell sheet 1
                    click pop up button "Where:"
                    repeat until menu 1 of pop up button "Where:" exists
                    end repeat
                    click menu item "Xcode" of menu 1 of pop up button "Where:"
                    click button "Save"
                end tell
            end tell
        end tell
    end tell
    

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .