Save images to hard disk WITHOUT prompt?
Asked Answered
K

6

10

I use twitter. Some people's tweets contain photos and I want to save them.

I checked ifttt, where twitter is not a trigger. Thus, ifttt cannot help me do it.

One idea is probably to use JavaScript. I use Firefox and installed Greasemonkey. I can write a Greasemonkey script (JavaScript) running on twitter website. Once I click "retweet" link or other button added by my script, my script examines the content of the tweet, find the URL of the photo, and save it to my disk.

One problem is how to save the image. I searched the Internet. Some use win.document.execCommand("SaveAs"), and it will show a "save as" window. Now that the window shows, why not just right click the image and choose save as manually? So I don't like the method.

Any suggestions?

Kinetic answered 29/11, 2012 at 13:30 Comment(0)
I
7

Greasemonkey cannot do this, because ordinary javascript is forbidden to do this (for security reasons), and the Greasemonkey API does not expose a method to write files (and never will).

Here are four alternatives:

  1. Update: Switch to Tampermonkey, which you should do anyway. Then you can use GM_download as user136036 said in his answer.

    or

  2. Install and use the excellent DownThemAll add-on (Update: Firefox 57 withdrew support for this kind of extension). It still requires one click, but that's better than always grabbing a file willy nilly, in most cases anyway.

    or

  3. Write your own addon extension. See this (now obsolete) answer for file-writing code from one of the top gurus of FF add-ons. But "new" style extensions can still do this.

    or

  4. Use XAMPP (or similar) to run a web server on your machine. You will then have to write a web application that excepts incoming image data (or just the image URL) and saves the image to disk.

Infatuate answered 29/11, 2012 at 14:26 Comment(3)
Pity that GM seems not to have implemented GM_download. It works with TM for Firefox though.Thirtieth
@brasofilo, not just not implemented. That issue is tagged Bankruptcy, which means that the controller of Greasemonkey has decided to never support that feature. Greasemonkey 4+ is an abomination and a travesty.Infatuate
Ahaaa... suggestive tag name btw, lolz. Donnow abut the inner workings but interface wise GM is years behind...Thirtieth
F
13

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);

See the official Tampermonkey documentation.

Faradmeter answered 19/4, 2016 at 13:11 Comment(2)
It looks like promising as long as GM_download works as expected. I will try later, thanks.Kinetic
what is the folder location of CustomFileName.jpgHumming
I
7

Greasemonkey cannot do this, because ordinary javascript is forbidden to do this (for security reasons), and the Greasemonkey API does not expose a method to write files (and never will).

Here are four alternatives:

  1. Update: Switch to Tampermonkey, which you should do anyway. Then you can use GM_download as user136036 said in his answer.

    or

  2. Install and use the excellent DownThemAll add-on (Update: Firefox 57 withdrew support for this kind of extension). It still requires one click, but that's better than always grabbing a file willy nilly, in most cases anyway.

    or

  3. Write your own addon extension. See this (now obsolete) answer for file-writing code from one of the top gurus of FF add-ons. But "new" style extensions can still do this.

    or

  4. Use XAMPP (or similar) to run a web server on your machine. You will then have to write a web application that excepts incoming image data (or just the image URL) and saves the image to disk.

Infatuate answered 29/11, 2012 at 14:26 Comment(3)
Pity that GM seems not to have implemented GM_download. It works with TM for Firefox though.Thirtieth
@brasofilo, not just not implemented. That issue is tagged Bankruptcy, which means that the controller of Greasemonkey has decided to never support that feature. Greasemonkey 4+ is an abomination and a travesty.Infatuate
Ahaaa... suggestive tag name btw, lolz. Donnow abut the inner workings but interface wise GM is years behind...Thirtieth
M
1

You won't be able to do this in the way that you would like. If browsers allowed websites to save whatever content they wanted directly to the user's computer... well you can imagine the consequences.

Marcello answered 29/11, 2012 at 13:33 Comment(0)
D
1

JavaScript does not have access to the computer's file system.

There is no native JS functionality for this. Otherwise any site would be able to save anything to your PC, which would result in your PC getting messed up in no time.

Dragster answered 29/11, 2012 at 13:33 Comment(4)
So..should I write a firefox plugin to do the job? It seems that the work becomes bigger and bigger...Kinetic
That would be a option, yes.Dragster
@BrockAdams: Not necessarily. There are some add-ons that can automatically save files to disk.Dragster
You're right, that's why I prefaced that comment with "IIRC".Infatuate
E
0

Plugin is the right answer for this. If you are looking for a framework checkout Firebreath it gives you cross platform capability as well as works on all possible browser you can ever think of, including IE. Its easy to learn too

Ellisellison answered 29/11, 2012 at 14:15 Comment(0)
E
0

You can do this easily in Firefox by selecting an option to Save this automatically from now onwards instead of prompting. I guess this option should be available in Chrome too.

First time when you download a file of new extension say Zip or jpg, the browser may prompt you the location where to save this file. In this case, you can set the location to a default location wherever you want to download the files and set the checkbox to Automatically Download such files.

Ellmyer answered 1/12, 2012 at 10:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.