Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
How to associate files with user scripts in Nautilus 3?
View unanswered posts
View posts from last 24 hours
View posts from last 7 days

 
Reply to topic    Gentoo Forums Forum Index Desktop Environments
View previous topic :: View next topic  
Author Message
Aphax
Tux's lil' helper
Tux's lil' helper


Joined: 16 Jan 2006
Posts: 75

PostPosted: Wed Jan 25, 2012 5:51 pm    Post subject: How to associate files with user scripts in Nautilus 3? Reply with quote

Over the years I have gathered a useful set of shell scripts doing various image processing/slicing and other random web-development tasks on files, that I used to be able to associate with filetypes in Nautilus (through file properties, "Open With" tab). However, now that I have upgraded to Gnome 3, I seem to have lost the ability to do this, only 'recognized' applications are listed and I can't define my own. Is there any way for a user to do this without having write and manage .desktop files for all my scripts? Or is this another one of those 'let's make Gnome work for the average user and punish everyone that doesn't fit that mold' decisions that led to the removal of this ability? :(
Back to top
View user's profile Send private message
Aphax
Tux's lil' helper
Tux's lil' helper


Joined: 16 Jan 2006
Posts: 75

PostPosted: Wed Jan 25, 2012 9:26 pm    Post subject: Reply with quote

Oh well, for now I resorted to just making (yet another) script for this, maybe others find it useful (not thouroughly tested, will probably kill your dog/cat/lizard!)

Code:

#!/bin/sh

# Generate desktop file with given name for given commandline, so files can be associated with it
# through nautilus. Curse you, gnome 3 ! :(

DESKTOP_PATH="$HOME/.local/share/applications"

usage()
{
    THIS=`basename $0`
    echo "Usage: $THIS <appname> <cmdline>"
    echo ""
    echo "Creates (or replaces) a .desktop file under $DESKTOP_PATH with given appname and"
    echo "commandline. Note that <cmdline> needs to contain one of %f, %F, %u or %U; else"
    echo "it will not show up under the \"Open with other application\" list."
    echo ""
    echo "See also: http://standards.freedesktop.org/desktop-entry-spec/latest/ar01s06.html"
    echo ""
    echo "Example:"
    echo ""
    echo "  $THIS foobar \"\$HOME/.bin/foobar %f\""
    echo ""
}

if [ "x$1" = x ] || [ "x$2" = x ]; then
    echo "Incorrect/invalid arguments given"
    echo ""
    usage
    exit 1
fi

APP_NAME="$1"
APP_PATH="$DESKTOP_PATH/$APP_NAME.desktop"
EXEC=$2

# Check if there already exists a desktop file for given appname, if so, ask to remove it first.
if [ -e "$APP_PATH" ]; then

    echo -n "$APP_PATH already exists, delete? y/n: "
    read DELETE_YN

    if [ "x$DELETE_YN" = xy ]; then
        echo "Removing $APP_PATH"
        rm "$APP_PATH"
    else
        exit 0;
    fi
fi

cat << EOF > $APP_PATH
[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
Exec=$EXEC
Name=$APP_NAME
Comment=Custom definition for $APP_NAME
NoDisplay=true
EOF

echo "Done!"
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Desktop Environments All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum