Skip to content

Instantly share code, notes, and snippets.

@amien8
Forked from redoPop/README.md
Created December 14, 2015 08:30
Show Gist options
  • Select an option

  • Save amien8/00aa8889ccecb56930fd to your computer and use it in GitHub Desktop.

Select an option

Save amien8/00aa8889ccecb56930fd to your computer and use it in GitHub Desktop.

Revisions

  1. @redoPop redoPop revised this gist Jun 10, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -2,4 +2,4 @@ At the time of writing, [Hazel's](http://www.noodlesoft.com/hazel.php) default d

    This script provides a custom date attribute reflecting the time the photo was actually taken. As written, it's intended to be added as an embedded script in a "Run JavaScript" rule action, so that it's custom attribute can be used in subsequent "Sort into subfolder" patterns.

    The date this script exposes is obtained via [`sips -g creation \[filename\]`](https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/sips.1.html). It's not clear to me exactly which EXIF attribute the sips "creation" property comes from, but it seems reasonable to assume it's either `DateTimeOriginal` or `DateTimeDigitized`.
    The date this script exposes is obtained via [`sips -g creation [filename]`](https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/sips.1.html). It's not clear to me exactly which EXIF attribute the sips "creation" property comes from, but it seems reasonable to assume it's either `DateTimeOriginal` or `DateTimeDigitized`.
  2. @redoPop redoPop revised this gist Jun 10, 2015. No changes.
  3. @redoPop redoPop created this gist Jun 10, 2015.
    5 changes: 5 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    At the time of writing, [Hazel's](http://www.noodlesoft.com/hazel.php) default date attributes all refer to an image file's creation date rather than the date on which the photo was originally taken. The two dates may differ.

    This script provides a custom date attribute reflecting the time the photo was actually taken. As written, it's intended to be added as an embedded script in a "Run JavaScript" rule action, so that it's custom attribute can be used in subsequent "Sort into subfolder" patterns.

    The date this script exposes is obtained via [`sips -g creation \[filename\]`](https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/sips.1.html). It's not clear to me exactly which EXIF attribute the sips "creation" property comes from, but it seems reasonable to assume it's either `DateTimeOriginal` or `DateTimeDigitized`.
    25 changes: 25 additions & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    var app = Application.currentApplication();
    app.includeStandardAdditions = true;

    var theDate = app.doShellScript(
    'sips -g creation ' +
    // Dragons below: Q&D shell escape:
    ('' + theFile).replace(/ /g, '\\ ')
    )
    // Parse SIPS output & extract date
    .match(/(\d{4}):(\d{2}):(\d{2}) (\d{2}):(\d{2}):(\d{2})/)
    .slice(1)
    // Q&D numberification of stringy dates
    .map(function (i) { return +i });

    // Offset the month by 1 because JavaScript
    theDate[1] -= 1;

    return {
    hazelOutputAttributes: [
    // Apply array of values to Date constructor
    new (Function.prototype.bind.apply(
    Date, [null].concat(theDate)
    ))
    ]
    };