New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Run script on save #357

Open
ronjouch opened this Issue Sep 26, 2018 · 6 comments

Comments

Projects
None yet
4 participants
@ronjouch
Copy link

ronjouch commented Sep 26, 2018

I like to pass my screenshots through pngquant, for excellent lossy-but-I-don't-care-for-screenshots compression.

I do this manually each time, but it would be great if Flameshot had a Run script on save option.

  • It would require configuration of a path to a script/binary.
  • After screenshot save, if configured and if the path provided exists and is executable, the script/binary would be called with the full path passed as argument.
@lupoDharkael

This comment has been minimized.

Copy link
Owner

lupoDharkael commented Sep 26, 2018

You can use the command line interface of flameshot to do that. Here is an example:
flameshot gui -r > myfile.png && do stuff with myfile.png

@ronjouch

This comment has been minimized.

Copy link

ronjouch commented Sep 26, 2018

@lupoDharkael thanks for the fast feedback 🙂.

I wanted to like flameshot gui -r, but it's annoying as it results in two pngs being written 😕: the one produced by the redirect, and the default one named after the naming configuration. If passing flag -r I'd expect the GTK "save as" dialog to not popup.

@lupoDharkael

This comment has been minimized.

Copy link
Owner

lupoDharkael commented Sep 26, 2018

You are right, I guess it would be a good idea to have optional scripts called after the capture is done (and passing the path of the image to the script as an argument)

@drm86

This comment has been minimized.

Copy link

drm86 commented Oct 9, 2018

This could be a nice feature, for now I have to use a crappy shell script to do things like upload the result screenshot to other service different than imgur (like ptpb.pw). This is what I'm using now and this script is binded to Print Screen key:

#!/bin/bash

PATH_IMG=/tmp/$RANDOM$RANDOM$RANDOM

mkdir $PATH_IMG &&

RESULT_CAP=$(flameshot gui -p $PATH_IMG -r > $PATH_IMG/img.png && head -n 1 $PATH_IMG/img.png)

if [[ $RESULT_CAP != "screenshot aborted" ]] ; then
    
    RESULT_CURL=$(curl -F c=@$PATH_IMG/img.png https://ptpb.pw/?u=1)
    echo $RESULT_CURL | xclip -i -rmlastnl -selection clipboard
    notify-send "Captura subida a: "$RESULT_CURL "El enlace copiado en el portapapeles" -u normal -t 7500 -i clipboard
fi

rm -rf $PATH_IMG;

Other problem with scripting is there's no Exit Codes present in this application, so the only way I can manage is reading the first line of the raw output file.

Thanks.

@chelobaka

This comment has been minimized.

Copy link

chelobaka commented Oct 10, 2018

I'm looking for a program to replace outdated and broken Shutter, and Flameshot could be my choice if it could pass a screenshot to a custom script. (I need to upload images over WebDAV and copy URLs to clipboard.)

UI part of this feature could be done like this:

  1. In the settings user adds a script, gives it a name. Several scripts can be added.
  2. In screenshot window for each user script extra button is created with script name shown, when cursor is over the button.
@ronjouch

This comment has been minimized.

Copy link

ronjouch commented Oct 10, 2018

I gave up on Flameshot and other do-it-all screenshot tools. No harsh feelings on Flameshot at all, at the end of the day I think it's just too much to ask to a single free niche Linux app. I prefer to delegate [screenshot, edition, automation] to dedicated tools, tied together by a customizable script. Here's my current script that:

  1. Makes a screenshot, using the minimal gnome-screenshot (but replace with whatever you like).
  2. Optionally passes it to Inkscape for powerful editing.
  3. Runs pngquant on it.
  4. Saves for archival in a dedicated folder.
#!/usr/bin/env sh

date=$(date +%Y-%m-%d-%H:%M:%S)
filename="screenshot_$date.png"
file_orig="/tmp/${filename}"

gnome-screenshot --area --file="$file_orig"
# or install & use maim, it's better as the pointer and delay options
# are not exclusive, so you can have the cursor in the screenshot
# maim --delay=1 --select "$file_orig"
if [ ! -f "$file_orig" ]; then exit 1; fi

title="$(zenity --entry --title='Screenshot' --text='Optionally name the screenshot (start with "i " to edit in Inkscape):' --ok-label='Save screenshot')"
if [ $? -ne 0 ]; then exit 1; fi

if [ "${title#i }" != "${title}" ]; then
  inkscape "$file_orig"
  title="${title#i }"
fi

folder="$(xdg-user-dir 'PICTURES')/Screenshots"
if [ ! -d "folder" ]; then
  mkdir -p "$folder"
fi

if command -v pngquant > /dev/null; then
  if [ -n "$title" ]; then
    middle="_${title}_"
  else
    middle="_"
  fi

  file="${folder}/screenshot${middle}${date}.png"
  pngquant --strip --force --output "$file" "$file_orig"
  # zopfli too slow, disabled but enable it if you want to shave even more bits from your PNGs
  # if command -v zopflipng > /dev/null; then zopflipng -y "$file" "$file"; fi
else
  zenity --warning --text='Please install pngquant'
fi
rm "$file_orig"

nautilus "$folder"

I bind this to PrtScr using GNOME Shell's native keybinding mechanism. ❤ ensues. Improvements welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment