Announcement

Collapse
No announcement yet.

Service Menus with Dolphin

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • chimak111
    replied
    I made this service menu to copy a file to the same location with a timestamp added to the end of the target filename.

    Code:
    [Desktop Action copy-with-stamp]
    Exec=cp-with-timestamp.sh %U
    Name=Add timestamp as suffix
    Icon=edit-copy
    
    [Desktop Entry]
    Actions=copy-with-stamp
    ServiceTypes=KonqPopupMenu/Plugin
    MimeType=all/all
    Type=Service
    X-KDE-Priority=TopLevel
    The script, cp-with-timestamp.sh, is this:
    Code:
    #!/bin/bash
    
    cp "$@" "$@"-"$(date +%Y%m%d%H%M%S)"
    I had to use the script because I couldn't figure out how to get it done directly from the .desktop file. If it's possible can someone please show me. Thanks!

    Leave a comment:


  • chimak111
    replied
    Never knew of kdemv5!

    Anyway, https://forum.kde.org/viewtopic.php?t=138670#p371069

    Leave a comment:


  • oshunluvr
    replied
    This works to move up one. Doesn't warn about failure if you don;t have permission;

    Code:
    [FONT=monospace][COLOR=#000000][Desktop Entry][/COLOR]
    Type=Service
    Icon=transform-shear-up
    X-KDE-ServiceTypes=KonqPopupMenu/Plugin
    MimeType=all/allfiles;
    Actions=moveUp;
    X-KDE-Priority=TopLevel
    #X-KDE-Submenu=
    Encoding=UTF-8
    
    [Desktop Action moveUp]
    Name=Move up one level
    Icon=transform-shear-up
    Exec=echo "%U" | sed 's# /#\\n/#g' | while read url; do kdemv5 "$url" ..; done
    
    [/FONT]
    Stole most of this code from Rog...

    Leave a comment:


  • oshunluvr
    replied
    Yes, just up to the parent folder.

    But it would be cool to have a "create folder and move" dialog. Sounds like a fun weekend project!

    Leave a comment:


  • kyonides
    replied
    Do you mean to move to a parent folder? Like in mv ../anything? Or like mv folder/new_folder?

    Leave a comment:


  • oshunluvr
    replied
    I want one to move files/folders up one folder - something I seem to do a lot. Seems easy enough, just haven't gotten around to it.

    Leave a comment:


  • chimak111
    replied
    Service Menu to move selected files in a folder to a new subfolder

    I came across this reddit thread: Dolphin: New folder with selected files ... how? and a response there points to this: https://aur.archlinux.org/packages/k...rwithselection

    So I created $HOME/.local/share/kservices5/ServiceMenus/new_folder_with_selection.desktop with

    Code:
    [Desktop Entry]
    Type=Service
    ServiceTypes=KonqPopupMenu/Plugin,all/allfiles
    MimeType=Application/octet-stream;inode/directory
    Actions=NFFS
    
    [Desktop Action NFFS]
    Name=New Folder with Selection
    Icon=folder-download
    Exec=sh /$HOME/bin/new_folder_with_selection.sh %U
    and
    $HOME/bin/new_folder_with_selection.sh with
    Code:
    #!/bin/sh
    
    dirname="$(kdialog \
     --inputbox "Folder to be created" "New Folder" \
     )" &&
    
    mkdir -p -- "$dirname" &&
    
    mv --target-directory="$dirname" -- "$@" ||
    
    kdialog --error "Something went wrong"

    Leave a comment:


  • chimak111
    replied
    Originally posted by jlittle View Post
    Wouldn't it be easier to invoke a script in the Exec line, and get the script to do what's needed, with many advantages, ...
    No doubt about that but I have my limitations

    Plus this issue came up as a question in another site. It's not something I plan on doing personally. The .desktop files I make or modify stay in ~/.local/share/applications.

    Leave a comment:


  • jlittle
    replied
    Wouldn't it be easier to invoke a script in the Exec line, and get the script to do what's needed, with many advantages, like
    • relaxed layout
    • comments
    • meaningful variable names
    • opportunities for logging
    • testing in isolation
    • syntax highlighting while editing
    • use of favourite scripting language

    and so on?

    Leave a comment:


  • chimak111
    replied
    How to change user and group ownership to root via service menu?

    OS: Kubuntu 18.04

    I have this service menu

    Code:
    [Desktop Action move-file]
    
    Exec=/usr/lib/x86_64-linux-gnu/libexec/kf5/kdesu mv "%U" /usr/share/applications
    
    Name=Move file
    
    Icon=document-send
    
    [Desktop Entry]
    Actions=move-file
    
    MimeType=application/x-desktop;
    
    ServiceTypes=KonqPopupMenu/Plugin
    Type=Service
    X-KDE-Priority=TopLevel
    The "Move file" option appears in Dolphin's right-click menu if the file being right-clicked is a .desktop file.

    It pops up a window for me to enter my password and then moves the file to the destination folder.

    However, the user and group are still mine, not root. How can I fix that in the Exec= line?

    I can modify the Exec= line to copy the file's path like this:

    Code:
    Exec=printf %U | xsel -b -i && /usr/lib/x86_64-linux-gnu/libexec/kf5/kdesu mv "%U" ...
    and that works to the extent that the file's path is in the clipboard (checked by using Ctrl+V in Kate) and the file is moved.

    But then I'd also want something like
    Code:
    sudo chown root:root basename
    to act on the clipboard contents in the destination folder. Is that possible and if so, how to do it correctly?




    This works:

    Code:
    Exec=printf %U | xsel -b -i && /usr/lib/x86_64-linux-gnu/libexec/kf5/kdesu mv "%U" /usr/share/applications && cd /usr/share/applications && /usr/lib/x86_64-linux-gnu/libexec/kf5/kdesu chown root:root $( basename $(xsel -b -o) )
    Last edited by chimak111; Oct 08, 2019, 02:52 AM.

    Leave a comment:


  • Don B. Cilly
    replied
    Actually, I just realised that the "sudo touch" action doesn't work.
    I had just tried it on "normal" files", not root-owned ones.
    Then, I had the "Beached Dolphin" debacle, and left testing.
    Until today, when Neon updated the kernel (an older one, again) and I had to "touch" the /boot entries.

    If I right-click on a root-owned file , no actions are available.
    If I use root-mode Dolphin, it doesn't find the actions (they're probably supposed to go in another place).

    If I use root-mode Krusader, I set up the action within it , it works just fine. Which it would, I set it up in root mode...
    Still, that's another point to Krusader. You just click Manage User Actions, use 'touch %aCurrent%' as a command, and Robert's you father's brother.
    No need to edit abstruse .desktop files in far-away directories.

    Leave a comment:


  • kubicle
    replied
    Originally posted by jlittle View Post
    Also, I use zsh now, and it doesn't source .profile at all.
    As a zsh user myself, I always symlink ~/.zprofile to ~/.profile just to get a more consistent experience/environment between shells.

    As far as good places for locally generated user scripts, both ~/bin and ~/.local/bin will work fine (personally I find ./local/bin a bit "cleaner" as it buried in a hidden directory), but one is of course free to use whatever one wishes (but it helps if you add that to $PATH one way or another).

    For system wide local scripts (meant for all users on the system), /usr/local/bin is the best place (you can also use /usr/local/sbin (generally for scripts meant for root only).

    Leave a comment:


  • jlittle
    replied
    Originally posted by Don B. Cilly View Post
    Well, if you
    echo $PATH
    ~.local/bin should be there. Right?
    (Assuming you meant ~/.local/bin). I thought, surely not, and I don't, but then I checked /etc/skel/.profile, and it has
    Code:
    # set PATH so it includes user's private bin if it exists
    if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
    fi
    
    # set PATH so it includes user's private bin if it exists
    if [ -d "$HOME/.local/bin" ] ; then
    PATH="$HOME/.local/bin:$PATH"
    fi
    (The files in /etc/skel are copied when a new user is created.) I'd not seen this before.

    The last time I looked at the default .profile it didn't have the .local bin, but that would have been a few years ago now. One is quite free to muck about with this, and I always have. Also, I use zsh now, and it doesn't source .profile at all.

    Leave a comment:


  • Don B. Cilly
    replied
    Well, if you
    echo $PATH
    ~.local/bin should be there. Right?
    And not have much in it, owned by you... not a bad place for scripts, is it?

    About the refresh... just having to re-open Dolphin is not that bad...

    Leave a comment:


  • jlittle
    replied
    "bin" for binaries is ancient unix speak, getting on for 50 years now, if not more from a unix predecessor. /bin, /usr/bin, and /usr/local/bin will always be there.

    But I agree that these archaisms can be confusing and unfriendly. Exploring more pleasant names is IMO a good idea.

    Leave a comment:

Users Viewing This Topic

Collapse

There are 0 users viewing this topic.

Working...
X