Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: KF5 file associations fail with spaces in file names

  1. #1
    Join Date
    Aug 2008
    Location
    England
    Posts
    65

    Default KF5 file associations fail with spaces in file names

    I have moved my Leap 42.2 installation to use the KDE Framework 5 applications but have found that the file associations for the KF5 applications do not work with spaces in the target file name.
    Example okular - the file association is:
    sh -c "[[ -e /opt/kf5/share/env/kf5.sh ]] && . /opt/kf5/share/env/kf5.sh; /opt/kf5/bin/okular %U"

    So when the application is run it may be invoked with:
    /opt/kf5/bin/okular file with spaces.pdf

    This will fail because it looks for three files:
    file
    with
    spaces.pdf

    The solution is to change the file association to:
    sh -c "[[ -e /opt/kf5/share/env/kf5.sh ]] && . /opt/kf5/share/env/kf5.sh; /opt/kf5/bin/okular \"%U\""

    Now all I have to do is change all the other file associations but first I will have to find them!
    This could take some time.

  2. #2
    Join Date
    Feb 2016
    Location
    Berlin
    Posts
    357

    Default Re: KF5 file associations fail with spaces in file names

    im slightly confused, file associations appear to work perfectly on TW. for those of us less versed in the obscurifications of bash could you explain the problem (what your trying to solve)? AFAIK "/opt/kf5/bin/okular file with spaces.pdf" should indeed fail by design?

  3. #3
    Join Date
    Aug 2008
    Location
    England
    Posts
    65

    Default Re: KF5 file associations fail with spaces in file names

    Hi ndc33.
    The standard file association for okular as found in System Settings -> Applications -> File Associations -> Find pdf is
    okular %U %i -caption %c

    and for the document viewer evince is
    evince %U

    where AFAIK the %U inserts the file name but something in the KDE application launch ensures that it is "quoted" so the spaces will be treated as part of the one file name.

    When the KF5 version is invoked, something in the structure looses this implied "quoting" of the file name. Maybe because the whole command is "quoted". So to resolve this the "quotation marks" have to be inserted explicitly.

    As for the obfuscation of bash I have to agree. The syntax is Byzantine and there are so many ways of doing everything. Here we have:

    sh = invoke the default version of the shell command (bash)
    -c = the following is the command for the invoked shell
    [[ expression ]] = test this condition
    -e /opt/kf5/share/env/kf5.sh = does the file exist?
    && = if the result is true then execute the following command
    . /opt/kf5/share/env/kf5.sh = the command is to read and execute the contents of the file (space between . and filename)
    ; = having done that now do this...
    /opt/kf5/bin/okular %U = the command okular with the file name but it would appear in this case unquoted.

    So the change to
    /opt/kf5/bin/okular "%U" puts the file name inside quotes and passes it on as it is with spaces and all.

    Hope that helps.

  4. #4

    Default Re: KF5 file associations fail with spaces in file names

    For clarification: You are apparently using the KF5 packages from my repo, home:wolfi323:branches:KDE:Frameworks5.

    Those cryptic Exec lines are a trick to make those applications work on other desktops than Plasma5. The packages install the files to /opt/kf5/ instead of /usr/ to achieve coinstallability with KDE4, some changes to the environment need to be done so that the applications actually find their files and libraries there.

    I haven't noticed this problem with spaces myself so far (apparently I don't have any files with spaces in the name... ), but thanks for reporting it.
    I will have a look at trying to fix it. Unfortunately it will not be so straight forward as to just add the quotes to the Exec lines, because I generate those automatically based on the original one...

  5. #5
    Join Date
    Feb 2016
    Location
    Berlin
    Posts
    357

    Default Re: KF5 file associations fail with spaces in file names

    i wrote a long message and have just noted to msg from wolfi, after editing heres whats left!
    - your fix "%U" should be checked, %U is for multiple file names and so not sure of behaviour in all cases.

  6. #6

    Default Re: KF5 file associations fail with spaces in file names

    Quote Originally Posted by ndc33 View Post
    - your fix "%U" should be checked, %U is for multiple file names and so not sure of behaviour in all cases.
    True. From the specification:
    %U A list of URLs. Each URL is passed as a separate argument to the executable program. Local files may either be passed as file: URLs or as file path.
    Same as %F:
    %F A list of files. Use for apps that can open several local files at once. Each file is passed as a separate argument to the executable program.
    %u or %f mean one single file.

    So quoting %U (and %F) is definitely wrong.

    Anyway, I will have a look at this and try to fix it.
    In the worst case I probably could just remove that "hack" completely (I do build the applications with RPATH meanwhile, so they should at least find the libs in /opt/kf5/lib/ and start...)

    FTR, the specs also say this:
    Field codes must not be used inside a quoted argument, the result of field code expansion inside a quoted argument is undefined.
    Last edited by wolfi323; 23-Feb-2017 at 09:32.

  7. #7
    Join Date
    Aug 2008
    Location
    England
    Posts
    65

    Default Re: KF5 file associations fail with spaces in file names

    wolfi323

    I see the problem but may I suggest this:

    Code:
    ( [[ -e /opt/kf5/share/env/kf5.sh ]] && . /opt/kf5/share/env/kf5.sh; /opt/kf5/bin/okular %U)
    The enclosing
    Code:
    ( )
    makes the commands execute as a group in a subshell which is what I think you were after.

    I have tested and it works fine for the Okular/KF5 association called from Dolphin with two files, both with spaces.

    Thanks for all your work on the KF5.

  8. #8

    Default Re: KF5 file associations fail with spaces in file names

    Quote Originally Posted by pblewis View Post
    wolfi323

    I see the problem but may I suggest this:

    Code:
    ( [[ -e /opt/kf5/share/env/kf5.sh ]] && . /opt/kf5/share/env/kf5.sh; /opt/kf5/bin/okular %U)
    The enclosing
    Code:
    ( )
    makes the commands execute as a group in a subshell which is what I think you were after.
    Sounds good, thanks for the suggestion.

    I want to test it with other desktops first though (mainly GNOME and IceWM, which I have installed).

    It took me a while (and quite some experimentation) to find a construct that works in all of them even if /opt/kf5/share/env/kf5.sh does not exist, when I added that 2 years ago...
    (it's not necessary in Plasma5, as with my packages that script is run on login already)

  9. #9

    Default Re: KF5 file associations fail with spaces in file names

    Quote Originally Posted by wolfi323 View Post

    I want to test it with other desktops first though (mainly GNOME and IceWM, which I have installed).
    Unfortunately, both do not even show the the application menu entry any more if I do that change.

    And now I remember that that was exactly the reason why I used "sh" in the first place...

    The specs say this:
    The Exec key must contain a command line. A command line consists of an executable program optionally followed by one or more arguments. The executable program can either be specified with its full path or with the name of the executable only. If no full path is provided the executable is looked up in the $PATH environment variable used by the desktop environment. The name or path of the executable program may not contain the equal sign ("="). Arguments are separated by a space.
    In short, this means the Exec line must look like this:
    Code:
    Exec=command arg1 arg2 ...
    Apparently both IceWM and GNOME check whether "command" actually exists...

    I have to think about this...

    But as I wrote, I can probably remove that hack completely (only add the full path), it should not be really necessary any more.
    Although there may be certain problems because the files in /opt/kf5/etc/ are not found (would mostly affect the "Get New ..." functionality), and if applications run other commands (because /opt/kf5/ won't be in the path). Though as I wrote that would only happen when run outside of Plasma5.
    For the first problem, it should be possible to just move those files to /etc/ anyway, I think there wouldn't be any conflicts as KDE4 used other locations.
    I would have to check though.

    Or maybe I have another idea...
    Last edited by wolfi323; 23-Feb-2017 at 12:50.

  10. #10
    Join Date
    Aug 2008
    Location
    England
    Posts
    65

    Default Re: KF5 file associations fail with spaces in file names

    I have changed the file association to
    Code:
    /opt/kf5/bin/okular %U
    and in plasma 5 all runs fine for the simple testing I have done.

    Now for the big question...

    Which other file associations should I change before they come up and bite me?
    I have already found
    Code:
    /opt/kf5/bin/ark %U
    .

    I suppose that I could look in /opt/kf5/bin and alter all the application that I am likely to invoke from dolphin or other. Is there any other place to look?

    Thanks.

Page 1 of 2 12 LastLast

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •