iPhotoの複数の写真を(ほぼ自動で)まとめてEvernoteに取り込むスクリプト完成ã®PVã¯ã絶対æ°ããå°ãªããã©ãæ¯æ¥ä¸å®æ°ããã®ãè¦ã¦ããã¨ãç»åãã¼ã¿ãä¸æ¬ã§ã¾ã¨ãã¦Evernoteã«ç»é²ãããã¨ãããã¼ãºã¯ããã¨ããã®ãç¥ã£ã¦å°ãèªåã®ä¸ã®ã¢ããã¼ã·ã§ã³ãä¸ãã£ãã®ã¨ãã®å¾ã®ãã¨ãèãã¦å°ãä¿®æ£ãã¾ããã
ä¿®æ£ãããã¨æã£ãèæ¯ï¼ã¹ã¯ãªããã®ä¸èº«ãæ°ã«ãªã人ã¯ãã®é¨åèªã¿é£ã°ãã¦ãã ããï¼
ãããªã¹ã¯ãªãããèªåã§æ¸ãã¨ãã¦ãªãã ãã©ããã®ã¹ã¯ãªããå¦çãããã¾ã綺éºãããªãã£ã¦æ°æã¡æªããã§ãããã»ã»
æ°æã¡æªãã¨æãã¦ããã®ã¯
- iPhotoããã¢ã«ãã æ å ±ãHTMLã¨ãã¦çæãã¦ãããã©ãã¢ã«ãã æ å ±ãæ¸ãåºãã¨ãã®ãªãã·ã§ã³æå®ã«ãã£ã¦ã
HTMLãã¡ã¤ã«å ã«è¨è¼ããã¦ããåçã®æ®å½±æ¥ã®ä½ç½®ãããã
- Nokogiri使ã£ãå¦çãã¦ãããã©ããã使ããªãã£ã¦ãè¯ãããæ¹ãããã
ã¨ãããããã
ã§ããäºãªãã°ãMac OS X10.5 以ä¸ã§ã追å ã®gemãªããããå¯è½ãªéãå©ç¨ããªããããªå½¢ã§å®è¡ã§ããã»ãããå®éã«è©¦ã人ã«ã¨ã£ã¦ã¯æ·å±
ããããããããªã¨æã£ã¦ãã¾ãã
ãã¨ã¯æè§ãªã®ã§ãWindowsçã®ã¹ã¯ãªããï¼WSH+JScriptï¼ãæ¸ããããªã¼ã¨æã£ã¦ãã¦ããã®å ´åã«Nokogiriã®ãããªãã¼ãµã¼ä½¿ã£ãå¦çããã¦ãããã®ãWSH+JScriptåãã«ç§»æ¤ãã(*)ã¨ãªãã¨ãèããã ãã§ãå«ã«ãªããããªãã¹ãã·ã³ãã«ãªå½¢ã®å¦çã«ãã¦ãããã»ããå¾ã è¯ãããªã¨æã£ã¦ããããã¾ãã
ä¿®æ£ããã¹ã¯ãªãã
æ°æã¡æªãç¶æ ãå°ãã§ã解æ¶ããããã«ããããªå½¢ã§æ¸ãæãã¾ãããerbã§å©ç¨ãããã³ãã¬ã¼ãã¯iPhotoの複数の写真を(ほぼ自動で)まとめてEvernoteに取り込むスクリプト完成ã§æ¸ãããã®ããå ¨ãå¤æ´ããã¾ããã
## iphoto2evernote.rb require 'rubygems'require 'base64' require 'digest/md5' require 'erb' require 'extexif' class Images2Enex def initialize() @exif ={}; if ARGV[0].nil? exit! else @base_directory = ARGV[0] end end attr_accessor :evernote_created_date, :evernote_note_title,:evernote_hash, :imgdata def convert Dir::glob(@base_directory + "*.jpg").each{|f| _exif = ExtractExit(f) # JPEGã®ãã¡ã¤ã«åãEvernoteã®ãã¼ãã¿ã¤ãã«ã«æ´»ç¨ãã¤ã¤ # enexãã¡ã¤ã«ã®æ¸ãåºãã¨ãã®ãã¡ã¤ã«åã«ãæ´»ç¨ jpeg_filename = File.basename(f).split(".") output_filename = jpeg_filename[0] @imgdata = base64_encode(f) @evernote_note_title = output_filename @evernote_hash = make_hash(f) @evernote_created_date = convert_date_format(_exif["Date"]) template = File.open("evernote_enex01.tmpl") { |tmpl| tmpl.read } @result = ERB.new(template, nil, '-') begin make_enex(output_filename) rescue OpenURI::HTTPError => e e.io.close end } end private # Evernoteæå®ã®æ¥ä»ãã©ã¼ãããã§ããyyyymmddThhmmssZã«å¤æ def convert_date_format(str) separete_str = str.split(" ") each_date_element = separete_str[0].split(":") each_minutes_element = separete_str[1].split(":") return each_date_element[0] + each_date_element[1] + each_date_element[2] + "T" + each_minutes_element[0] + each_minutes_element[1] + each_minutes_element[2] + "Z" end def make_hash(file) return Digest::MD5.hexdigest(File.open(file,'rb').read) end def make_enex(file) f = File.open(@base_directory + file + ".enex","w") f.puts @result.result(binding) f.close end def base64_encode(jpeg) return Base64.encode64 File.open(jpeg).read end def ExtractExit(file) image = ExtExif.new(file) @exif = { "Maker" => image["Make"], "Width" => image["PixelXDimension"], "Height" => image["PixelYDimension"], "Aperture" => image["ApertureValue"], "Date" => image["DateTimeOriginal"], "FNum" => image["FNumber"] } return @exif end end i2e = Images2Enex.new() i2e.convert()
使ãæ¹
- iPhotoã§ç®¡çãã¦ããåçããé©å½ãªãã©ã«ãï¼ä»®ã«ãã¹ã¯ãããä¸ã®âphotoâã¨ãããã©ã«ãï¼ã«æ¸ãåºã
- ã¿ã¼ããã«ä¸ã§ãããªæãã§å®è¡ããã¨ãåçãæ¸ãåºãããã©ã«ãå ã«ãé çªã«enexãã¡ã¤ã«ãçæãããã®ã§ãã¨ã¯ãããEvernoteã«ã¤ã³ãã¼ãããã°OK
ruby ./iphoto2evernote.rb ~/Desktop/photo/
ä»åä¿®æ£ããä¸ã§ãæ°ã¥ããã®ã¯ãDir::globã使ã£ãå¦çããã¦ãããããªã®ã§ããã£ã¬ã¯ããªé ä¸ã®ãã¡ã¤ã«ååå¾ãªãããæ¬æ¥ç°¡åã«åºæ¥ãã¨æã£ã¦ãããã©ãã®ããããæ°ã«ãªã£ã¦ããã®ã§Ruby でファイル一覧の取得ã¨ãããµã¤ããåèã«ãã¦ãããã¹ãããªãã¾ããã
(*)JavaScriptでBase64エンコードする。 - ブックマクロ開発にã¨ããã¨ã³ããªãæè¿è¦ã¤ããããããããåèã«ããã°Base64ã¨ã³ã³ã¼ãåºæ¥ããã ãMD5を計算するライブラリãªãã£ã¦ããã®ãããã
ä¸çªãã£ãããªJPEGã®Exifæ
å ±ã®èªåã¯ãADODB.Streamãªãã¸ã§ã¯ãã使ã£ã¦å¦çãããããªãããã§こちらのlzhファイルの中にあったVBScriptファイルãåèã«ãªãããã ãã©ãèªã¿åã£ããã¤ããªãã¼ã¿ã®å¦ç大å¤ããã»ã»ã¨ãæã£ã¦ãããJavaScript だけで EXIF を読むã¨ããã¨ã³ããªã§EXIF ã®ã¿ã°å®ç¾©ãã¼ãã«ãåå¾ã£ã¦ãã辺ãã®ã³ã¡ã³ãæ¬ã®æ
å ±ãåèã«ãªãããã