1

I need to have Safari visit a specific URL, and "Save As... page source" to a specified location in my Home folder. I don't want to actually see Safari while this is going on - unless that's unavoidable. I understand this is do-able using AppleScript, but I have zero experience with that. I tried using the Automator app to generate something, but I’m stuck at the first step.

Can someone show me how this is done?

4
  • How do you get the 'specific url'?
    – Mockman
    Commented Feb 24 at 0:19
  • @Mockman: For the purposes of this Q, it can be any URL. You can use this one if you like.
    – Seamus
    Commented Feb 24 at 0:24
  • If you plan on using this regularly, how will you feed that url to the script/app/service? Will it be on the clipboard? Will it be selected text in a file? I'll assume that it's on the clipboard.
    – Mockman
    Commented Feb 24 at 0:28
  • @Mockman It will always be the same URL.
    – Seamus
    Commented Feb 24 at 0:29

2 Answers 2

1

Create an automator document. While testing, make it a workflow. Once you've got it working the way you like, you can make an application or whatever is most useful.

Add two actions, both from the Internet category:

  1. Get specified URLs
  2. Download URLs

With the first action, click the expand triangle and if there is a default URL in there, select it and click Remove and then Add your specific URL.

With the second action, click the Where dropdown and choose a destination. Click 'other' to choose an arbitrary location. It might be worthwhile to have an exclusive folder specified as then you could easily run other actions on the 'contents' of the folder (see below).

Then click 'Run' to test the workflow. It should download the html for the page (but not all of the ancillary files) and save it in the specified location. If it already exists, it will save an additional copy.

This is probably the easiest method to download a web page and doesn't require that Safari actually open the page. You could also use applescript or you could use a command-line tool like wget or curl and run it from the terminal.

Update:

To make this into an app rather than a workflow, it's probably easiest to simply create a new app and then add the actions the same way that the workflow was created. Unfortunately, the file > convert to… menu command doesn't seem very effective.

As to renaming the resulting file, unfortunately the download urls action doesn't seem to work as it might as it does not provide a result (ie a reference to the saved html).

You can add a workaround though. Here is one that uses the saved file (so you have to download the file so you can then 'choose' it) and then renames that — note that you can then remove/trash that initial file as you only need it long enough to add the entry to the action. I use the 'add date or time' option in the 'rename finder items' action because it doesn't require user interaction but you can go through the various options and choose the best for your need.

  1. Get specified finder items
    This uses add to specify the file so you must have a file in the download location with the correct name and then choose it (eg 'text-mode-web-browsers.html'). This is the name that the two-step download would generate based on your supplied url. Run it again with the actual url to get the correct file name for that url. Note, you don't need the actual file, just the actual file name, so you could also just stick a random text file there and give it the same name and then trash it.

  2. Rename finder items: add date or time
    You can choose your renaming options for this action but the date/time one is easy to work with. Note that some rename options seem to function only in a workflow.

4
  • 1
    Haha... I know all about wget & curl... believe me, if I could use them - I would. They are both blocked by this website.
    – Seamus
    Commented Feb 24 at 0:50
  • Hey - very good - it works! Can you embellish it a little bit to save it as a different filename... by that I mean I'd like to set the filename to save as. And I don't want an additional copy created, but overwriting is OK.
    – Seamus
    Commented Feb 24 at 1:14
  • "Once you've got it working the way you like, you can make an application or whatever is most useful." I'm going to run it autonomously via cron or as a "UserAgent" under LaunchControl, so maybe I should make it an app?? How do I do that?
    – Seamus
    Commented Feb 24 at 1:30
  • The easiest way would be to just start with a new application. Add the two actions. You will find that the app defaults to application receives files and folders as input, which you don't want. Right-click on the first action and select ignore input. You will probably have to run the app at least once to let the OS know that it's legitimate. There may be some other security measures depending upon your OS version.
    – Mockman
    Commented Feb 24 at 3:18
1

This post is to augment the accepted answer fm @Mockman:

  1. Following the accepted answer's advice using Automator led to the successful creation of a workflow file. In my case, I saved this as getwebpage.workflow (catchy name, eh?).

  2. I could run my getwebpage.workflow from Automator, but that was not what I expected for Automation... what do I do with a workflow file? ... how do I run it as a "stand-alone" ... is this even possible?

    Stumbling blindly through the wasteland known as Apple's Documentation led nowhere (as usual), but I did find something in a search that proved to be The Answer:

    As it turns out, there is a command line app also named automator!! And it has a man page (wonders never cease):

    NAME  
      automator – Runs Automator workflow   
    
    SYNOPSIS  
      automator [-v] [-i input] [-D name=value ...] workflow  
    
    DESCRIPTION  
      automator runs the specified workflow.  To create or edit a workflow, use the Automator application.
    
      The following options are available:
    
      -D name=value
               Set variable name to value for this run of workflow.
    
      -i input
               Set input as the input to workflow.  If input is - then the contents of standard input is used.  Each newline (\n)-terminated line is treated as one
               text input item.
    
      -v       Run in verbose mode.
    
    Mac OS X                                                                    April 1, 2007                                                                    Mac OS X   
    

Armed with this information, I was able to create a small bash script around automator, and create a "Global Daemon" in LaunchControl to run it on a schedule.

Afterword:

My incredulity and sarcasm here mask my appreciation at finding a solution; this solution filled a real need for me. But I cannot help but wonder: Why does Apple develop a solution like Automator, let it languish for 17 years, but leave it in the distribution with only the scantest of documentation? The same question could be asked re Apple's AutoFS.
Yes, these are rhetorical questions.

P.S.

As it turns out, there is some documentation on the Automator.
It goes well with this tasty crow.

You must log in to answer this question.

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