Xfce Forum

Sub domains
 

You are not logged in.

#1 2023-11-17 11:30:15

boop
Member
Registered: 2023-05-23
Posts: 15

Making a custom action to paste images from clipboard

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 hmm

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

#2 2023-11-17 12:44:47

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,240

Re: Making a custom action to paste images from clipboard

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

#3 2023-11-18 17:23:51

boop
Member
Registered: 2023-05-23
Posts: 15

Re: Making a custom action to paste images from clipboard

that's awesome smile  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

#4 2023-11-20 06:56:56

JayGursky
Member
Registered: 2023-07-04
Posts: 21

Re: Making a custom action to paste images from clipboard

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

Board footer

Powered by FluxBB