I need a way that helps me to run a command automatically after a download completes.

I want to create a directory beside the downloaded file automatically after I clicked on the integrated download button from Firefox. I want all of those to be automatic.

  • I think this hasn't got much to do with Ubutnu. Just search for a addon which executes a command after completing a download. – Marton Jun 27 '15 at 21:32
  • What would be the purpose of the newly created directory and what would the command exactly need to do? – Jacob Vlijm Jun 28 '15 at 17:17
  • that was just an example to explain my problem. actually I want to learn "the way" to run any command after download completed, not only such a thing like creating a directory! – Snowleaf Jun 28 '15 at 23:26
  • wget has that option... – You'reAGitForNotUsingGit Aug 2 '16 at 16:00

If you can download the file outside of Firefox, you can use

wget http://www.example.org/"$filetodownload" -O "$filetodownload"
#"I want to create a directory beside the downloaded file automatically"
#You didn't specify a dir name
mkdir "$filetodownload"

Otherwise, you'll have to monitor the file's download progress and when it's finished, make the directory "beside the downloaded file". The following worked for me (but I couldn't make a dir with the same name as the file). It looks at all files though, including hidden ones. Modify as needed.

#! /bin/bash
while [ 1 ]
  for files in $(find . -maxdepth 1 -mmin -1 -type f)
    testbefore=$(ls -l $files | awk '{print $5$6$7$8$9}')
    sleep 2
    testafter=$(ls -l $files | awk '{print $5$6$7$8$9}')
    if [ $testbefore = $testafter ]
#     echo $testbefore
     mkdir $(basename "$files")_
   sleep 5
| improve this answer | |
  • I don't understand the first line of the first method! what is it? – Snowleaf Jun 27 '15 at 23:43
  • That's a variable. When you assign a value to a variable, you can just do var=value. When you want to use it later in the script or command-line session, you prefix it with a '$'. If you paste that into Notepad++ and set the "Language" to "Shell", it will colorize the keywords. It makes it easier to see what's what. – user38537 Jun 28 '15 at 0:10
  1. Add mime type to neverAsk.openFile in about:config (you can add */* for all)
  2. Create an executable script that:
    • takes the file path from the arguments list (the first argument)
    • moves it to target location (as it has been downloaded to tmp)
    • runs whatever commands you want
  3. Tell Firefox to open this file type with your script

This last one is easy to do in about:preferences but little harder if you want to manually add records to mimeTypes.rdf file in Firefox's profile.

| improve this answer | |
  • It doesn't work any more. I checked on Firefox 41.0.2, 44.0 and 47.0. It seems like a bug in Firefox. The checkbox "do this automatically for files like that from now on" works for Save File but does not work for Open with download dialog option any more. – cprn Aug 4 '16 at 11:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.