« [exiftool] exiftoolで取得したメタデータをHTML表示(少し修正) | トップページ | [bash]libwebpインストール »

[exiftool] exiftoolのhtmlDumpの内容をHTMLで保存する(画像系専用)


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
(* HTMLの保存先のデフォルトは再起動時に削除されるディレクトリですので
生成されたファイルを保存したい場合は別途保存してください
exiftoolのインストールはこちらをどうぞ
https://quicktimer.cocolog-nifty.com/icefloe/2024/01/post-e7e51d.html
*)
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application
set appFileManager to refMe's NSFileManager's defaultManager()

########################################
### 設定項目
### exiftoolへのパス
########################################
set strExifPath to "~/bin/exiftool/exiftool" as text

#
set ocidExifPathStr to refMe's NSString's stringWithString:(strExifPath)
set ocidExifPath to ocidExifPathStr's stringByStandardizingPath()
set ocidExifPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidExifPath) isDirectory:false)
set strExifPath to ocidExifPathURL's |path| as text

########################################
####出力先(再起動時に削除されます)
set ocidTemporaryDirPathURL to appFileManager's temporaryDirectory
set ocidVarFoldersDirURL to ocidTemporaryDirPathURL's URLByDeletingLastPathComponent()
set ocidTemporaryItemsPathURL to ocidVarFoldersDirURL's URLByAppendingPathComponent:"TemporaryItems"
##フォルダを作る
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
# 777-->511 755-->493 700-->448 766-->502
ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
set listDone to appFileManager's createDirectoryAtURL:(ocidTemporaryItemsPathURL) withIntermediateDirectories:(true) attributes:(ocidAttrDict) |error|:(reference)
set aliasTemporaryItems to (ocidTemporaryItemsPathURL's absoluteURL()) as alias
########################################
#######ファイル選択
#####ダイアログを前面に
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
##
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
set listUTI to {"public.image"}
set strPromptText to "ファイルを選んでください" as text
set strMesText to "ファイルを選んでください" as text
set aliasFilePath to (choose file strMesText with prompt strPromptText default location (aliasDefaultLocation) of type listUTI with invisibles without multiple selections allowed and showing package contents) as alias
####入力ファイル関連
set strFilePath to POSIX path of aliasFilePath as text
###NSストリングに
set ocidFilePath to refMe's NSString's stringWithString:(strFilePath)
###NSURLに
set ocidFilePathURL to refMe's NSURL's fileURLWithPath:(ocidFilePath)
##ファイル名取得
set strFileName to (ocidFilePathURL's lastPathComponent) as text
##コンテナ
set ocidContainerPathURL to ocidFilePathURL's URLByDeletingLastPathComponent()
set aliasContainerDirPath to (ocidContainerPathURL's absoluteURL()) as alias

########################################
######出力ファイル
##ファイル名
set strFileName to (strFileName & ".html") as text
set aliasSaveFilePath to (choose file name with prompt "htmlのファイル名を付けてください" default name strFileName default location aliasTemporaryItems) as «class furl»
set strSaveFilePath to (POSIX path of aliasSaveFilePath) as text
###NSストリングに
set ocidSaveFilePath to refMe's NSString's stringWithString:(strSaveFilePath)
###NSURLに
set ocidSaveFilePathURL to refMe's NSURL's fileURLWithPath:(ocidSaveFilePath)
##拡張子
set strFileExtension to (ocidSaveFilePathURL's pathExtension) as text
###拡張子つけ忘れ対策
if strFileExtension is not "html" then
  set strSaveFilePath to (POSIX path of aliasSaveFilePath & ".html") as text
end if

########################################
###【1】データ取得 JSON出力
try
  set theCommandText to ("\"" & strExifPath & "\" -htmlDump \"" & strFilePath & "\"") as text
  set strResponseHTML to (do shell script theCommandText) as text
on error
return "たぶんexiftoolの非対応のファイルタイプです"
end try
###【2】NSStringにテキストに格納して
set ocidHtmlDump to refMe's NSString's stringWithString:(strResponseHTML)

###ファイルに書き出し
set boolWritetoUrlArray to ocidHtmlDump's writeToFile:(strSaveFilePath) atomically:true encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)
(*
####テキストエディタで開く
log strSaveFilePath
tell application "TextEdit"
activate
open (POSIX file strSaveFilePath as alias)
end tell
*)
####サファリで開く
set strOpenURL to ocidSaveFilePathURL's absoluteString() as text
tell application "Safari"
activate
make new document with properties {name:"MDLS2HTMLv2"}
  tell window 1
open location strOpenURL
  end tell
end tell


|

« [exiftool] exiftoolで取得したメタデータをHTML表示(少し修正) | トップページ | [bash]libwebpインストール »

AppleScript EXIFData」カテゴリの記事