Class: Imagetools::Imageburst
- Inherits:
-
Object
- Object
- Imagetools::Imageburst
- Defined in:
- lib/imagetools/imageburst.rb
Constant Summary collapse
- BASE_FOLDER =
"~/Documents/capture"
- DEFAULAT_TIME =
180
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(opts) ⇒ Imageburst
constructor
A new instance of Imageburst.
- #run ⇒ Object
Constructor Details
#initialize(opts) ⇒ Imageburst
Returns a new instance of Imageburst.
33 34 35 |
# File 'lib/imagetools/imageburst.rb', line 33 def initialize(opts) @opts = opts end |
Class Method Details
.run(argv) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/imagetools/imageburst.rb', line 12 def self.run(argv) STDOUT.sync = true opts = {} opt = OptionParser.new(argv) opt.version = VERSION opt. = "Usage: #{opt.program_name} [-h|--help] args" opt.separator('') opt.separator('Options:') opt.on_head('-h', '--help', 'Show this message') do |v| puts opt.help exit end opt.on('-v', '--verbose', 'Verbose message') {|v| opts[:v] = v} opt.on('-p PREFIX', '--prefix PREFIX', 'Capture file prefix.') {|v| opts[:p] = v} opt.on('-D DISPLAY', '--display DISPLAY', Integer, 'Capture from the display specified. -D 1 is main display, -D 2 secondary, etc.') {|v| opts[:d] = v} opt.on('-t TIME', '--time TIME', Integer, 'Recording time.') {|v| opts[:t] = v} opt.parse!(argv) cmd = Imageburst.new(opts) cmd.run end |
Instance Method Details
#run ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/imagetools/imageburst.rb', line 37 def run # 撮影時間 time = DEFAULAT_TIME if @opts[:t] time = @opts[:t] end # prefixの決定 prefix = Time.now.strftime("%Y%m%d_%H%M%S") if @opts[:p] prefix = @opts[:p] end # ディスプレイの設定 display = '' if @opts[:d] display = "-D#{@opts[:d]}" end # 現在時刻 current = Time.now # 終了時間 finish = current + time # 保存フォルダ(ベースフォルダの下に現在日付のフォルダを作成しその下に保存) # session = Time.now.strftime("%Y%m%d_%H%M%S") folder = File.(File.join(BASE_FOLDER, prefix)) if FileTest.directory?(folder) puts "Output folder already exists: #{folder}" exit(1) end Dir.mkdir(folder) while current < finish current = Time.now name = current.strftime("%s_%6N.jpg") path = File.join(folder, name) cmd = "screencapture #{display} #{path}" puts cmd system(cmd) end end |