Results 1 to 4 of 4
I have a .sh script i'm making to run a few commands before a file is open.
In my launcher command I have.
/opt/scripts/test.sh myfile.pdf
I can get the file ...
- 01-23-2008 #1Just Joined!
- Join Date
- Jan 2008
- Posts
- 2
How do I pass the file name in a launcher?
I have a .sh script i'm making to run a few commands before a file is open.
In my launcher command I have.
/opt/scripts/test.sh myfile.pdf
I can get the file name with $1 at that point, but what if I wanted this to work for 100's of files each with a different name? is there a way to pass the file name with the command?
maybe something like
/opt/scripts/test.sh $THIS_FILE
^ I know that wont work but is there some way I can give the name of the file being opened as an argument?
thanks in advance
- 01-24-2008 #2
I'm afraid I don't understand. You have a script that at some point calls "/opt/scripts/test.sh myfile.pdf"? But instead, you want to have a list of files and call it for every one?
You could do something like this:
This creates a loop on every file in the current directory ending in ".pdf" and stores that name in the file variable. You can loop through these and call the script on each of them. Within the script, you can use $1 to get the first argument.Code:for file in *.pdf; do /opt/scripts/test.sh "$file" done
Does this help? If not, try explaining the problem a bit more thoroughly (maybe with an example?).DISTRO=Arch
Registered Linux User #388732
- 01-24-2008 #3Just Joined!
- Join Date
- Jan 2008
- Posts
- 2
little more explanation
Thanks for the reply.
We have 3 servers, 2 with Solaris 10 x86 and one with Red Hat ES. We have been having a ton of problems printing and viewing PDF's on the solaris box's and Adobe's last Solaris x86 release of Acroread is 4 and now its up to 8. So we have been having our users save the file in a mounted DIR, then we made a launcher on the Solaris box that would SSH into the RedHat box with X-forwarding and open Acroread. This is all fine and dandy but for end users, it becomes a pain because they have to go threw like 5-6 steps in order for this to work. So I decided that I would write a sell script that would automate the process. This is what I have so far. Oh and just to let everyone know we have tried GNOME pdf, XPDF, and GV, they work some times but there not consistent.
This is the command I'm using for the launcher. but after I get this working I'm going to set it as the default action when opening a PDF file
^ this wont work cause it assumes that all files are named mypdf.pdf. Is there a way to get the file name threw a variable like $FILE or something, and is there a variable to tell what DIR the file is located in like $DIR. I thought it might be $PWD but that seems to point to where the SH script is.Code:/opt/scripts/test.sh mypdf.pdf
Heres the SH script (so far)
^ this works but again is dependent on the file being on Desktop and not just anywhere.Code:cp $HOME/Desktop/$1 /mounted_dir/pdf ssh 192.168.1.123 -X acroread /mounted_dir/pdf/$1
Maybe if I ask the question like this it will be easier to understand.
Lets say you have a file called textfile.txt and you double click it and it opens in gedit.
How does gedit know what file you are trying to open? the only command that seems to be being sent is "gedit". there must be a variable passed along when you open it that tells gedit what file your trying to open and where it is.
thanks
- 01-24-2008 #4
Gotcha!
So I don't personally use Gnome, so I'm not sure exactly how it works. However, the way it probably works is that it takes the command it was told to execute and adds the filename after that.
So if your command is called "/opt/scripts/test.sh", you could set "/opt/scripts/test.sh" in the Nautilus configuration, and within the script, use $1 to find out the file you were given.
Give it a shot and see what happens!DISTRO=Arch
Registered Linux User #388732


Reply With Quote