I need to create an automation to make a new folder named by my selected text and then make that folder the new default Safari downloads folder. This would be the default folder when I click on a download file link from a webpage until I run the script again for a new selection.

edit: this may seem trivial but I have to click a URL to download 5-8 .pdf files (I have to click on each file separately) per order for about 30 orders a day and I have to make a folder named by the the order number to put the files in. I have done a lot of research and I'm not sure if this is something that can be done with AppleScript or if it also requires Shell script and is something I will have to pay for to be developed. I did post a freelancer post hoping someone could code it but I'm looking for an easier solution from someone smart in these boards. thank you so much for any help or guidance.

  • 1
    It seems like a whole lot of trouble to go to, when you can simply change the download location from Prefs > General... & especially as you appear to have done no initial research & just want someone to write it for you.
    – Tetsujin
    Apr 6, 2016 at 6:57
  • @BeckyPiscitelli If you're downloading files 6 hours a day, maybe we/you could try automating that whole process instead of automating just the folder creation. Apr 6, 2016 at 16:13
  • @AndrewLarsson I would love to automate the whole process, theres so many more steps. I have to rename each file almost like a part number (44444_1F_PAPERCOLOR_SIZE_BLEED_QTY.PDF). I can't export the order information from the website in a way that includes or downloads the URLS in the output, but I have been trying to dig around the inspector to see what code could be extracted from the site. I feel like there must be a way to write a program or script that will pull the details from the order and download the files, rename and save them in a folder named after the order number (ex. 44444) Apr 6, 2016 at 18:14

1 Answer 1


Open Automator and create a new service:

  • Choose: Service receives selected text in Safari like in the screenshot below.

    Automator service

  • Then add an item Run AppleScript with the content:

    on run {input} -- create folder from text
        display dialog " —Create folder from chosen text—
    This AppleScript will create  a folder from text you specify."
        set destination to (choose folder with prompt "Where would you like to make the folder?")
        tell application "Safari"
            if (input exists) then
                set folderName to input
                -- of text of document 
            end if
        end tell
        tell application "Finder"
            make folder in destination with properties {name:folderName}
            --select folder "untitled folder" in the destination 
            --set the name of the selection to folderName 
        end tell
        tell application "Safari"
        end tell
    end run
  • Save the service as Create Folder from Text.

Then in Safari choose some text and right-click it -> Services -> Create Folder from Text.

If the destination folder already contains a folder with the same name the service fails without any further notice.

If you don't like the dialog "—Create folder from ..." add a # in front of it or remove the two lines.

If you replace:

        tell application "Safari"
        end tell


        tell application "Safari"
            set destination to (choose folder with prompt "Where would you like to save the new file(s)?")
        end tell

the Automator service will open the new folder and ask you to choose the new folder as new download folder. Simply hit Choose. If you then right-click the download link -> Download linked file as…, the file will be downloaded to the new folder.

The script may be improved further, because I didn't get it to work to set the new folder as new download destination automatically.

  • thank you so much for taking the time to write this! I will try it tonight and see how it works! I am sure it is better than my current process. many many thanks! Apr 6, 2016 at 18:19

You must log in to answer this question.

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