Advertisement
Guest User

screenshot.sh

a guest
Apr 22nd, 2014
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.99 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. key="secret-api-key"
  4. ico="$HOME/Pictures/imgur.png"
  5. pre="scrn-"
  6. save="$HOME/screenshots/"
  7. #edit="gimp %img"
  8. connect="5"
  9. max="120"
  10. retry="1"
  11. #open="firefox %url"
  12. log="$HOME/.imgur-screenshot.log"
  13.  
  14.  
  15. if [ ! -z "$save" ]
  16.   then
  17.   cd "$save"
  18. fi
  19. #filename with date
  20. img="$pre`date +"%d.%m.%Y-%H:%M:%S.png"`"
  21. #echo "Please select area"
  22. # Yea.. don't ask me why, but it fixes a weird bug.
  23. # https://bbs.archlinux.org/viewtopic.php?pid=1246173#p1246173
  24.  
  25. sleep 0.1
  26.  
  27. if ! scrot "$img" #takes a screenshot with selection
  28.   then
  29.   echo "Error for image '$img'! Try increasing the sleep time. For more information visit https://github.com/JonApps/imgur-screenshot#troubleshooting" >> "$log"
  30.   echo "Something went wrong."
  31.  # notify-send -a ImgurScreenshot -u critical -c "im.error" -i "$ico" -t 500 "Something went wrong :(" "Information logged to $log"
  32.   exit 1
  33. fi
  34.  
  35. if [ ! -z "$edit" ]
  36.   then
  37.   edit=${edit/%img/$img}
  38.   echo "Opening editor '$edit'"
  39.   $edit
  40. fi
  41.  
  42. echo "Uploading $img"
  43. response=`curl --connect-timeout "$connect" -m "$max" --retry "$retry" -s -F "image=@$img" -F "key=$key" https://imgur.com/api/upload.xml`
  44. echo "Server reponse received"
  45. #echo "$response" #debug
  46. if [[ "$response" == *"stat=\"ok\""*  ]]
  47.   then
  48.   url=`echo "$response" | egrep -o "<original_image>(.)*</original_image>" | egrep -o "http://i.imgur.com/[^<]*"`
  49.   echo "$url"
  50.   echo "$url" | xclip -selection c
  51.   if [ ! -z "$open" ]
  52.     then
  53.     open=${open/\%img/$img}
  54.     open=${open/\%url/$url}
  55.     echo "Opening '$open'"
  56.     $open
  57.   fi
  58. #  notify-send -a ImgurScreenshot -u low -c "transfer.complete" -i "$ico" -t 500 'Imgur: Upload done!' "`printf "$url\ncopied to clipboard\041"`"
  59. else
  60.   url="error - couldn't get image url"
  61.   echo "Upload failed, Server response:" >> "$url"
  62.   echo "$response" >> "$log"
  63. #  notify-send -a ImgurScreenshot -u critical -c "transfer.error" -i "$ico" -t 500 "Imgur: Upload failed :(" "Information logged to $log"
  64. fi
  65. echo -e "$url\t\t$save$img" >> "$log"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement