LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-06-2006, 11:09 PM   #1
paddyjoy
Member
 
Registered: Apr 2005
Location: Sydney
Distribution: FC5
Posts: 174

Rep: Reputation: 30
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
 
Old 03-07-2006, 09:22 AM   #2
zeitounator
Member
 
Registered: Aug 2003
Location: Montpellier, France, Europe, World, Solar System
Distribution: Debian Sarge, Fedora core 5 (i386 and x86_64)
Posts: 262

Rep: Reputation: 30
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
 
Old 03-07-2006, 04:01 PM   #3
paddyjoy
Member
 
Registered: Apr 2005
Location: Sydney
Distribution: FC5
Posts: 174

Original Poster
Rep: Reputation: 30
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
 
Old 03-07-2006, 07:45 PM   #4
zeitounator
Member
 
Registered: Aug 2003
Location: Montpellier, France, Europe, World, Solar System
Distribution: Debian Sarge, Fedora core 5 (i386 and x86_64)
Posts: 262

Rep: Reputation: 30
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).
 
Old 03-07-2006, 07:57 PM   #5
paddyjoy
Member
 
Registered: Apr 2005
Location: Sydney
Distribution: FC5
Posts: 174

Original Poster
Rep: Reputation: 30
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
 
Old 03-08-2006, 07:26 AM   #6
zeitounator
Member
 
Registered: Aug 2003
Location: Montpellier, France, Europe, World, Solar System
Distribution: Debian Sarge, Fedora core 5 (i386 and x86_64)
Posts: 262

Rep: Reputation: 30
Quote:
Originally Posted by paddyjoy
Thanks I can't believe I missed that
I often need a second pair of eyes as well
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Not able to click instal in the menu?! Calavera Linux - Newbie 2 10-29-2005 02:43 PM
right click menu in shell ryedunn Programming 3 10-19-2005 04:05 PM
Editing the Right click Menu thisguyz Linux - Software 1 08-26-2003 07:38 PM
Right-click menu in KDE3 Slakje Linux - Software 5 08-26-2003 01:09 PM
Konqueror right click menu tenn_eric Linux - Software 0 08-04-2003 09:45 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration