KDE service menu to create new folder from selection

Resolved

Like the title says, I'm trying to create a KDE service menu for the purpose (I think something similar is in OSX 10.8).

I used this tutorial and I've gotten as far as invoking kdialog to get the name of the new directory... and possibly using xargs to pass the output to mkdir.

However, I can't seem to find how to create a folder in the directory the service was called from (it defaults to $HOME).

Two, I'm trying to use the following:

bash -c "(kdialog --inputbox "Folder to be created" "New Folder" --title "Create New Folder with selection" | xargs -0 mkdir)"

in the Exec field of the .desktop file for the service. It errors out with "to: -c: line 1: syntax error: unexpected end of file". My question is how I get "bash -c" to accept multiple inputs with command line switches.

Three, and this is if anyone's experimented with this kinda thing, Dolphin reflects changes made to the .desktop file for the service menu only on the 2nd execution or so. Bug?

KDE 4.10 on Arch x64, if that's relevant.

Posted Feb 11, 2013, 8:09 PM UTC · edited

63
BasioMeusPugaOP•

Figured it out:

The Service menu folder needs a desktop file in it. How to make one is in the tutorial above.

In my case, this was:

[Desktop Entry]
Type=Service
ServiceTypes=KonqPopupMenu/Plugin,all/allfiles
MimeType=Application/octet-stream;inode/directory
Actions=NFFS

[Desktop Action NFFS]
Name=New Folder from selection
Icon=folder-download
Exec=sh /path/to/script %U

And as for the actual script,

#!/bin/bash
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
foldname=`kdialog --inputbox "Folder to be created" "New Folder" --title "Create New Folder with selection"`

if [ $? = 0 ]; then
dir=`dirname $1`
mkdir "$dir"/"$foldname"

if [ $? = 1 ]; then      
kdialog --error "Invalid Name"
else

for file in ${@} ; do
mv "$file" -t "$dir"/"$foldname"
done

fi
else
kdialog --error "Cancelled"
fi
IFS=$SAVEIFS

Someone tell me I'm pretty.

5
karper•

You're awesome. And pretty. Very pretty. :)

Also, I'm stealing this for r/kde.

1
[deleted]•

Add it to the AUR!!!

1