Skip to content

Instantly share code, notes, and snippets.

@mhayes
Last active August 29, 2015 14:22
Show Gist options
  • Select an option

  • Save mhayes/066ea78643ebcd4d2ef0 to your computer and use it in GitHub Desktop.

Select an option

Save mhayes/066ea78643ebcd4d2ef0 to your computer and use it in GitHub Desktop.

Revisions

  1. mhayes revised this gist Jun 9, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion renamer.rb
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    require "fileutils"
    names = %w{EXAMPLE_ONE EXAMPLE_TWO}
    sizes = %w{160x600-3 300x250-4 300x600-4 728x90-4}
    sizes = %w{160x600-4}
    expanded_sizes = sizes.map do |s|
    new_sizes = []
    size = s.split("-")
  2. mhayes created this gist Jun 9, 2015.
    15 changes: 15 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    # quickstart

    Let's assume you have OS X screenshots named like `Screen Shot 2015-06-09 at 9.39.56 AM.png`. You can use this script to rename them like so:

    ```bash
    mark:screens mark$ ruby renamer.rb
    move ./Screen Shot 2015-06-09 at 9.39.56 AM.png to EXAMPLE_ONE_160x600_1.png
    move ./Screen Shot 2015-06-09 at 9.39.57 AM.png to EXAMPLE_ONE_160x600_2.png
    move ./Screen Shot 2015-06-09 at 9.39.58 AM.png to EXAMPLE_ONE_160x600_3.png
    move ./Screen Shot 2015-06-09 at 9.40.00 AM.png to EXAMPLE_ONE_160x600_4.png
    move ./Screen Shot 2015-06-09 at 9.40.30 AM.png to EXAMPLE_TWO_160x600_1.png
    move ./Screen Shot 2015-06-09 at 9.40.31 AM.png to EXAMPLE_TWO_160x600_2.png
    move ./Screen Shot 2015-06-09 at 9.40.32 AM.png to EXAMPLE_TWO_160x600_3.png
    move ./Screen Shot 2015-06-09 at 9.40.34 AM.png to EXAMPLE_TWO_160x600_4.png
    ```
    28 changes: 28 additions & 0 deletions renamer.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    require "fileutils"
    names = %w{EXAMPLE_ONE EXAMPLE_TWO}
    sizes = %w{160x600-3 300x250-4 300x600-4 728x90-4}
    expanded_sizes = sizes.map do |s|
    new_sizes = []
    size = s.split("-")
    dims = size[0]
    variations = size[1].to_i
    variations.times do |i|
    new_sizes << "#{dims}_#{i+1}"
    end
    new_sizes
    end
    expanded_sizes.flatten!
    sizes = []
    names.each do |name|
    sizes << expanded_sizes.map {|size| "#{name}_#{size}"}
    end
    sizes.flatten!

    files = Dir.glob("./Screen*").sort_by {|pth| File.mtime(pth)}

    raise Exception unless sizes.length == files.length

    files.each_with_index do |path, idx|
    puts "move #{path} to #{sizes[idx]}.png"
    FileUtils.mv path, "#{sizes[idx]}.png"
    end