LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Addin to Nautilus right click menu (https://www.linuxquestions.org/questions/linux-newbie-8/addin-to-nautilus-right-click-menu-422348/)

paddyjoy 03-07-2006 12:09 AM

Addin to Nautilus right click menu
 
I have a script that I use for resizing a jpg and uploading it using ftp onto my webserver. Is there some way I can add this script to the nautilus right click menu so that I can just right click on a jpg(or multiple jpg's) and select upload and the script will do the rest?

Paddy

zeitounator 03-07-2006 10:22 AM

Put that script in your nautilus-script folder (~/.gnome2/nautilus-scripts). It will then be accessible through right-click > script > scriptName.

You'll probably need to modify your script a little bit as nautilus scripts expect to read their arguments from an environment variable. As a starter example, here is a script I use for rotating jpeg files. For more info, http://g-scripts.sourceforge.net/ has some valuable scripts and tips.

Code:

#!/bin/bash
#####
# Nautilus script to rotate jpeg images.
#
# Put that script
# in your ~/.gnome2/nautilus-script folder. You can then use
# it from any folder after selecting the images your want to
# rotate with "right-click > scripts > rotateJpeg"
#
# Copyright 2005 Olivier Clavel
# Author: Olivier Clavel <contact AT retiz DOT com>
# Licence: GPL (http://www.gnu.org/licenses/gpl.txt)
# Depends: nautilus, libjpeg (jpegtran), gnome-utils (zenity), file
#######

# We set input field separator to "new line" so that we can safely read
# file name with spaces from $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS
IFS="
"
# location of temporary directory for file rotation
TMPDIR="/tmp"                    # Temporary directory

# Test if a file has been selected
if [ $# -eq 0 ]; then
        zenity --error --title="error" --text="You must select at least 1 file to process"
        exit 1
fi

# Ask for desired clockwise rotation.
rotation=`zenity --title "JPEG rotation" --list --column "" --radiolist --column "Clockwise rotation in degrees" TRUE 90 FALSE 180 FALSE 270`

# If no rotation value was selected, user clicked cancel: exit
if [ -z "$rotation" ] ; then
    exit;
fi


# Go for rotation
totalFiles=$#
processedFiles=0
(for name in $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS
do
  # check if the file is jpeg
  isJpeg=`file -bi "$name" | grep jpeg | wc -l`
  if [ $isJpeg -eq 1 ] ; then
      # Rotate the picture in a temporary file.
      jpegtran -copy all -rotate $rotation "$name" > $TMPDIR/tmppict.jpeg
      # Replace the original file with the rotated one.
      mv $TMPDIR/tmppict.jpeg "$name"
  fi
  let "processedFiles++"
  let "progress=processedFiles*100/totalFiles"
  echo $progress
done) |
zenity --progress --auto-close --title="Images Rotation"  --text="Processing images ..."  --percentage=0

Good luck

paddyjoy 03-07-2006 05:01 PM

Thanks for the info! Before your post I actually discovered nautilus-actions. I think it is probably just a gui for putting scripts in the ~/.gnome2/nautilus-scripts directory!

Do you know what user the scripts run as? Is it the user who is logged in?

I have a script that resizes and uplaods pictures to a web server. It works perfectly when I run it from the command line but doesn't work through the menu, any idea where the error messages go? Can't find them in /var/log/messages.

Sorry for all the question!

Here is my script, it resizes the files ok but then when it tries to execute ./ftp.pl it fails.

Code:

#!/bin/sh


for FILE in $*
do
        convert $FILE -resize 384x $FILE
done

./ftp.pl $*
OUT=$?
if [ $OUT -eq 0 ];then
        zenity --info --info-text "Files Uploaded!"
else
        zenity --info --info-text "Failed for some reason!"
fi


zeitounator 03-07-2006 08:45 PM

Change ./ftp.pl to an absolute path. I guess that is your problem.

For the other questions: yes, the script run as the loged in user. Those script are in a personal directory anyway in your home and are not shared with other users.

About standard output and error, that's the bad part: it does not go anywhere (at least nowhere I could find). I've found this messageadvising to run nautilus from a command line to get standard output and error in the same terminal. Unfortunately it does not work for me (nautilus launches a new window and exits).

paddyjoy 03-07-2006 08:57 PM

Thanks I can't believe I missed that, it was late last night when I was playing with this ha ha!

It's a pity that you can't catch the output/error, it would greatly enhance this software. In my case if I had got a "file not found ./ftp.pl" message it would have made solving my problem a lot easier!

Paddy

zeitounator 03-08-2006 08:26 AM

Quote:

Originally Posted by paddyjoy
Thanks I can't believe I missed that

I often need a second pair of eyes as well :)


All times are GMT -5. The time now is 05:26 AM.