Ubuntu: How to run a command automatically after completing download?



Question:

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.


Solution:1

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

filetodownload=file-to-download.ext  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 ]   do    for files in $(find . -maxdepth 1 -mmin -1 -type f)     do      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 ]       then  #     echo $testbefore       mkdir $(basename "$files")_      fi     sleep 5    done   done  


Solution:2

  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.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »