Web Category Shortcuts

The Shortcuts app has a number of actions that come under the Web category, and I thought I would include a few simple examples. There are two basic actions that can be used to get the URL of a web page–one is to specify the URL, and the other is to get the URL of the current web page from Safari. I’ve used the former in my examples.

The first shortcut gets the URLs of all links from the specified web page. It sorts the URLs alphabetically and removes duplicates. This shortcut returns text, which is easily converted to a list with the Split Text action.

It should be noted that if the last two URLs are duplicates, both are returned. This can be fixed by adding a linefeed to the end of the text after the Combine Text action or possibly by revising the regex.

Get Links.shortcut (22.6 KB)

The next shortcut is similar to the above, except that it returns the URLs of links to PDF documents only. The Filter action can be revised to return links to whatever is desired.

Get PDF Documents.shortcut (22.8 KB)

The third shortcut returns the component parts of URLs, which are structured as follows:

scheme://user:password@host:port/path?query#fragment

URL Components.shortcut (22.6 KB)

Other Web actions are relatively simple to implement and follow the patterns shown above. Examples are:

  • add URL to reading list;
  • show web view of URL;
  • get headers of URL;
  • get items from RSS feed;
  • and so on…

I wrote the following shortcut for learning purposes. It does the following:

  • gets the links to every PDF on the web page specified in the second action of the shortcut;

  • prompts the user to select one of the PDFs; and

  • saves the selected PDF to the folder set by the user in the first action of the shortcut.

A few comments:

  • I was unable to sort the PDF file names shown in the chose-from-list dialog.

  • The shortcut uses a dictionary with the file name of the PDF as a key and the corresponding URL as the value. If multiple PDFs have the same name, only one will be shown in the dialog.

Save PDF.shortcut (23.6 KB)

The shortcut included below downloads all files of a particular type (currently PDF) from one or multiple web pages. A few comments:

  • The target web page or pages are specified in the URL action.

  • A Get current web page from Safari action can be used instead of the URL action.

  • Getting and filtering data from web pages can take some time. With the currently specified web page, the shortcut takes about 4 seconds to run (without the dialog) on my 2023 Mac mini with a fast internet connection.

  • I’ve successfully tested the shortcut with five web pages, but it may not work with some web pages.

  • Before running the shortcut for the first time, the File action needs to be set to the desired download folder.

  • The following screenshot only shows a portion of the shortcut.

Save PDFs.shortcut (23.7 KB)