LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices


Reply
  Search this Thread
Old 04-22-2017, 01:26 AM   #1
msdobrescu
Member
 
Registered: Feb 2006
Location: Romania
Distribution: Sabayon
Posts: 36

Rep: Reputation: 3
desktop file to process the selected files


Hello,

I try to create a .desktop file to pass the selected files in Dolphin and process them in a bash script.
I use "%F" for parameter passing, but I can't really split the files list after (in the script) as the paths have spaces and I can't tell where the file paths + names end and where the space is the separator of them in the parameter list.

Is it even possible to have this working?

Thank you.
 
Old 04-22-2017, 02:00 AM   #2
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
yes.
whichever program parses the files, should be able to deal with spaces.

but please show us what you have.
 
Old 04-22-2017, 02:30 AM   #3
msdobrescu
Member
 
Registered: Feb 2006
Location: Romania
Distribution: Sabayon
Posts: 36

Original Poster
Rep: Reputation: 3
Hi,

I've used a script from here, altered a bit: https://gielberkers.com/convert-a-fi...-shell-script/

meaning:

Code:
for f in "$@"; do
    convertToUtf8 "$f"
done
and a desktop file like:

Code:
[Desktop Entry]
Type=Service
Encoding=UTF-8
ServiceTypes=KonqPopupMenu/Plugin,text/plain
Icon=text
Actions=ToUTF8;

[Desktop Action ToUTF8]
Name=Convert to UTF-8
Icon=text
Exec=$HOME/.local/share/kservices5/toUTF8.sh "%F" > convert2utf8.log
The log contains:

Code:
Iterate through files and convert them to UTF-8
/home/admius/Downloads/test/non utf8.txt /home/admius/Downloads/test/utf8.txt is not UTF-8 encoded (found )
Convert  to UTF-8
Probably somewhere some quotes are missing or are too many...

Note: it looks to open one file, "non utf8.txt" and doesn't process it as it passes "/home/admius/Downloads/test/non utf8.txt /home/admius/Downloads/test/utf8.txt" to the function and due to that doesn't find the file on the provided path.

Last edited by msdobrescu; 04-22-2017 at 02:35 AM.
 
Old 04-22-2017, 07:48 AM   #4
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Quote:
Originally Posted by msdobrescu View Post
Code:
for f in "$@"; do
    convertToUtf8 "$f"
done
too many quotes.
"$@" means that the for loop treats the whole string as 1 argument, so "$f" is "/home/admius/Downloads/test/non utf8.txt /home/admius/Downloads/test/utf8.txt"

this is tricky; i suspect you cannot use a for loop, but rather some sort of
Code:
echo $@ | while read line
do
    .....
done
not sure if it will work like this.
you need to do some troubleshooting to see what konqueror actually passes to the script, and if you can force it to do what you want.
i know there's alternatives to "%F" - maybe %f or %u or %U...
 
Old 04-22-2017, 09:33 AM   #5
msdobrescu
Member
 
Registered: Feb 2006
Location: Romania
Distribution: Sabayon
Posts: 36

Original Poster
Rep: Reputation: 3
I have complicated things a bit by storing all the files in a directory containing spaces in name, "my test".
I also set two files named:
  • "non utf-8.txt"
  • "utf8.txt"

Without quotes in the loop, Iget the following log:

Code:
Iterate through files and convert them to UTF-8
/home/admius/Downloads/my
/home/admius/Downloads/my is not UTF-8 encoded (found binary)
Convert  to UTF-8
test/non
test/non is not UTF-8 encoded (found )
Convert  to UTF-8
utf-8.txt
utf-8.txt is not UTF-8 encoded (found )
Convert  to UTF-8
/home/admius/Downloads/my
/home/admius/Downloads/my is not UTF-8 encoded (found binary)
Convert  to UTF-8
test/utf8.txt
test/utf8.txt is not UTF-8 encoded (found )
Convert  to UTF-8
It creates an empty new file, named "utf-8.txt".

And it does not correct the non UTF-8 file, as it works with wrong paths, obviously.

I don't care how, or if it is following the above code at all, is this even possible, i.e. selecting some files and converting them when spaces are in the names of the files and their directory paths?

Last edited by msdobrescu; 04-22-2017 at 10:47 AM.
 
Old 04-22-2017, 12:18 PM   #6
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
i told you, you need a 'while read x' sort of structure.
where x is a line of output from some command.
but you need to find out what sort of output is sent to your script.
do some troubleshooting, and whenever you post some output here, also post the script that produced it.
you just need to try different things.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
I need a script to Delete Selected BackupFiles and Restore selected backup file finalwar Linux - Newbie 3 07-20-2010 02:10 AM
scheduler invocation, process selected, process entry and exit linuxdoniv Programming 1 03-14-2008 08:37 AM
scheduler invocation, process selected, process entry and exit linuxdoniv Programming 1 03-14-2008 03:48 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop

All times are GMT -5. The time now is 02:51 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration