LinuxQuestions.org
Visit Jeremy's Blog.
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 01-04-2010, 01:18 PM   #1
kwanbis
LQ Newbie
 
Registered: Nov 2009
Posts: 17

Rep: Reputation: 0
Nautilus Scripts Not Working (Fedora 12)


I'm trying to write some nautilus scripts.

I have a file (script) called fileType, on the scripts folder, that shows when i right click over a file, on the context menu, but it does nothing.

Code:
#!/bin/sh
for arg
do
filetype=$(file "$arg")
  gdialog --title "File-Type Determinator" --msgbox "File $filetype" 200 200
done
Now, i tried gdialog on terminal, and i get a command not found.

So, i changed gdialog --title "File-Type Determinator" --msgbox "File $filetype" 200 200 to echo "File $filetype" but i see nothing.

To test, i added at the end of the script the command "peazip", and peazip starts, so the script is running, but the echo/gdialog lines are not working, any ideas?

Last edited by kwanbis; 01-04-2010 at 03:21 PM.
 
Old 01-04-2010, 02:04 PM   #2
David1357
Senior Member
 
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Blog Entries: 1

Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by kwanbis View Post
any ideas?
To get it to work, I had to change the script to look like the following:
Code:
#!/bin/sh
for arg
do
    filetype=$(file "$arg")
    # Uncomment the following for debugging
    # echo "File $filetype"
    zenity --info --title="File-Type Determinator" --text="File $filetype" --width=200 --height=200
done
At one point, I got a message saying gdialog was just a wrapper around zenity, and that I should execute zenity directly.
 
1 members found this post helpful.
Old 01-04-2010, 03:14 PM   #3
kwanbis
LQ Newbie
 
Registered: Nov 2009
Posts: 17

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by David1357 View Post
To get it to work, I had to change the script to look like the following:
...
At one point, I got a message saying gdialog was just a wrapper around zenity, and that I should execute zenity directly.
Thanks, that worked.

What is NOT working, is the echo command, as in:

echo "File $filetype" (without the comments).

Does the echo goes to a log? or i'm not seeing it cause i'm running as a nautilus script?
 
Old 01-04-2010, 03:18 PM   #4
David1357
Senior Member
 
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Blog Entries: 1

Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by kwanbis View Post
Does the echo goes to a log? or i'm not seeing it cause i'm running as a nautilus script?
You would only be able to see that output if you ran the script from a terminal window.
 
Old 01-04-2010, 03:21 PM   #5
kwanbis
LQ Newbie
 
Registered: Nov 2009
Posts: 17

Original Poster
Rep: Reputation: 0
Thanks, you have been mostly helpful.
 
Old 01-05-2010, 11:16 AM   #6
kwanbis
LQ Newbie
 
Registered: Nov 2009
Posts: 17

Original Poster
Rep: Reputation: 0
Ok, i finally got my script to work. Almost.

Code:
#!/bin/sh
for arg
do
	pathName=`echo $NAUTILUS_SCRIPT_CURRENT_URI | sed -e 's|file:///|/|' -e 's|//|/|' -e 's|%20| |'`
	fileName="$arg"
	fullName=$pathName/$fileName
	fileNoExt=${fileName%.*}
	fullFolder=$pathName/$fileNoExt
	# zenity --info --title="Executing..." --text="/usr/local/share/PeaZip/res/7z/7z x -o$fullFolder $fullName" --width=200 --height=200
	/usr/local/share/PeaZip/res/7z/7z x -o"$fullFolder" "$fullName"
	zenity --info --title="DONE Executing" --text="/usr/local/share/PeaZip/res/7z/7z x -o$fullFolder $fullName" --width=200 --height=200
done
Now, the problem is that 7z, executes hidden! I don't see it, i thought it would open a terminal like screen. But nothing.

What can it be? Can it be related to me not being able to see "echo XXX" messages also?

Last edited by kwanbis; 01-05-2010 at 11:19 AM.
 
Old 01-05-2010, 12:08 PM   #7
David1357
Senior Member
 
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Blog Entries: 1

Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by kwanbis View Post
Now, the problem is that 7z, executes hidden!
Why don't you use PeaZip instead of 7z? It has command line options like "-ext2here" that should give you the GUI. 7z is probably a command-line-only application that outputs text to stdout, which would only show up in a terminal.

I have put some questions inline with the code below.

Code:
#!/bin/sh
### Why not use /bin/bash?
for arg
do
	pathName=`echo $NAUTILUS_SCRIPT_CURRENT_URI | sed -e 's|file:///|/|' -e 's|//|/|' -e 's|%20| |'`
	fileName="$arg"
	fullName=$pathName/$fileName
	### With bash, the following can be fileNoExt=$(basename $fileName)
	fileNoExt=${fileName%.*}
	fullFolder=$pathName/$fileNoExt
	### Why not use the following instead
	/usr/local/share/PeaZip/bin/PeaZip -ext2folder
	zenity --info --title="DONE Executing" --text="/usr/local/share/PeaZip/bin/PeaZip -ext2folder" --width=200 --height=200
done
 
Old 01-05-2010, 12:13 PM   #8
kwanbis
LQ Newbie
 
Registered: Nov 2009
Posts: 17

Original Poster
Rep: Reputation: 0
Yes, i know about peazip, in fact, it comes with some scripts in itself.

But i'm trying to understand why this is not working.

Like, shouldn't this scripts output to terminal?

Last edited by kwanbis; 01-05-2010 at 12:18 PM.
 
Old 01-05-2010, 12:20 PM   #9
David1357
Senior Member
 
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Blog Entries: 1

Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by kwanbis View Post
Like, shouldn't this scripts output to terminal?
Are you running the script from a terminal? If you are running this using the GUI, there is no TTY and all output goes to "/dev/null".

Even if you are running this from a terminal, the "res/7z/7z" binary may be designed to send all output to "/dev/null" as it appears to be a helper program.

Last edited by David1357; 01-05-2010 at 12:22 PM. Reason: Added comment about 7z helper program
 
Old 01-05-2010, 12:26 PM   #10
kwanbis
LQ Newbie
 
Registered: Nov 2009
Posts: 17

Original Poster
Rep: Reputation: 0
I see what you mean.

So how comes i've seen plenty of shell script examples, where they use the "echo something2?

Shouldn't that work?

Also, fileNoExt=$(basename $fileName) gives nothing, i have tried it before.

I even changed to bash: #!/bin/bash
 
Old 01-05-2010, 01:08 PM   #11
David1357
Senior Member
 
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Blog Entries: 1

Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by kwanbis View Post
So how comes i've seen plenty of shell script examples, where they use the "echo something"?
Many times I write scripts that use "echo" and a log file. That way, even if the script runs without a TTY, I can see the output of the "echo". For example
Code:
#!/bin/bash
LOGFILE="/var/log/script.log"
# Notice that the first time I write to the log file
# I use the create file redirect ">".  Also, I combine
# stderr with stdout using "2>&1", so that I log any
# errors.
echo "Starting the script..." > $LOGFILE 2>&1
# Notice that from this point on, I use the append file redirect ">>".
/usr/bin/something >> $LOGFILE 2>&1
echo "Done." >> $LOGFILE 2>&1
Quote:
Originally Posted by kwanbis View Post
Also, fileNoExt=$(basename $fileName) gives nothing, i have tried it before.
Make sure your "bash" is really "bash". Run "ls -al $(which bash)". It may be a link to dash or something in "/etc/alternatives". In either case, it may not be the real full-featured "bash". Accept no substitutes...
 
Old 01-05-2010, 01:15 PM   #12
kwanbis
LQ Newbie
 
Registered: Nov 2009
Posts: 17

Original Poster
Rep: Reputation: 0
Thanks again. I do know about redirection, from my DOS BATCH days. I would try that then, if needed.

This is the output i get:

-rwxr-xr-x. 1 root root 861128 2009-12-11 08:51 /bin/bash
 
Old 01-05-2010, 01:27 PM   #13
David1357
Senior Member
 
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Blog Entries: 1

Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by kwanbis View Post
Thanks again. I do know about redirection, from my DOS BATCH days. I would try that then, if needed.
Yes, a lot of the Linux redirection syntax is very similar to DOS batch file syntax (and NT CMD file syntax for that matter...).

Quote:
Originally Posted by kwanbis View Post
This is the output i get:

-rwxr-xr-x. 1 root root 861128 2009-12-11 08:51 /bin/bash
That looks correct. What does "bash --version" produce?
 
Old 01-05-2010, 01:34 PM   #14
kwanbis
LQ Newbie
 
Registered: Nov 2009
Posts: 17

Original Poster
Rep: Reputation: 0
I get:

Quote:
GNU bash, version 4.0.35(1)-release (i386-redhat-linux-gnu)
 
Old 01-05-2010, 01:58 PM   #15
David1357
Senior Member
 
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Blog Entries: 1

Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by kwanbis View Post
GNU bash, version 4.0.35(1)-release (i386-redhat-linux-gnu)
This is the second time I have seen someone post unexpected behaviour from version 4 of bash. Looks like "good enough" wasn't, so they changed it to "worse than before".
 
  


Reply

Tags
echo, nautilus, scripts


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
suse 11.1 nautilus scripts not working NewDisciple SUSE / openSUSE 6 02-15-2009 02:10 PM
KDE equivalent of nautilus scripts? lethargy Linux - Software 2 12-27-2006 07:16 AM
Nautilus scripts Menu flebber Linux - General 1 11-28-2006 08:10 AM
Scripts in Nautilus 2.6 bramadams Slackware 1 07-26-2004 10:15 AM
gnome nautilus scripts verstapp Linux - Newbie 0 03-12-2004 05:43 AM

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

All times are GMT -5. The time now is 01:11 PM.

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