Welcome to FutureAppLaboratory

v=(*^ワ^*)=v

Copy Screenshots Easier

| Comments

When I need screenshot for blog post, I always use Mac’s default shortcuts to take them.
It’s super easy to do so. But Mac always store them on Desktop folder. So I have to copy it from Desktop folder to Octopress’s image folder. And the default name for the screenshot is a bit complicated to be managed.
So I write some script to make it easier.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env ruby
# encoding: utf-8

require 'fileutils'

if ARGV.length < 1
  puts "Usage"
  puts "1. ruby tools.rb cp_ss -> (Copy screenshot on Desktop to source/images and named with prefix of newest post's date)"
  exit
end

prefix = File.basename(Dir.glob("source/_posts/*.*")[-1]).split(/-/)[0..2].join("_")

desktop = ENV['HOME'] + "/Desktop/"
Dir.entries(desktop).each do |file|
  if File.path(file).start_with?("Screen Shot")
    origin = desktop + File.path(file)
    index = 1
    index += 1 while File.exist?(target = "source/images/%s_image%02d.png" % [prefix, index])
    puts "Copy %s -> source/images/\%s. Yes[Y] or No[N]" % [origin, target]
    if (/[yY]/ =~ STDIN.gets.chomp)
      FileUtils.mv(origin, target)
      puts "Done."
    else
      puts "Skip."
    end
  end
end

Comments