You are not logged in.
I use nautilus every time i wanna paste image from clipboard as a file I realised I could maybe use thunar custom action, but idk how to
I want something like "Paste Clipboard Image" and ideally it should prompt me for name but it's fine if it uses current date/time or smthn like that
please help me..
jumpieee
Offline
How about a script like this (it requires xclip to be installed):
#!/bin/bash
DEST="$1/$(date +%s).png"
xclip -selection clipboard -t image/png -o > $DEST
Make the script executable and in the custom action, set the command to "/path/to/this/script %f" and in appearance settings, select "Dicrectories" only.
Or if you want to be prompted for the filename (requires zenity):
#!/bin/bash
FILENAME=$(zenity --entry --title "Filename..." --text "Enter the filename to use:")
DEST="$1/$FILENAME.png"
xclip -selection clipboard -t image/png -o > $DEST
Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki | Community | Contribute ---
Offline
that's awesome I went made it a bit more dynamic (making it work with jpgs etc) and added notifications
#!/bin/bash
type="$(xclip -selection clipboard -t TARGETS -o | grep image | head -n1)"
extension="$(echo "$type" | awk -F"/" '{print $2}')"
if [ -z "$extension" ] ; then
notify-send "No image copied in clipboard" && exit
elif [ "$extension" == "jpeg" ] ; then
extension="jpg"
fi
xclip -selection clipboard -t $type -o > "Pasted-$(date +%Y-%d-%m_%H-%M-%S).$extension"
Last edited by boop (2023-11-18 17:24:42)
jumpieee
Offline
Yet another version.
1. x-qt-image is the type of image cropped-copied from XnView etc.
2. Zenity to confirm/change file name.
3. Check for "$1" allows to paste image into the current folder, running the script via terminal or via xfce launcher button (where it could be set as Pictures etc).
#!/bin/bash
# Paste image from clipboard as file
type="$(xclip -selection clipboard -t TARGETS -o | grep image | head -n1)"
extension="$(echo "$type" | awk -F"/" '{print $2}')"
if [ -z "$extension" ] ; then
notify-send "No image copied in clipboard" && exit
elif [ "$extension" == "jpeg" ] ; then
extension="jpg"
elif [ "$extension" == "x-qt-image" ] ; then
extension="png"
fi
if ! FILENAME=$(zenity --entry --width=720 --title "Picture from clipboard" --text "Save .$extension as:" --entry-text="pic-$(date +%Y-%m-%d_%H-%M)")
then
# echo Cancelled
exit
fi
if [ -z "$1" ]
then
DEST="$FILENAME.$extension"
else
DEST="$1/$FILENAME.$extension"
fi
xclip -selection clipboard -t $type -o > $DEST
Offline
This is just what I was looking for.
However, my first use case failed. When I right-click an image in MS Teams and select Copy image, this script doesn't paste the image. Yet somehow I can paste it into Firefox or LibreOffice and the image shows up. A little poking around shows that the image is only on the clipboard as text/html or text/plain. Looking at the text, it's stored as "<img src="data:image/jpeg;base64,....>".
If I can find some time, I'll see about adding some checks to the script to recognize this type of data and decode it.
Ideally, it would be integrated into Thunar so that Ctrl-v in a directory would create a file. IIRC, DirectoryOpus does this.
Offline
[ Generated in 0.013 seconds, 8 queries executed - Memory usage: 535.91 KiB (Peak: 536.75 KiB) ]