Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8890585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:32:10+00:00 2026-06-14T22:32:10+00:00

I am trying to make a script that opens an swf file with safari

  • 0

I am trying to make a script that opens an swf file with safari and then print it as a pdf using the built in “Save as PDF” feature. So far my code looks like this:

set appleworksFolder to choose folder

tell application "Finder"
set folderItems to (files of entire contents of appleworksFolder)
repeat with I from 1 to number of items in folderItems
    set the_doc to item I of folderItems
    set doc_name to name of the_doc as text
    tell application "Finder"
        set the clipboard to doc_name & ".pdf"
    end tell
    if name of the_doc is not ".DS_Store" then
        try
            tell application "Safari"
            activate
                open the_doc
                tell application "System Events"
                    tell application process "Safari"
                        delay 1
                        click menu item "Print…" of menu "File" of menu bar 1
                        delay 5
                        click menu button "PDF" of window "Print" of application process "Safari" of application "System Events"
                        delay 1
                        click menu item "Save as PDF…" of menu "PDF" of menu button "PDF" of window "Print" of application process "Safari" of application "System Events"
                        delay 1
                        keystroke "v" using command down
                        click button "Save" of window "Save" of application process "Safari" of application "System Events"
                        delay 8
                        keystroke "w" using command down
                        delay 0.5
                    end tell
                end tell
            end tell
        end try
    end if
end repeat
end tell

This works up to seeing the print dialogue, but it doesn’t seem to click the pdf menu button so doesn’t get any further than this. I was wondering if this is a problem with mountain lion not letting me use applescript to control buttons, and if so, is there a fix for it? Any help would be greatly appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T22:32:11+00:00Added an answer on June 14, 2026 at 10:32 pm

    I just showed someone how to do this in Mail on another website. You can see that in post #7 here. Anyway, here’s that code adjusted for your particulars and Safari. I hope it helps!

    set appleworksFolder to choose folder
    
    tell application "Finder"
        set folderItems to (files of entire contents of appleworksFolder) as alias list
    end tell
    
    repeat with i from 1 to count of folderItems
        set thisItem to (item i of folderItems) as text
    
        tell application "Finder"
            set n to name of file thisItem
            set c to (container of file thisItem) as text
        end tell
    
        tell application "Safari"
            activate
            open file thisItem
        end tell
    
        saveAsPDFInSafari(c, n, true)
    end repeat
    
    tell me
        activate
        display dialog "Finished!" buttons {"OK"} default button 1 with icon note
    end tell
    
    (*********** SUBROUTINES *************)
    on saveAsPDFInSafari(saveFolder, saveFileName, shouldCloseWhenFinished)
        set myDelay to 0.2
    
        -- setup the name
        if saveFileName does not end with ".pdf" then
            if character -4 of saveFileName is "." then
                set saveFileName to text 1 thru -5 of saveFileName
            end if
            set saveFileName to saveFileName & ".pdf"
        end if
    
        -- setup the folder
        set saveFolder to saveFolder as text
        set posixSaveFolder to POSIX path of saveFolder
        if posixSaveFolder ends with "/" then set posixSaveFolder to text 1 thru -2 of posixSaveFolder
    
        -- save as pdf
        tell application "Safari" to activate
        tell application "System Events"
            tell process "Safari"
                keystroke "p" using command down
                repeat until exists sheet 1 of window 1
                    delay myDelay
                end repeat
    
                tell sheet 1 of window 1
                    click menu button "PDF"
                    repeat until exists menu 1 of menu button "PDF"
                        delay myDelay
                    end repeat
    
                    click menu item "Save as PDF…" of menu 1 of menu button "PDF"
    
                end tell
    
                repeat until exists (sheet 1 of sheet 1 of window 1)
                    delay myDelay
                end repeat
    
                keystroke saveFileName
                delay myDelay
    
                keystroke "g" using {command down, shift down}
                repeat until exists sheet 1 of sheet 1 of sheet 1 of window 1
                    delay myDelay
                end repeat
    
                tell sheet 1 of sheet 1 of sheet 1 of window 1
                    set value of text field 1 to posixSaveFolder
                    delay myDelay
                    click button "Go"
                end tell
    
                repeat while exists sheet 1 of sheet 1 of sheet 1 of window 1
                    delay myDelay
                end repeat
    
                tell sheet 1 of sheet 1 of window 1
                    click button "Save"
                end tell
    
                repeat while exists sheet 1 of sheet 1 of window 1
                    delay myDelay
                end repeat
    
                repeat while exists sheet 1 of window 1
                    delay myDelay
                end repeat
    
                if shouldCloseWhenFinished then
                    keystroke "w" using command down
                end if
            end tell
        end tell
    end saveAsPDFInSafari
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a script that write text in a file and then
I'm trying to make a script that will generate a .WPL file. The script
I am trying to make dropdown enabling using jquery and click search then that
[edited] I am trying to make a script that downloads a file, the problem
I'm trying to make a script that will prompt the user and wait for
I'm trying to make a script that automatically starts uploading after the data has
I'm trying to make a script that will go into a directory and run
hello everyone I am trying to make a script that steps through a list
I'm trying to make a PHP script that will take a potentially infinite number
I'm trying to make a PHP script that will check the HTTP status of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.