Nemo script to get selected files as one command line string

Forum rules
Before you post please read how to get help
Post Reply
JohnML
Level 1
Level 1
Posts: 26
Joined: Sat Mar 20, 2010 1:13 pm
Location: frankfurt, germany

Nemo script to get selected files as one command line string

Post by JohnML » Mon Oct 02, 2017 3:21 am

Usable with LinuxMint cinnamon nemo!!

On windows ( Powertoys?!) i used it very often and missed it for Linux:

Copy selected files to string usable as command line argument.

Example:
"/home/john1/.local/share/nemo/scripts/Queue in Audacious" "/home/john1/.local/share/nemo/scripts/Scan with Avast"

As you see, long filenames will be ok

its just a one line script
Edit: 11.10.17 uses single quotes 'PathAndName'

Code: Select all

#!/bin/bash

# Powertoys "copy as name" nachahmen, geht auch mit langen Dateinamen

# single Quotes
copyq copy -- "$(echo -en "$NEMO_SCRIPT_SELECTED_FILE_PATHS" |sed -e 's/^\|$/'\''/g' | tr '\n' ' ' )"

Save it to your home-folder/.local/share/nemo/scripts/Copy_filenames
Make it executable
Goto Nemo edit/plugins
Right listbox
Check it
Select some files, right click srcipts/Copy_filenames

Paste it for example to terminal: gedit + paste

Really great copyq need to be installed!!!

Code: Select all

deb http://ppa.launchpad.net/hluk/copyq/ubuntu xenial main
deb-src http://ppa.launchpad.net/hluk/copyq/ubuntu xenial main


I could not write a sript thta handles all xcopy ...

Hope its useful ...

... have to learn which files can be attached: no scripts no *.list !!!

Ok, next solution: open terminal besides nemo and drag'n drop selected files to terminal ... bat that's much to easy, i wanted the srcipt :-)
Last edited by JohnML on Wed Oct 11, 2017 5:09 am, edited 2 times in total.

User avatar
Termy
Level 5
Level 5
Posts: 757
Joined: Mon Sep 04, 2017 8:49 pm
Location: UK
Contact:

Re: Nemo script to get selected files as one command line string

Post by Termy » Mon Oct 02, 2017 7:27 am

I'm having a hard time understanding what the goal of this one-liner is. Is it to convert this:

Code: Select all

$ ls
Beep.wav  bin  BP.wav  Desktop	Documents  dong.wav  Downloads	FB.wav	GitHub	kdenlive  Music  Pictures  ShellPlugins  Videos
...to this:

Code: Select all

$ ls -Q
"Beep.wav"  "bin"  "BP.wav"  "Desktop"	"Documents"  "dong.wav"  "Downloads"  "FB.wav"	"GitHub"  "kdenlive"  "Music"  "Pictures"  "ShellPlugins"  "Videos"
As for copying files, shell does this very, very well out of the box, thanks to things like brace expansion, parameter expansion, and then there's tab auto-completion. Find too is really good for this, thanks to features like -exec.

You're calling sed three times here; I recommend revising that. You can combine multiple sed expressions into one sed command. Here are two typical approaches:

Code: Select all

sed 's/[^ ][^ ]*/"&"/g; s/\%20/\ /g; s/file:\/\///g'
sed -e 's/[^ ][^ ]*/"&"/g' -e 's/\%20/\ /g' -e 's/file:\/\///g'
I'm also confused by the duplication of [^ ]; one of them would optionally match a space at the beginning of the line; two make no sense to me, but as it's optional, probably won't break the regex. If you have issues with these examples, which is a potentiality, you may need to revise the logic. I'd be interested in seeing an example of the output you're dealing with.

Oh, I see what the goal is now! That's awesome. Nice one. I didn't think nemo could share that sort of info like that. Makes me wonder what else it shares which could be scripted.

You could use this to save calling sed at all, and thus rely only on shell builtins for more portability (useful just about anywhere) and efficiency:

Code: Select all

for FILE in $NEMO_SCRIPT_SELECTED_URIS
{
        while read
        do  
                echo "${REPLY//%20/ }"
        done <<< ${FILE/file:\/\/}
}
Last edited by Termy on Mon Oct 02, 2017 10:04 am, edited 2 times in total.
Here to help.

I'm LearnLinux (LL) on YouTube: https://www.youtube.com/channel/UCfp-lN ... naEE6NtDSg
I'm also terminalforlife (TFL) on GitHub: https://github.com/terminalforlife

User avatar
Misko_2083
Level 1
Level 1
Posts: 23
Joined: Mon Jan 12, 2015 10:17 am

Re: Nemo script to get selected files as one command line string

Post by Misko_2083 » Mon Oct 02, 2017 9:38 am

This is interesting.
I have this in my ~/.bashrc

Code: Select all

select_files() {
OIFS=$IFS
IFS=$'\n' 
local files=" $(for line in $(zenity --file-selection --multiple --title="Select a File"  2> /dev/null | tr '|' '\n'); do printf "'%s' " "$line"; done)"
IFS=$OIFS
READLINE_LINE="${READLINE_LINE:0:READLINE_POINT}$files${READLINE_LINE:READLINE_POINT}"
READLINE_POINT=$((READLINE_POINT + ${#files}))
}

bind -x '"\C-g":select_files'
When I press ctrl+g, zenity dialog pops up and let's me select files.

User avatar
Termy
Level 5
Level 5
Posts: 757
Joined: Mon Sep 04, 2017 8:49 pm
Location: UK
Contact:

Re: Nemo script to get selected files as one command line string

Post by Termy » Mon Oct 02, 2017 10:01 am

Nice! Maybe I should start using GUIs more. xD
Here to help.

I'm LearnLinux (LL) on YouTube: https://www.youtube.com/channel/UCfp-lN ... naEE6NtDSg
I'm also terminalforlife (TFL) on GitHub: https://github.com/terminalforlife

Post Reply

Return to “Scripts & Bash”