Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Could I have a bash script open multiple files when I click on one?

  1. #1
    Join Date
    Nov 2006
    Location
    There and back again
    Beans
    1,097

    Could I have a bash script open multiple files when I click on one?

    Hello all.

    I just learned about feh, and I think it's a great image viewer. I am hoping to be able to incorporate feh into my desktop. Feh does have the ability to browse through images. If I select feh as my default viewer in Gnome, click on the image, it opens images be in a single viewmode - I am unable to browse to images in the same directory.. So I wrote a bash script,

    Code:
    #!/bin/bash
    feh *.png
    pointed Gnome to it, to noavail. I know this is pretty basic but I don't have a clue on what I need to have this work. Can anyone think of a way I can browse with feh?

  2. #2
    Join Date
    Feb 2007
    Beans
    314
    Distro
    Ubuntu 7.04 Feisty Fawn

    Re: Could I have a bash script open multiple files when I click on one?

    Quick solution in python:

    PHP Code:
    import os

    files 
    os.listdir("path here")
    for 
    x in files:
        
    os.system("feh " x
    I think thats what you want it to do? Open multiple instances of feh with all the images in a specific directory?
    <plexr> do you know std c++ ?
    <plexr> or is a weak understanding of VB your only strength
    <ahorse_> oohhhhh he just said the equivalent of *yo momma*
    www.acgla.net <--- My webpage : )

  3. #3
    Join Date
    Nov 2006
    Location
    There and back again
    Beans
    1,097

    Re: Could I have a bash script open multiple files when I click on one?

    No, actually this would be just one instance. Feh allows browsing by right and left arrows if multiple images are opened:

    Code:
    feh desktop#1.png desktop#2.png
    feh *.png
    If only one image is picked then browsing is not available. So I'm looking for a script that feh will be aware of other image files in the directory when double-clicking on say desktop#1.png.
    Last edited by Gen2ly; March 9th, 2008 at 10:38 PM.

  4. #4
    Join Date
    Feb 2007
    Beans
    314
    Distro
    Ubuntu 7.04 Feisty Fawn

    Re: Could I have a bash script open multiple files when I click on one?

    I got into a bit of an issue when trying to solve this. When you call a program from nautilus it doesn't give you back its full path which i was going to use to scan for more images. Any ideas?
    <plexr> do you know std c++ ?
    <plexr> or is a weak understanding of VB your only strength
    <ahorse_> oohhhhh he just said the equivalent of *yo momma*
    www.acgla.net <--- My webpage : )

  5. #5
    Join Date
    Jun 2006
    Location
    Gwangju, Korea
    Beans
    3,479

    Re: Could I have a bash script open multiple files when I click on one?

    Here's an untested workup in Ruby:

    Code:
    #!/usr/bin/env ruby
    
    files = Dir.entries(File.split(ARGV[0])[0])
    `feh #{files[2..-1].join ' '}`
    Last edited by mssever; March 10th, 2008 at 04:40 AM.

  6. #6
    Join Date
    Nov 2006
    Location
    There and back again
    Beans
    1,097

    Re: Could I have a bash script open multiple files when I click on one?

    Ah awesome! I'm looking for to trying this when I get a chance later tonight.

  7. #7
    Join Date
    Feb 2007
    Beans
    314
    Distro
    Ubuntu 7.04 Feisty Fawn

    Re: Could I have a bash script open multiple files when I click on one?

    The ruby one doesn't work for me : \
    <plexr> do you know std c++ ?
    <plexr> or is a weak understanding of VB your only strength
    <ahorse_> oohhhhh he just said the equivalent of *yo momma*
    www.acgla.net <--- My webpage : )

  8. #8
    Join Date
    Jun 2006
    Location
    Gwangju, Korea
    Beans
    3,479

    Re: Could I have a bash script open multiple files when I click on one?

    It appears that Nautilus passes the interesting information via environment variables, not commant line arguments. Here's a test script that displays the environment and arguments given to it:
    Code:
    #!/bin/bash
    
    zenity --info --title=Environment --text="$(env)"
    zenity --info --title="Command Line Arguments" --text="$*"
    This code works for me:
    Code:
    #!/usr/bin/env ruby
    
    # Get the currently-selected files as an array
    files = ENV['NAUTILUS_SELECTED_FILE_PATHS'].to_s.chomp.split "\n"
    
    if files.length >= 1
      # One or more files must be selected
      `feh #{files.join ' '}`
    else
      # no files are selected
      `feh #{ENV['NAUTILUS_SCRIPT_CURRENT_URI'].gsub(/^[^:]+:\/\/(.*)/, '\1')}`
    end
    This will call feh with the selected files. If no files are selected, it will call feh with the selected directory.
    Last edited by mssever; March 10th, 2008 at 05:23 AM.

  9. #9
    Join Date
    Nov 2006
    Location
    There and back again
    Beans
    1,097

    Re: Could I have a bash script open multiple files when I click on one?

    Appreciate the coding guys - cool stuff. I just put ruby on my pc, so I hope I did it right. I chmodded the script, and put it in /usr/bin and in the "Open With" dialog choose it. I double click it and got a spike in the cpu but thats all. I ran the script from the command line and got this but I probably not helpful:

    Code:
    ./usr/bin/feh-browser:4: private method `chomp' called for nil:NilClass (NoMethodError)

  10. #10
    Join Date
    Jun 2006
    Location
    Gwangju, Korea
    Beans
    3,479

    Re: Could I have a bash script open multiple files when I click on one?

    Quote Originally Posted by Dirk.R.Gently View Post
    I ran the script from the command line and got this but I probably not helpful
    Actually, you did just the right thing. Running from the command line lets you see errors, and posting errors allows people to debug them. (Command line note: Because Nautilus sets environment variables, you'll need to manually set them in order to test the script from the command line.

    I edited my post above to fix precisely that error. Probably you missed my edit. (By the way, you can write this in any language. I used Ruby because it's my personal favorite.

    One other thing: Nautilus scripts belong in ~/.gnome2/nautilus-scripts, not /usr/bin.

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •