Quantcast
Channel: Planet Ubuntu
Viewing all articles
Browse latest Browse all 17727

Stuart Langridge: Downloading all the files in an Ubuntu One folder

$
0
0

Ubuntu One syncs your files and folders. However, sometimes you don't, or can't, sync your files; you're using the web UI on someone else's computer, you're on a machine we don't support, that sort of thing. You can always use the web interface, of course, but as yet the web UI doesn't support downloading a whole folder in one go, and that can be a pain if you want to download many files at once. To alleviate that for myself, I have a quick bookmarklet. As usual, just right-click the link and "Add to bookmarks" (or however you normally do that), and then when you're looking at a folder in the Ubuntu One web UI, you can click the bookmark and it'll download all the files in that folder.

First, the caveats: it only works in Chrome (and only recent Chrome, at that; sorry; if you care why, see the explanation below), and it will download all the files in this folder to your Downloads folder (that is: it will not create a new folder and download them into that).

Second, the bookmarklet itself:

Download U1 folder

Third, a brief explanation, for those of you who are technical people who want it and can't decipher the code:

  • First, we look for a[download] support (currently only in Chrome), which allows an ordinary HTML link to specify that when clicked its destination should be downloaded (with a specific name) rather than opened.
  • Then we grab all the links to files on the page you're looking at; we assume this is an Ubuntu One page, so we look for links with querySelectorAll('.files-td-name a').
  • That's a NodeList, not an array, which means we can't use forEach on it; we convert it to an array with Array.prototype.slice.call(nodelist), which is a trick I use a lot (can't remember who I first learned this from, but it's neat)
  • and for each of the links, construct a new link, set the new link's href to the existing link's href and its download attribute to the filename, and then fake a mouse click on the new link with event.initMouseEvent. (We construct a new link because the existing links in the page have onclick handlers, which we don't want to fire.)
  • ta daah, the link downloads without further prompting, to your Downloads folder (because that's where Chrome puts it).

Viewing all articles
Browse latest Browse all 17727

Trending Articles