It is possible when using Tampermonkey or Violentmonkey (Firefox or Chrome). Those userscript managers have added a GM_download
method.
You can use it like this:
// ==UserScript==
// @name New Userscript
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match http*://*/*
// @grant GM_download
// ==/UserScript==
var arg = { url: "https://example.com/123456.jpg",
name: "CustomFileName.jpg"
};
GM_download(arg);