KDE desktop action to execute a command on each file of a type and append the result to a file in the same place
by msdobrescu from LinuxQuestions.org on (#4WXQ8)
I need to execute a command on each file of a specific type from the Actions context menu of Dolphin, in KDE. For example, I need to make a list with the length in milliseconds of the audio files in some directory.
What I know so far is that I should create a .desktop file in a specific path, ~/.local/share/kservices5/ or ~/.local/share/kservices5/ServiceMenus/ (this is not clear where would suffice, for me works in any of these).
The .desktop file could be like:
Code: [Desktop Entry]
Type=Service
Encoding=UTF-8
ServiceTypes=KonqPopupMenu/Plugin,inode/directory
Icon=soundconverter
Actions=ListFlacTimes;
[Desktop Action ListFlacTimes]
Terminal=true
Name=list flac times
Icon=soundconverter
Exec=...So, in the Exec part some Code:sh -c ... or Code:bash -c ... or Code:xterm -e ... should be added (in order to have everything in one place), but I fail to get the right code for that.
If I take the following command I should run:
Code:for file in /path/to/files/*.flac; do echo -e $(basename "$file")'\t'$(soxi -D "$file"); done >> /path/to/files/flac_list what should be written in the Exec entry in the .desktop file?
I fail to form a current directory expression to execute the command for each file and create the list in that folder where the action is taken.


What I know so far is that I should create a .desktop file in a specific path, ~/.local/share/kservices5/ or ~/.local/share/kservices5/ServiceMenus/ (this is not clear where would suffice, for me works in any of these).
The .desktop file could be like:
Code: [Desktop Entry]
Type=Service
Encoding=UTF-8
ServiceTypes=KonqPopupMenu/Plugin,inode/directory
Icon=soundconverter
Actions=ListFlacTimes;
[Desktop Action ListFlacTimes]
Terminal=true
Name=list flac times
Icon=soundconverter
Exec=...So, in the Exec part some Code:sh -c ... or Code:bash -c ... or Code:xterm -e ... should be added (in order to have everything in one place), but I fail to get the right code for that.
If I take the following command I should run:
Code:for file in /path/to/files/*.flac; do echo -e $(basename "$file")'\t'$(soxi -D "$file"); done >> /path/to/files/flac_list what should be written in the Exec entry in the .desktop file?
I fail to form a current directory expression to execute the command for each file and create the list in that folder where the action is taken.