LinuxQuestions.org
Help answer threads with 0 replies.
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-05-2010, 01:15 PM   #16
kwanbis
LQ Newbie
 
Registered: Nov 2009
Posts: 17

Original Poster
Rep: Reputation: 0

It is probably me doing something wrong:

Quote:
#!/bin/bash
for arg
do
fileName="$arg"
fileNoExt=$(basename $fileName)
zenity --info --title="LOG" --text="$fileNoExt" --width=200 --height=200
done
Over a file called "Open Archive.TXT", i get "Open" as the output.

Over a file called "Extract To Folder", i get nothing as the output.

:S
 
Old 01-05-2010, 01:41 PM   #17
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
Over a file called "Open Archive.TXT", i get "Open" as the output.
The name "Open Archive.TXT" will get split into separate arguments, so the first argument will be "Open". You should also get a dialog for "Archive.TXT".

Try this
Code:
fileName="$@"
fileNoExt=$(basename "$fileName")
zenity --info --title="LOG" --text="$fileNoExt" --width=200 --height=200
Hopefully the window manager is smart enough to make separate calls for each file if you have multiple files selected.
 
Old 01-05-2010, 01:46 PM   #18
kwanbis
LQ Newbie
 
Registered: Nov 2009
Posts: 17

Original Poster
Rep: Reputation: 0
but shouldn't the fileName="$arg" make it one file?

I get: "Open Archive.TXT", the .EXT is not taken out.

Quote:
#!/bin/bash
fileName="$@"
fileNoExt=$(basename "$fileName")
zenity --info --title="LOG" --text="$fileNoExt" --width=200 --height=200
 
Old 01-05-2010, 01:51 PM   #19
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
but shouldn't the fileName="$arg" make it one file?
No. You use the "for arg do" syntax, which splits the command line into arguments using space as the delimiter.

Quote:
Originally Posted by kwanbis View Post
I get: "Open Archive.TXT", the .EXT is not taken out.
AUGH! My bad. Use your original extension stripping code. I occasionally get "basename" confused with the DOS/Windows "splitpath" function. Most of the time, they do the same thing... unless there is an extension you want to remove.
 
Old 01-05-2010, 02:17 PM   #20
kwanbis
LQ Newbie
 
Registered: Nov 2009
Posts: 17

Original Poster
Rep: Reputation: 0
Files:
Quote:
AAA BBB CCC.TXT
DDD EEE FFF.DOC
Script 1:
Quote:
#!/bin/bash
for arg
do
fileName="$arg"
zenity --info --title="LOG" --text="$fileName" --width=200 --height=200
done
Result 1:
Quote:
AAA BBB CCC.TXT
DDD EEE FFF.DOC
Script 2:
Quote:
#!/bin/bash
for arg
do
fileName="$arg"
fileNoExt=${fileName%.*}
zenity --info --title="LOG" --text="$fileNoExt" --width=200 --height=200
done
Result 2:
Quote:
AAA BBB CCC
DDD EEE FFF
So "AAA BBB CCC" is not treated as 3 params.
 
Old 01-05-2010, 04:16 PM   #21
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 "AAA BBB CCC" is not treated as 3 params.
I ran this from the command line
Code:
#!/bin/bash
for arg
do
        fileName="$arg"
        echo "fileName = $fileName"
done
and got this
Code:
[user@machine:~]:./blah AAA BBB CCC.TXT
fileName = AAA
fileName = BBB
fileName = CCC.TXT
Are you running the script from the command line?

Are you getting the file name by typing "A[Tab]" and getting "AAA\ BBB\ CCC.TXT"?
 
Old 01-05-2010, 04:21 PM   #22
kwanbis
LQ Newbie
 
Registered: Nov 2009
Posts: 17

Original Poster
Rep: Reputation: 0
No, i'm running it as a nautilus script, by placing them on /home/kwanbis/.gnome2/nautilus-scripts

By the way, i just tested unrar on the command line, and as a script.

On the command line, i get echoes to the screen, but under the script, nothing is echoed to the screen.

It is like nautilus/gnome redirects the output.

Would it be possible somehow to make it print to the screen?
 
Old 01-05-2010, 04:41 PM   #23
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
It is like nautilus/gnome redirects the output.
I think that is what I was trying to tell you.

Because a GUI does not (normally) have a terminal, GUIs that run command line utilities have nowhere to send the output. Thus the need for log files for scripts that will be run under the control of a GUI.

The same problem occurs with daemons (such as web servers) that close stdout, stderr, and stdin in the child after they fork. They have no terminal to which to send output, so they log everything to files. Thus the need for several different log files in the configuration for Apache (i.e. error.log, access.log, etc.).
 
Old 01-05-2010, 06:01 PM   #24
kwanbis
LQ Newbie
 
Registered: Nov 2009
Posts: 17

Original Poster
Rep: Reputation: 0
Right.

So my question then is if there is a way to create a dialog or terminal or something where the application can output to.

Like zenity, but live.
 
Old 01-06-2010, 08:04 AM   #25
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 my question then is if there is a way to create a dialog or terminal or something where the application can output to.
You can start xterm or gnome-terminal and run a command:
Code:
#!/bin/bash
xterm -e tail -f /var/log/messages
# Note the quotes required for the gnome-terminal version
gnome-terminal -e "tail -f /var/log/messages"
The command could easily be another script which would then display all its output in the terminal.
 
Old 01-06-2010, 08:25 AM   #26
kwanbis
LQ Newbie
 
Registered: Nov 2009
Posts: 17

Original Poster
Rep: Reputation: 0
I found out that zenity itself has a progress dialog that can be used. As in this example.

Quote:
#!/bin/sh
(
echo "10" ; sleep 1
echo "# Doing XYZ" ; sleep 1
echo "20" ; sleep 1
echo "# Doing ABC" ; sleep 1
echo "50" ; sleep 1
echo "This line would be ignored as it does not starts with #" ; sleep 1
echo "75" ; sleep 1
echo "# Finalizing Test" ; sleep 1
echo "100" ; sleep 1
) |
zenity --progress \
--title="Actualizando los registros del sistema" \
--text="Rastreando los registros de los correos..." \
--percentage=0

if [ "$?" = -1 ] ; then
zenity --error \
--text="Actualización cancelada."
fi
Now, the problem is that i need to pass a number, so it moves the percentage, and a # before the text. But this is what unrar outputs.

Quote:
UNRAR 3.91 freeware Copyright (c) 1993-2009 Alexander Roshal


Extracting from filXXXX.part1.rar

Creating abcd OK
Extracting abcd/filXXXX.xxx 0% 1% 2% 3% 4% 5% 6% 7% 8% 9% 10% 11% 12% 13% 14% 15% 16% 17% 18% 19% 20%

Extracting from filXXXX.part2.rar

... filXXXX.xxx 21% 22% 23% 24% 25% 26% 27% 28% 29% 30% 31% 32% 33% 34% 35% 36% 37% 38% 39% 40%

Extracting from filXXXX.part3.rar

... filXXXX.xxx 41% 42% 43% 44% 45% 46% 47% 48% 49% 50% 51% 52% 53% 54% 55% 56% 57% 58% 59% 60%

Extracting from filXXXX.part4.rar

... filXXXX.xxx 61% 62% 63% 64% 65% 66% 67% 68% 69% 70% 71% 72% 73% 74% 75% 76% 77% 78% 79% 80%

Extracting from filXXXX.part5.rar

... filXXXX.xxx 81% 82% 83% 84% 85% 86% 87% 88% 89% 90% 91% 92% 93% 94% 95% 96% 97% 98% 99% OK
All OK
So i need to use Sed to make it work somehow.

Last edited by kwanbis; 01-06-2010 at 08:26 AM.
 
Old 01-06-2010, 10:17 AM   #27
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 i need to use Sed to make it work somehow.
I put your output from unrar in a file and used this
Code:
sed -e 's/\([0-9]*\)%/\n\1#\n/g' < data | grep '#'
to convert it to a sequence of lines that looked like
Code:
0#
1#
...
8#
9#
10#
...
98#
99#
The "..." indicates lines I removed from the output.
 
Old 01-06-2010, 11:43 AM   #28
kwanbis
LQ Newbie
 
Registered: Nov 2009
Posts: 17

Original Poster
Rep: Reputation: 0
That works fine, the only problem is that it is not real time. Unrar decompresses all the files, and then the progress works.

So i created a VERY BASIC Lazarus/FreePascal application, that reads all the input, and prints it to both, a memo, and a tpanel.

This is most of the code.

Code:
procedure TForm1.Memo1Enter(Sender: TObject);
var
 fStdIO: TextFile;
 sLinea: string;
begin
  assignfile(fStdIO,''); reset(fStdIO);                                                 // open the stdin "file"
  while not eof(fStdIO) do begin                                                        // while we are getting standard input ...
    application.ProcessMessages;                                                        // process messages (paint the texts)
    readln(fStdIO,sLinea);                                                              // read the a line
    sLinea := StringReplace(sLinea, '', '', [rfReplaceAll, rfIgnoreCase]);             // remove the strange unrar characters
    sLinea := StringReplace(sLinea, '  ', ' ', [rfReplaceAll, rfIgnoreCase]);           // remove double spaces
    Memo1.Append(sLinea);                                                               // update the memo
    Panel1.Caption := sLinea;                                                           // update the panel
  end;
  closefile(fStdIO);                                                                    // close stdin "file"
  Application.Terminate;
end;
So now i have a script to extract my RARs, that goes like this:

Code:
#!/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
	fileNoExt=${fileName%.*}
	fullFolder=$pathName/$fileNoExt
	~/xtractor/unrar e "$fullName" "$fullFolder/" | ~/xtractor/capturer
done
I still need to add something to check the returned value, and if it is ok, just close, if not, give an error message.

Last edited by kwanbis; 01-06-2010 at 11:57 AM.
 
Old 01-06-2010, 12:11 PM   #29
kwanbis
LQ Newbie
 
Registered: Nov 2009
Posts: 17

Original Poster
Rep: Reputation: 0
Just in case it is useful for anybody else, here is the link to the executable and the code/project for lazarus.

I release it under the GPL.

http://www.mediafire.com/?mownyjyuydg
 
Old 01-06-2010, 12:46 PM   #30
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
That works fine, the only problem is that it is not real time. Unrar decompresses all the files, and then the progress works.
I guess I was assuming you would change your script to be something like this
Code:
#!/bin/sh
(
unrar-command | sed -e 's/\([0-9]*\)%/\n\1\n/g'
) |
zenity --progress \
--title="Actualizando los registros del sistema" \
--text="Rastreando los registros de los correos..." \
--percentage=0

if [ "$?" = -1 ] ; then
zenity --error \
--text="Actualización cancelada."
fi
The sed expression should convert the output of the "unrar-command" to data that zenity understands. I created a proof of concept here using the following two scripts.

This first script simulates the output of the unrar command being processed into lines that zenity understands:
Code:
#!/bin/bash
# This simulates the output of the unrar command
exec 3<data
while read -u 3 line
do
        echo $line | sed -e 's/\([0-9]*\)%/\n\1 #\n/g' | grep "#"
        sleep 1 ;
done
This takes the output of the previous script and updates the progress bar of the zenity dialog:
Code:
#!/bin/bash
unrar-command | zenity --progress --percentage=0
My experiments show that you will need two scripts, one to run the command and convert the output, and one to display the zenity dialog. Trying to do the sed and grep in the zenity script causes the dialog to wait until the first script completes before it updates the progress bar, and then it jumps all the way to 100%.
 
  


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/Novell 6 02-15-2009 01:10 PM
KDE equivalent of nautilus scripts? lethargy Linux - Software 2 12-27-2006 06:16 AM
Nautilus scripts Menu flebber Linux - General 1 11-28-2006 07:10 AM
Scripts in Nautilus 2.6 bramadams Slackware 1 07-26-2004 09:15 AM
gnome nautilus scripts verstapp Linux - Newbie 0 03-12-2004 04:43 AM


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration