class Nautilus::Scripts

Document the responsibility of the class

Nautilus::Scripts class

Helpers for handling NAUTILUS_SCRIPT environment variables in ruby scripts placed in ~/.local/share/nautilus/scripts

Formatting

Embody parameters or options in Teletype Text tags. You can also use bold or italics but must use HTML tags for multiple words, like this and like this.

Public Class Methods

current_uri(default="") click to toggle source

Returns the URI for the current directory from where the script was run.

Arguments

  • default - value to use if Environment variable is not set

Environment Variable

NAUTILUS_SCRIPT_CURRENT_URI=file:///home/tmp/bjs/nexus_5/links/20161202/Internal%20shared%20storage/DCIM/Camera

# File lib/nautilus_scripts.rb, line 63
def self.current_uri(default="")
        ENV['NAUTILUS_SCRIPT_CURRENT_URI']||default
end
defile(item) click to toggle source

Convert file URI to filesystem path

Arguments

  • item - file URI to convert to a filesystem path

# File lib/nautilus_scripts.rb, line 43
def self.defile(item)
        item.sub(/^file:\/\//, "").gsub(/%20/, " ")
end
new(items=nil) click to toggle source

Constructor for Scripts class

Arguments

  • items - optionally set paths to be manipulated, only if NAUTILUS_SCRIPT

environment variables are not set

# File lib/nautilus_scripts.rb, line 29
def initialize(items=nil)
        @items = []
        Scripts.selected_uris(items).each { |item|
                @items << defile(item)
        }
end
refile(item) click to toggle source

Convert filesystem path to file URI

# File lib/nautilus_scripts.rb, line 48
def self.refile(item)
        item.sub(/^/, "file://").gsub(/\s/, "%20")
end
selected_file_paths(default="") click to toggle source

Returns the list of selected files as filesystem paths

Arguments

  • default - value to use if Environment variable is not set

Environment Variable

NAUTILUS_SCRIPT_SELECTED_FILE_PATHS='/home/tmp/bjs/nexus_5/links/20161202/Internal shared storage/DCIM/Camera/IMG_20131122_111539.jpg

# File lib/nautilus_scripts.rb, line 78
def self.selected_file_paths(default="")
        (ENV['NAUTILUS_SCRIPT_SELECTED_FILE_PATHS']||default).split(/\n/)
end
selected_uris(default="") click to toggle source

Returns the list of selected files as URIs

Arguments

  • default - value to use if Environment variable is not set

Environment Variable

NAUTILUS_SCRIPT_SELECTED_URIS='file:///home/tmp/bjs/nexus_5/links/20161202/Internal%20shared%20storage/DCIM/Camera/IMG_20131122_111539.jpg

# File lib/nautilus_scripts.rb, line 94
def self.selected_uris(default="")
        (ENV['NAUTILUS_SCRIPT_SELECTED_URIS']||default).split(/\n/)
end
window_geometry(default="") click to toggle source

Returns the window geometry extracted from the environment variable as a hash

Arguments

  • default - value to use if Environment variable is not set

Environment Variable

NAUTILUS_SCRIPT_WINDOW_GEOMETRY=1540x808+26+23

# File lib/nautilus_scripts.rb, line 108
def self.window_geometry(default="")
        geo=ENV['NAUTILUS_SCRIPT_WINDOW_GEOMETRY']||default
        m=geo.match(GEOMETRY_RE)
        h={}
        [:x, :y, :w, :h].map { |k| h[k]=m.nil? ? nil : m[k] }
        return h
end

Public Instance Methods

each(&block) click to toggle source

Iterator

Arguments

  • block - block from caller

Example

s = Nautilus::Scripts.new s.each { |path|

puts path

}

Yields

  • item - each selected filesystem path

# File lib/nautilus_scripts.rb, line 134
def each(&block)
        @items.each { |item|
                block.call(item)
        }
end