flameshot icon indicating copy to clipboard operation
flameshot copied to clipboard

Add flag to/not to overwrite file specified through `--path` when the file already exists

Open rodrigo-morales-1 opened this issue 1 year ago • 1 comments

Feature Description

Today, I wrote a Python script (for my own use) that run flameshot. A minimal working example is shown below.

$ cat /tmp/a.py
import subprocess
import tempfile

temporary_file = tempfile.NamedTemporaryFile(suffix = '.png')
print('Original temporary file name:', temporary_file.name)
process_flameshot = subprocess.run([
  'flameshot',
  'gui',
  '--path',
  temporary_file.name])

Note the _1.png below.

$ python3 /tmp/a.py
Original temporary file name: /tmp/tmprop6_kxq.png
flameshot: info: Capture saved as /tmp/tmprop6_kxq_1.png

As you can see above, I used the Python function tempfile.NamedTemporaryFile(suffix = '.png') to create a temporary file (that function creates the temporary file in the filesystem) and provided that path to the binary flameshot using the flag --path.flameshot appends the suffix _1 when the file already exists. As a previous user of scrot and maim (other screenshot utilities whose default behavior is to overwrite the file if it already exists), this was undesired because I want to use the specific name created by Python to avoid doing extra steps (e.g. removing the temporary file so that flameshot thinks that the file doesn't exist, so that it doesn't add the suffix _1 to the file name).

I believe there are two possible outcomes from this feature request:

  1. The default behavior is changed (i.e. flameshot now overwrites the path specified through --path) and the flag --no-overwrite-path is added. The downside of doing this is that we might break some scripts created by people who considered that the default behavior of flameshot is to add the prefix _1 if the file exists, those people could get the previous behavior by using --no-overwrite-path.
  2. The default behavior is not changed (i.e. flameshot adds the suffix _1 when the file exists) and the flag --overwrite-path is added. Users that want to overwrite the path specified through --path can use the flag --overwrite-path. The downside of doing this is that people that have got used to the default behavior of maim and scrot will need to find out that flameshot doesn't overwrite files and look for the extra flag --overwrite-path.

rodrigo-morales-1 avatar Oct 16 '24 23:10 rodrigo-morales-1

+1 for the --overwrite flag.

Use case: using codex, claude over ssh. There is no way to transfer clipboard images through ssh, but I can instruct the agent to load the picture from a well-known location. The current implementation (increasing _1, _2) makes this difficult... I have to wrap flameshot in a script.

I'd use it like this:

# flameshot gui --clipboard -p test.png 
flameshot: info: Capture saved as /home/user/shared/test.png
# flameshot gui --clipboard -p test.png 
flameshot: info: Capture saved as /home/user/shared/test_1.png

samodadela avatar Oct 23 '25 09:10 samodadela