# Automation

Downie can be used in various automated workflows as well. This help topic will cover this.

## Automated Mode

From time to time, Downie needs to show you some kind of a prompt (login dialog, subtitle selection, etc.). If you are away from the machine, this can be unwanted as it blocks the UI and processing of the links in the background. For this, there is the “automated mode” which can be enabled in `Preferences > Advanced`. When run in automated mode, Downie will suppress all dialogs. Please keep in mind that this has its risks - e.g. if Downie requires you to login, it will cancel the attempt automatically and the download will fail.

## Opening Links in Downie

The main question now is how to open a link in Downie. There are several options.

### Open a link with no options

If you just need to open a link in Downie, then it’s simple - if you are using a shell (command line), use the `open` command:

`open -a 'Downie 4' 'https://www.example.com/'`

Several notes:

- if you are running a Setapp version, use `Downie` instead of `Downie 4`
- `&` is a shell operator. Make sure that the link is surrounded by single or double quotes.

If you are using Apple Script, use the `open` command:

    tell application "Downie 4"
    	open location "https://www.example.com/"
    end tell

In Automator, you can use the `Open URLs in Downie` Automator action.

### Open a link with options

Sometimes, you want some links to be opened with particular postprocessing, or even in the User-Guided Extraction. For this, Downie uses a custom scheme `downie://`. Here is an example:

`downie://XUOpenURL?url=https://www.example.com/&postprocessing=audio`

Let’s break this down. The first part `downie://XUOpenURL` is fixed. After that, there is the query separator (`?`) and regular URL query parameters. In URLs, query parameters are separated by `&` and are in format `name=value`. In this case, there are two parameters - `url` (whose value is `https://www.example.com/`) and `postprocessing` whose value is `audio`.

There are several supported parameters:

- `url` - required - this is fairly obvious. This is the actual link you want to open. Please make sure that the link is URL-encoded. This mainly means that all `&` characters within the link must be encoded. Example: if the link is `https://www.youtube.com/watch?v=eSc2gwNrc8M&ab_channel=VisualGolf` - you can notice that the link itself contains `?` and `&`. If you pasted the link into the Downie custom link just as-is, you’d get:
  - ❌ `downie://XUOpenURL?url=https://www.youtube.com/watch?v=eSc2gwNrc8M&ab_channel=VisualGolf&postprocessing=audio` - which is wrong as it will be interpreted incorrectly - the `ab_channel` parameter will not be interpreted as part of the `url`, it will be interpreted as an additional argument of the Downie custom link. The correct link would be:
  - ✅ `downie://XUOpenURL?url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DeSc2gwNrc8M%26ab_channel%3DVisualGolf&postprocessing=audio` - this is the ideal representation, though the minimum you need to really encode is the `?` and `&` characters - this will also be accepted: `downie://XUOpenURL?url=https://www.youtube.com/watch%3Fv=eSc2gwNrc8M%26ab_channel=VisualGolf&postprocessing=audio`. To make it super easy for you, make sure that you replace `?` with `%3F` and `&` with `%26`.
- `postprocessing` - optional - set a certain postprocessing. Allowed values are:
  - `mp4` - MP4 postprocessing
  - `audio` - extract audio only
  - `permute` - send to Permute
- `destination` - optional - path to destination folder. Make sure that the folder exists.
- `action` - optional - perform certain action. Currently there’s only one action.
  - `open_in_uge` - opens the link in the User-Guided Extraction. Ignores the `postprocessing` argument.

Once you have this custom link, the workflow is the same - either use the `open -a 'Downie 4' 'downie://...'` shell command or use the same with Apple Script.