A question of Quote(s) in Nemo Action [SOLVED]

Forum rules
Before you post please read how to get help
Post Reply
Fuzzy
Level 4
Level 4
Posts: 235
Joined: Thu Jul 28, 2011 11:54 am

A question of Quote(s) in Nemo Action [SOLVED]

Post by Fuzzy »

I've run into a persistent problem with a previously posted Nemo Action. The problem is that, while the action works wonderfully most of the time - if a folder name or file name contains an ampersand, then it is omitted from the playlist (in the case of a file) or causes the nemo action to break (in the case of a folder).

I'm trying to figure out a way in which to overcome this hurdle, and suspect (perhaps wrongly) that it has something to do with quotes. My goal is to overcome this issue with ampersands, and to have the file/folder added to the playlist regardless of whether an ampersand is present.

Here's my action:

Code: Select all

[Nemo Action]
Name=Add to Playlist
Comment=Creates /tmp/Playlist.m3u playlist to open with Celluloid
Exec=bash -c "find %F -iname '*.mp3' | sort > /tmp/Playlist.m3u; celluloid /tmp/Playlist.m3u"
Icon-Name=media-playback-start-symbolic
Selection=notnone
Extensions=any
EscapeSpaces=true
Dependencies=celluloid
Any direction would be greatly appreciated. I've tried any number of quote combinations with single quotes, double quotes, and $( ), etc.

Thanks,
Fuzzy
Last edited by Fuzzy on Sun Aug 09, 2020 11:50 am, edited 1 time in total.
User avatar
Kadaitcha Man
Level 9
Level 9
Posts: 2751
Joined: Mon Aug 27, 2012 10:17 pm

Re: A question of Quote(s) in Nemo Action

Post by Kadaitcha Man »

Fuzzy wrote:
Fri Aug 07, 2020 11:58 am
Any direction would be greatly appreciated. I've tried any number of quote combinations with single quotes, double quotes, and $( ), etc.

Code: Select all

find %F -iname '*.mp3' | sort > /tmp/Playlist.m3u
That works from the command line, substituting a directory for %F.

Code: Select all

find %F -iname "*.mp3" | sort > /tmp/Playlist.m3u
That also works.

You might try this:

Code: Select all

Exec=bash -c "find %F -type f -print -name .mp3 | sort > /tmp/Playlist.m3u; celluloid /tmp/Playlist.m3u"
You should remove ; celluloid /tmp/Playlist.m3u while testing.
It's pronounced kad-eye-cha, not kada-itcha.
Fuzzy
Level 4
Level 4
Posts: 235
Joined: Thu Jul 28, 2011 11:54 am

Re: A question of Quote(s) in Nemo Action

Post by Fuzzy »

Thanks for the ideas, Kadaitcha Man!

Unfortunately, the line as provided

Code: Select all

Exec=bash -c "find %F -type f -print -name .mp3 | sort > /tmp/Playlist.m3u; celluloid /tmp/Playlist.m3u"
Produces two issues:
1. If the top folder contains an ampersand, then the action creates an empty playlist.m3u.
2. If the top folder doesn't contain an ampersand, then the action creates a playlist.m3u (including files with ampersands!), but also includes non-mp3 files in the list.

I tried tinkering with the command bit but never could get it to work correctly as an action.

So - perhaps the issue isn't a scripting issue, but is instead an action issue?

Thanks also for the tip about removing the celluloid portion for testing purposes - you'd think that would be pretty obvious...but no, I hadn't done that yet, which left me killing a lot of processes.

Fuzzy
User avatar
smurphos
Level 17
Level 17
Posts: 7332
Joined: Fri Sep 05, 2014 12:18 am
Location: Britisher
Contact:

Re: A question of Quote(s) in Nemo Action

Post by smurphos »

Try

Code: Select all

[Nemo Action]
Name=Add to Playlist
Comment=Creates /tmp/Playlist.m3u playlist to open with Celluloid
Exec=bash -c "find %F -iname '*.mp3' | sort > /tmp/Playlist.m3u; celluloid /tmp/Playlist.m3u"
Icon-Name=media-playback-start-symbolic
Selection=notnone
Extensions=any
Quote=single
Dependencies=celluloid
For custom Nemo actions, useful scripts for the Cinnamon desktop, and Cinnamox themes visit my Github pages.
Fuzzy
Level 4
Level 4
Posts: 235
Joined: Thu Jul 28, 2011 11:54 am

Re: A question of Quote(s) in Nemo Action

Post by Fuzzy »

Thanks Smurphos,

I had tried that before - but not with the deletion of EscapeSpaces. I was surprised that the results were different without the

Code: Select all

EscapeSpaces=true
line! Thank you very much for the suggestion!!

So - the great news is that it your suggestion totally fixed the issue with ampersands. The down side is that it created a new issue with folder names containing single quotes (though it seems to handle the file names containing single quotes just fine.)

If one of the parent folders contains single quotes in the folder name, then no new playlist is created, the prior/old playlist remains, and celluloid isn't launched.

I'm excited to see some change in output though!

Fuzzy
User avatar
smurphos
Level 17
Level 17
Posts: 7332
Joined: Fri Sep 05, 2014 12:18 am
Location: Britisher
Contact:

Re: A question of Quote(s) in Nemo Action

Post by smurphos »

Hi,

Separating this out to a script it the easiest solution I think.

Tested the below with paths including single quotes and ampersands and it worked OK.

The action

Code: Select all

[Nemo Action]
Name=Add to Playlist
Comment=Creates /tmp/Playlist.m3u playlist to open with Celluloid
Exec=<add_to_playlist.sh %F>
Icon-Name=media-playback-start-symbolic
Selection=notnone
Extensions=any
EscapeSpaces=true
Dependencies=celluloid
The script - saved as ~/.local/share/nemo/actions/add_to_playlist.sh and made executable

Code: Select all

#!/bin/bash
find "$1" -iname '*.mp3' | sort > /tmp/Playlist.m3u; celluloid /tmp/Playlist.m3u
For custom Nemo actions, useful scripts for the Cinnamon desktop, and Cinnamox themes visit my Github pages.
Fuzzy
Level 4
Level 4
Posts: 235
Joined: Thu Jul 28, 2011 11:54 am

Re: A question of Quote(s) in Nemo Action

Post by Fuzzy »

Hi Smurphos,

Thanks for putting the time into this. Indeed, your fix solves the primary problem, and helped me with a point of confusion (how to interact with a script from within an action).

However...while this works perfectly for a single parent folder or single individual files - it fails to allow more than one folder or file to be selected. (It will only add the folder or file I specifically right-clicked on - not all the selected folders or files - to the playlist.) Any thoughts on why %F would be interpreted this way? Is it due to the way actions pass the "%F" variable to the script?

Thanks again,
Fuzzy
User avatar
smurphos
Level 17
Level 17
Posts: 7332
Joined: Fri Sep 05, 2014 12:18 am
Location: Britisher
Contact:

Re: A question of Quote(s) in Nemo Action

Post by smurphos »

Fuzzy wrote:
Sat Aug 08, 2020 12:05 pm
Any thoughts on why %F would be interpreted this way? Is it due to the way actions pass the "%F" variable to the script?
It's because I'm an idiot... :roll:

Make the script this. The $@ passes all the arguments from %F to find - with the original $1 I suggested only the first argument is passed on.

Code: Select all

#!/bin/bash
find "$@" -iname '*.mp3' | sort > /tmp/Playlist.m3u; celluloid /tmp/Playlist.m3u
For custom Nemo actions, useful scripts for the Cinnamon desktop, and Cinnamox themes visit my Github pages.
Fuzzy
Level 4
Level 4
Posts: 235
Joined: Thu Jul 28, 2011 11:54 am

Re: A question of Quote(s) in Nemo Action

Post by Fuzzy »

Thanks, Smurphos!!

That was it!

So, that would mean every match of %F is passed as an argument - all at the same time in a single call of the script?! Meaning...if I had selected 1200 folders/files to run the action on, that %F passes add_to_playlist.sh 1200 (full file path) arguments in one giant in-line call?

Thanks,
Fuzzy
;^)>>>

[Edit: marking as solved]
Post Reply

Return to “Scripts & Bash”