0

I try to create a desktop file service action, under KDE, to split flac files by their cue and I would like it to open some terminal to display the process, ideally to wait for me to close it (for checking the potential errors).

So far I have a desktop file like this:

[Desktop Entry]
Type=Service
Encoding=UTF-8
ServiceTypes=KonqPopupMenu/Plugin,audio/x-flac,audio/x-flac+ogg,audio/x-oggflac
Icon=soundconverter
Actions=SplitFlacByCue;

[Desktop Action SplitFlacByCue]
Terminal=true
Name=split flac by cue
Icon=soundconverter
Exec=bash -c '$(file=$(basename "%f"); filename="${file%.*}"; shntool split -f \'$filename.cue\' -o \'flac flac --output-name=%f -\' -t \'%n - %p - %t\' \'$filename.flac\')'

I see no terminal, no error, it will fail due to the shntool part, where I fail to pass thr $filename variable. I've tried many variants, but it seems I don't get the right way.

Could anybody help me, please? Thank you.

[Edit]

Simply put: I need a desktop file with a script in the Exec parameter to split a flac by cue with the same name (except for extension, of course). It should be present when right clicking on a flac file. The challenge here is how to do it in one Exec entry instead of .sh file.

I have come to this:

Exec=xterm -e 'file=$(basename "%f"); filename="${file%.*}"; echo $filename; shntool split -f \""${filename}".cue\" -o '\''flac flac --output-name=%f -'\'' -t '\''%n - %p - %t'\'' \""${filename}".flac\"; bash\'

But when action is triggered, a generic error occurs, telling it can't parse the entry:

Error processing Exec field in

The issue lays in the shntool part, if I remove that, it opens xterm and prints the variables values.

A second try:

Exec=xterm -e 'file=$(basename "%f"); filename="${file%.*}"; echo $filename; shntool split -f \""$filename".cue\" -o "'"flac flac --output-name=%f -"'" -t "'"%n - %p - %t"'" \""$filename".flac\"; bash'

results in:

author - title shntool [split]: warning: cannot open non-existent

file: ["author - title.flac"] shntool [split]: error: cannot continue due to error(s) shown above

Still, I don't get the reason of this error.

[After a week...]

Here is the solution:

[Desktop Entry]
Type=Service
Encoding=UTF-8
ServiceTypes=KonqPopupMenu/Plugin,audio/x-flac,audio/x-flac+ogg,audio/x-oggflac
Icon=soundconverter
Actions=SplitFlacByCue;

[Desktop Action SplitFlacByCue]
Terminal=true
Name=split flac by cue
Icon=soundconverter
Exec=xterm -e 'path=$(dirname "%f"); echo $path; file=$(basename "%f"); filename="${file%.*}"; echo $filename; shntool split -D -f """$filename".cue"" -o "'"flac flac --output-name=%%f -"'" -t "'"%%n - %%p - %%t"'" """$filename".flac""; bash'
  • Yeah, closed despite I have edited the question. – mike Jul 3 '17 at 17:39
1

I see three issues with this:

  1. You seem to have too many execution levels - you are first running shntool and then you are running the output of shntool (the bash -c part). Presumably you wanted bash -c 'file=[...]' instead.
  2. I'm not sure how the command line is parsed here, but in Bash you can't escape single quotes anywhere within single quotes - you'll have to use $'' or "" quotes instead.
  3. You've just hit upon the distinction between a shell and a terminal. Instead of running bash (a shell, which does not have a graphical component) you'll want to run a terminal such as gnome-terminal, terminator or xterm (you should have at least one of these). xterm -e 'echo "Hello World"; sleep 5s', for example, will open up a new terminal window, run the two commands, and exit when the last command is finished. If you want the window to stay open after the command is finished you can add a shell as the last command:

    xterm -e 'echo "Hello World"; sleep 5s; bash'

  • Thanks, but the main issue here seems the escaping and quotes and the variable evaluation and insertion in the script. – mike Jun 25 '17 at 14:16
  • the shntool command should contain single quotes, like shntool split -f "$filename.cue" -o 'flac flac --output-name=%f -' -t '%n - %p - %t' "$filename.flac". – mike Jun 25 '17 at 14:33

Not the answer you're looking for? Browse other questions tagged or ask your own question.