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.
12345678910111213141516171819202122232425262728
#!/usr/bin/env ruby# encoding: utf-8require'fileutils'ifARGV.length<1puts"Usage"puts"1. ruby tools.rb cp_ss -> (Copy screenshot on Desktop to source/images and named with prefix of newest post's date)"exitendprefix=File.basename(Dir.glob("source/_posts/*.*")[-1]).split(/-/)[0..2].join("_")desktop=ENV['HOME']+"/Desktop/"Dir.entries(desktop).eachdo|file|ifFile.path(file).start_with?("Screen Shot")origin=desktop+File.path(file)index=1index+=1whileFile.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."elseputs"Skip."endendend