Class: Nautilus::Scripts

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/nautilus_scripts.rb

Overview

like this and like this.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(items = nil) ⇒ Scripts

Constructor for Scripts class

Arguments

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

environment variables are not set



29
30
31
32
33
34
# File 'lib/nautilus_scripts.rb', line 29

def initialize(items=nil)
  @items = []
  Scripts.selected_uris(items).each { |item|
    @items << defile(item)
  }
end

Class Method Details

.current_uri(default = "") ⇒ Object

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



63
64
65
# File 'lib/nautilus_scripts.rb', line 63

def self.current_uri(default="")
  ENV['NAUTILUS_SCRIPT_CURRENT_URI']||default
end

.defile(item) ⇒ Object

Convert file URI to filesystem path

Arguments

  • item - file URI to convert to a filesystem path



43
44
45
# File 'lib/nautilus_scripts.rb', line 43

def self.defile(item)
  item.sub(/^file:\/\//, "").gsub(/%20/, " ")
end

.refile(item) ⇒ Object

Convert filesystem path to file URI



48
49
50
# File 'lib/nautilus_scripts.rb', line 48

def self.refile(item)
  item.sub(/^/, "file://").gsub(/\s/, "%20")
end

.selected_file_paths(default = "") ⇒ Object

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



78
79
80
# 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 = "") ⇒ Object

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



94
95
96
# File 'lib/nautilus_scripts.rb', line 94

def self.selected_uris(default="")
  (ENV['NAUTILUS_SCRIPT_SELECTED_URIS']||default).split(/\n/)
end

.window_geometry(default = "") ⇒ Object

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



108
109
110
111
112
113
114
# 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

Instance Method Details

#each(&block) ⇒ Object

Iterator

Arguments

  • block - block from caller

Example

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

puts path

}

Yields

  • item - each selected filesystem path



134
135
136
137
138
# File 'lib/nautilus_scripts.rb', line 134

def each(&block)
  @items.each { |item|
    block.call(item)
  }
end