AppleScript EXIFData

[exiftool]画像のダンプ(少し修正)


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

property refMe : a reference to current application



#####設定項目
####exiftoolへのパス
set strExifPath to "$HOME/bin/exiftool/exiftool"
########################################
#######前準備
##このファイルへのパスとコンテナ
tell application "Finder"
  set aliasPathToMe to (path to me) as alias
  set aliasPathToMeDir to (container of aliasPathToMe) as alias
end tell
set strPathToMePath to (POSIX path of aliasPathToMe) as text
set strPathToMeDirPath to (POSIX path of aliasPathToMeDir) as text
########################################
#######ファイル選択
---プロンプトの文言改行が使えます\nを入れます
set theWithPrompt to "ファイルを選択してください"
---ファイル選択ダイアログのデフォルトのディレクトリ
set aliasDefaultLocation to path to desktop folder from user domain
set theFileTypeList to {"public.image"}
---ダイアログを出して選択されたファイルは「open」に渡す
set aliasFilePath to (choose file default location aliasDefaultLocation ¬
  with prompt theWithPrompt ¬
  of type theFileTypeList ¬
invisibles false ¬
  with showing package contents without multiple selections allowed)
####入力ファイル関連
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 strFileName to (strFileName & ".html") as text
set aliasSaveFilePath to choose file name with prompt "保存するHTMLのファイル名を付けてください" default name strFileName default location (aliasDefaultLocation)
###パス
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
log strFileExtension
###拡張子つけ忘れ対策
if strFileExtension is not "html" then
  set strSaveFilePath to (strSaveFilePath & ".html") as text
end if
########################################
######データ処理
###データ取得
set theCommandText to ("\"" & strExifPath & "\" -htmlDump \"" & strFilePath & "\" > \"" & strSaveFilePath & "\"") as text
do shell script theCommandText

tell application "Finder"
open file aliasSaveFilePath
  
end tell
return


|

[exiftool]メタデータをHTML表示する(少し修正)


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

property refMe : a reference to current application

#####設定項目
####exiftoolへのパス
set strExifPath to "$HOME/bin/exiftool/exiftool"
########################################
#######前準備
##このファイルへのパスとコンテナ
tell application "Finder"
  set aliasPathToMe to (path to me) as alias
  set aliasPathToMeDir to (container of aliasPathToMe) as alias
end tell
set strPathToMePath to (POSIX path of aliasPathToMe) as text
set strPathToMeDirPath to (POSIX path of aliasPathToMeDir) as text
########################################
#######ファイル選択
---プロンプトの文言改行が使えます\nを入れます
set theWithPrompt to "ファイルを選択してください"
---ファイル選択ダイアログのデフォルトのディレクトリ
set aliasDefaultLocation to path to desktop folder from user domain
set theFileTypeList to {"public.item"}
---ダイアログを出して選択されたファイルは「open」に渡す
set aliasFilePath to (choose file default location aliasDefaultLocation ¬
  with prompt theWithPrompt ¬
  of type theFileTypeList ¬
invisibles false ¬
  with showing package contents without multiple selections allowed)
####入力ファイル関連
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 ocidContainerDirPathURL to ocidFilePathURL's URLByDeletingLastPathComponent()
########################################
######出力ファイル
##ファイル名
set strFileName to (strFileName & ".html") as text
set aliasSaveFilePath to choose file name with prompt "htmlのファイル名を付けてください" default name strFileName default location (ocidContainerDirPathURL as alias)
###パス
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

########################################
######データ処理
###データ取得
try
  set theCommandText to ("\"" & strExifPath & "\" -json \"" & strFilePath & "\"") as text
  set strResponseJosn to (do shell script theCommandText) as text
on error
log "たぶんexiftoolの非対応のファイルタイプです"
end try
###テキストに
set ocidReadDataJson to refMe's NSString's stringWithString:strResponseJosn
###UTF8データに
set ocidReadDataUTF to ocidReadDataJson's dataUsingEncoding:(refMe's NSUTF8StringEncoding)
###データ初期化
set ocidReadData to (refMe's NSData's alloc()'s initWithData:ocidReadDataUTF)
###JSON初期化
set listJSONSerialization to (refMe's NSJSONSerialization's JSONObjectWithData:ocidReadData options:0 |error|:(reference))
####レコードを取得します
set ocidJsonData to item 1 of listJSONSerialization
--> (*__NSSingleObjectArrayI*)
set ocidJsonDict to (item 1 of ocidJsonData)
--> (*__NSDictionaryI*)
####レコードをNSDictionaryとして格納
set ocidJsonResponse to (refMe's NSDictionary's alloc()'s initWithDictionary:ocidJsonDict)
########################################
#######HTML 基本構造
###スタイル
set strStylle to "<style>#bordertable {padding: 10px;width: 100%;margin: 0;border-collapse: collapse;border-spacing: 0;word-wrap: break-word;} #bordertable table { width: 580px;margin: 0px;padding: 0px;border: 0px;border-spacing:0px;border-collapse: collapse;} #bordertable caption { font-weight: 900;} #bordertable thead { font-weight: 600;border-spacing:0px;} #bordertable td {border: solid 1px #666666;padding: 3px;margin: 0px;word-wrap: break-word;border-spacing:0px;} #bordertable tr {border: solid 1px #666666;padding: 0px;margin: 0px;border-spacing:0px;} #bordertable th {border: solid 1px #666666;padding: 0px;margin: 0px;border-spacing:0px;}</style>"
###ヘッダー部
set strHead to "<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"utf-8\"><title>[Exif]" & strFileName & "</title>" & strStylle & "</head><body>"
###ボディ
set strBody to ""
###最後
set strHtmlEndBody to "</body></html>"
###HTML書き出し用のテキスト初期化
set ocidHTMLString to refMe's NSMutableString's alloc()'s initWithCapacity:0
####
(ocidHTMLString's appendString:strHead)
###テーブル構造
set strTableHeader to "<div id=\"bordertable\"><table><caption>Exif情報:" & strFileName & "</caption><thead title=\"表の項目について\"><tr><th title=\"項目の番号が最初\" style=\"width: 36px;\">項番</th><th title=\"キーの名前が2番目\">キーの名前</th><th title=\"キーの値は3番目になっています\">キーの値</th></thead><tbody title=\"表の始まりです\">" as text
(ocidHTMLString's appendString:strTableHeader)

####JSONの全てのキーを取得して
set ocidAllKeys to ocidJsonResponse's allKeys()
set numLineNO to 0
####キーの種類だけ繰り返し
repeat with objKey in ocidAllKeys
  set strKey to objKey as text
  ####キーの値を取り出し
  set strValue to (ocidJsonResponse's valueForKey:strKey) as text
  ####内容によって表示させるための分岐
  if strKey is "ExifToolVersion" then
    ###キーと値を保存
    set strHTMLTagFooterKey to strKey as text
    set strHTMLTagFooterValue to strValue as text
    ####例外処理
  else if strKey is "Directory" then
    set numLineNO to numLineNO + 1 as number
    set strHTMLTag to "<tr><td title=\"項番:" & strKey & "\">" & numLineNO & "</td><td title=\"キー:" & strKey & "について\">" & strKey & "</td><td title=\"キー:" & strKey & "の値\">非表示にしています</td></tr>" as text
  else if strKey is "SourceFile" then
    set numLineNO to numLineNO + 1 as number
    set strHTMLTag to "<tr><td title=\"項番:" & strKey & "\">" & numLineNO & "</td><td title=\"キー:" & strKey & "について\">" & strKey & "</td><td title=\"キー:" & strKey & "の値\">非表示にしています</td></tr>" as text
  else
    ###普通はこの処理
    set numLineNO to numLineNO + 1 as number
    set strHTMLTag to "<tr><td title=\"項番:" & strKey & "\">" & numLineNO & "</td><td title=\"キー:" & strKey & "について\">" & strKey & "</td><td title=\"キー:" & strKey & "の値\">" & strValue & "</td></tr>" as text
  end if
  ####できたタグを追加
(ocidHTMLString's appendString:strHTMLTag)
  
end repeat
###最後にバージョンを入れる
set numLineNO to numLineNO + 1 as number
###最後のtfoot項目
set strHTMLTagFooter to "</tbody><tfoot title=\"表の終わりです\"><tr><td title=\"項番:" & numLineNO & "\">" & numLineNO & "</td><td title=\"キーの名前\">ExifToolVersion</td><td title=\"キー:" & strHTMLTagFooterKey & "の値\">ExifTool:" & strHTMLTagFooterValue & "で作成しました</td></tr></tfoot></table></div>" as text
###タグを全部追加して
(ocidHTMLString's appendString:strHTMLTagFooter)
ocidHTMLString's appendString:strHtmlEndBody
###ファイルに書き出し
set boolWritetoUrlArray to ocidHTMLString's writeToFile:(strSaveFilePath) atomically:true encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)



set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
set ocidConfig to refMe's NSWorkspaceOpenConfiguration's configuration
(ocidConfig's setActivates:(refMe's NSNumber's numberWithBool:true))
ocidConfig's setHides:(refMe's NSNumber's numberWithBool:false)
##
##
(appSharedWorkspace's openURL:(ocidSaveFilePathURL) configuration:(ocidConfig) completionHandler:(missing value))



|

[mediaInfo] mediaInfoのHTML出力


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
# mediainfoのHTML出力をブラウザに表示
# mediainfoのインストール付きです
#mediainfoをインストールしたくない人は実行しないでください
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions
property refMe : a reference to current application

#############################
# mediaInfoインストールチェック
log doChkBinInstall()

#起動時に削除される項目
set ocidSaveDirPathURL to doMakeTmpDir()

#############################
# ダイアログ
doActivate()
set appFileManager to refMe's NSFileManager's defaultManager()
# デフォルトロケーション
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

############UTIリスト
set listUTI to {"public.item"}
set strMes to ("ファイルを選んでください") as text
set strPrompt to ("ファイルを選んでください") as text
try
  ### ファイル選択時
  set listAliasFilePath to (choose file strMes with prompt strPrompt default location aliasDefaultLocation of type listUTI with invisibles, multiple selections allowed and showing package contents) as list
on error
log "エラーしました"
return "エラーしました"
end try
if listAliasFilePath is {} then
return "選んでください"
end if


repeat with itemAliasFilePath in listAliasFilePath
  set strFilePath to POSIX path of itemAliasFilePath as text
  set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath))
  set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
  #
  set ocidFileName to (ocidFilePath's lastPathComponent())
  set ocidSaveFilePathURL to (ocidSaveDirPathURL's URLByAppendingPathComponent:(ocidFileName))
  set ocidSaveFilePathURL to (ocidSaveFilePathURL's URLByAppendingPathExtension:("html"))
  set strSaveFilePath to ocidSaveFilePathURL's |path| as text
  #
  set strCommandText to ("$HOME/bin/mediaInfo/mediainfo \"" & strFilePath & "\" --Output=HTML > \"" & strSaveFilePath & "\"") as text
do shell script strCommandText
  #
  set aliasSaveFilePath to (ocidSaveFilePathURL's absoluteURL()) as alias
  tell application "Finder"
    
open location aliasSaveFilePath
  end tell
  
end repeat


to doActivate()
  #############################
  ###ダイアログを前面に出す
  set strName to (name of current application) as text
  if strName is "osascript" then
    tell application "Finder" to activate
  else
    tell current application to activate
  end if
end doActivate


to doMakeTmpDir()
  #############################
  set appFileManager to refMe's NSFileManager's defaultManager()
  #起動時に削除される項目
  set ocidTempDirURL to appFileManager's temporaryDirectory()
  set ocidUUID to refMe's NSUUID's alloc()'s init()
  set ocidUUIDString to ocidUUID's UUIDString
  set ocidSaveDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:(true)
  set strSaveDirPath to (ocidSaveDirPathURL's |path|) as text
  set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
  set listDone to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
return ocidSaveDirPathURL
end doMakeTmpDir




to doChkBinInstall()
  #####################
  set appFileManager to refMe's NSFileManager's defaultManager()
  ###インストールチェック(システム)
  set strDefaultPath to ("/usr/local/bin/mediaInfo") as text
  set ocidDefaultPathStr to refMe's NSString's stringWithString:(strDefaultPath)
  set ocidDefaultPath to ocidDefaultPathStr's stringByStandardizingPath()
  set boolExists to appFileManager's fileExistsAtPath:(ocidDefaultPath) isDirectory:(false)
  if boolExists = true then
    set strCommandText to ("/bin/mkdir -p $HOME/bin/mediaInfo") as text
do shell script strCommandText
    set strCommandText to ("/bin/chmod 700 $HOME/bin") as text
do shell script strCommandText
    set strCommandText to ("/bin/ln -s \"" & strDefaultPath & "\" $HOME/bin/mediaInfo") as text
do shell script strCommandText
return "インストール済みなので処理しない"
  else if boolExists = false then
    ###インストールチェック(ユーザー)
    set strDefaultPath to ("~/bin/mediaInfo/mediaInfo") as text
    set ocidDefaultPathStr to refMe's NSString's stringWithString:(strDefaultPath)
    set ocidDefaultPath to ocidDefaultPathStr's stringByStandardizingPath()
    set boolExists to appFileManager's fileExistsAtPath:(ocidDefaultPath) isDirectory:(false)
    if boolExists = true then
log "インストール済み"
    else if boolExists = false then
log "インストールします"
return doInstall()
    end if
  end if
end doChkBinInstall



to doInstall()
  #####################
  set appFileManager to refMe's NSFileManager's defaultManager()
  ###設定項目
  set strURL to ("https://mediaarea.net/download/binary/mediainfo/24.01.1/MediaInfo_CLI_24.01.1_Mac.dmg") as text
  set strInstallDirName to ("mediaInfo") as text
  #####################
  ###インストール先確保
  set ocidUserName to refMe's NSUserName()
  set ocidHomeDirURL to appFileManager's homeDirectoryForUser:(ocidUserName)
  set ocidBinDirPathURL to ocidHomeDirURL's URLByAppendingPathComponent:("bin") isDirectory:(true)
  set ocidInstallDirPathURL to ocidBinDirPathURL's URLByAppendingPathComponent:(strInstallDirName) isDirectory:(true)
  ###
  set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
  set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidInstallDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
  #####################
  ###ダウンロードディレクトリ
  set ocidTempDirURL to appFileManager's temporaryDirectory()
  set ocidUUID to refMe's NSUUID's alloc()'s init()
  set ocidUUIDString to ocidUUID's UUIDString
  set ocidSaveDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:(true)
  set strSaveDirPath to ocidSaveDirPathURL's |path| as text
  ###
  set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
  #####################
  #ダウンロードするファイル名を確定させる
  set strCommandText to ("/usr/bin/curl -s -L -I -o /dev/null -w '%{url_effective}' \"" & strURL & "\" | /usr/bin/rev | /usr/bin/cut -d'/' -f1 | /usr/bin/rev") as text
  set strInstallerFileName to (do shell script strCommandText) as text
  #
  set ocidInstallerFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strInstallerFileName) isDirectory:(false)
  set strInstallerFilePath to (ocidInstallerFilePathURL's |path|) as text
  #####################
  #ダウンロード
  set strCommandText to ("/usr/bin/curl -L -o \"" & strInstallerFilePath & "\" \"" & strURL & "\" --http1.1 --connect-timeout 20") as text
do shell script strCommandText
  #####################
  #DMGをシャドウでマウント
  #マウントポイントを作成
  set ocidMountPointDirPathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:("MountPoint/DmgMount") isDirectory:(true)
  set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidMountPointDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
  set strMountPointDirPath to (ocidMountPointDirPathURL's |path|) as text
  #マウント
  set strCommandText to ("/usr/bin/hdiutil attach \"" & strInstallerFilePath & "\" -noverify -nobrowse -noautoopen -mountpoint \"" & strMountPointDirPath & "\"") as text
do shell script strCommandText
  #####################
  #マウントされたディスクからPKGのパスを取得
  set ocidOption to (refMe's NSDirectoryEnumerationSkipsSubdirectoryDescendants)
  set ocidPropertiesForKeysArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
ocidPropertiesForKeysArray's addObject:(refMe's NSURLNameKey)
ocidPropertiesForKeysArray's addObject:(refMe's NSURLPathKey)
  set listDone to appFileManager's contentsOfDirectoryAtURL:(ocidMountPointDirPathURL) includingPropertiesForKeys:(ocidPropertiesForKeysArray) options:(ocidOption) |error|:(reference)
  set ocidContentsURLArray to (item 1 of listDone)
  repeat with itemArray in ocidContentsURLArray
    #
    set strExtension to itemArray's pathExtension() as text
    if strExtension is "pkg" then
      set ocidPkgFilePathURL to itemArray
      exit repeat
    end if
  end repeat
  ##
  set strPkgFilePathURL to ocidPkgFilePathURL's |path| as text
  #####################
  set ocidExpandDirPathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:("Expand") isDirectory:(true)
  set strExpandDirPath to (ocidExpandDirPathURL's |path|) as text
  #PKGを解凍
  set theComandText to ("/usr/sbin/pkgutil --expand \"" & strPkgFilePathURL & "\" \"" & strExpandDirPath & "\"") as text
do shell script theComandText
  #####################
  #ディスクをアンマウント
  set theComandText to ("/usr/bin/hdiutil detach \"" & strMountPointDirPath & "\" -force") as text
do shell script theComandText
  #####################
  set ocidPayloadFilePathURL to ocidExpandDirPathURL's URLByAppendingPathComponent:("Payload") isDirectory:(true)
  set strPayloadFilePath to (ocidPayloadFilePathURL's |path|) as text
  #
  set ocidExtractDirPathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:("Extract") isDirectory:(true)
  set strExtractDirPath to (ocidExtractDirPathURL's |path|) as text
  #Payloadを解凍
  set theComandText to ("/usr/bin/ditto -xz \"" & strPayloadFilePath & "\" \"" & strExtractDirPath & "\"") as text
do shell script theComandText
  #####################
  #ここからは案件毎にカスタマイズ
  set ocidOriginalPathURL to ocidExtractDirPathURL's URLByAppendingPathComponent:("usr/local/bin/mediainfo") isDirectory:(false)
  set strOriginalPath to (ocidOriginalPathURL's |path|) as text
  #
  set ocidBinDistPathURL to ocidInstallDirPathURL's URLByAppendingPathComponent:("mediainfo") isDirectory:(false)
  set strBinDistPath to (ocidBinDistPathURL's |path|) as text
  #
  try
    set theComandText to ("/bin/mv -f \"" & strOriginalPath & "\" \"" & strBinDistPath & "\"") as text
do shell script theComandText
return true
  on error
return false
  end try
end doInstall




|

[exiftool] exiftool2html 修正(mscOS14.4対応)


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
# 【留意事項】
# インストールされていない場合インストール処理をします
# exiftoolをインストールしたくない人は実行しないでください
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use framework "UniformTypeIdentifiers"
use scripting additions

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

########################################
### exiftool インストールチェック 基本
########################################
set strBinPathDefault to ("/usr/local/bin/exiftool/exiftool") as text
set ocidBinFilePathStr to refMe's NSString's stringWithString:(strBinPathDefault)
set ocidBinFilePath to ocidBinFilePathStr's stringByStandardizingPath()
#
set boolDirExists to appFileManager's fileExistsAtPath:(ocidBinFilePath) isDirectory:(false)
if boolDirExists is true then
log "基本ディレクトリにインストール済み"
  set strBinPath to ocidBinFilePath as text
else if boolDirExists is false then
  set strBinPathDefault to ("~/bin/exiftool/exiftool") as text
  set ocidBinFilePathStr to refMe's NSString's stringWithString:(strBinPathDefault)
  set ocidBinFilePath to ocidBinFilePathStr's stringByStandardizingPath()
  set boolDirExists to appFileManager's fileExistsAtPath:(ocidBinFilePath) isDirectory:(false)
  if boolDirExists is true then
log "ユーザーディレクトリにインストール済み"
    set strBinPath to ocidBinFilePath as text
  else if boolDirExists is false then
doInstallBin()
    set strBinPath to ocidBinFilePath as text
  end if
end if

########################################
####出力先/var/folders/XX/(再起動時に削除されます)
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
ocidAttrDict's setValue:(511) 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
##
set strSetValue to ("このディレクトリ内は再起動時に自動で削除されます") as text
set strTmpFileName to ("_起動時削除されるフォルダ") as text
set ocidTmpFileStr to refMe's NSString's stringWithString:(strSetValue)
set ocidTmpFilePathURL to ocidTemporaryItemsPathURL's URLByAppendingPathComponent:(strTmpFileName)
set listDone to ocidTmpFileStr's writeToURL:(ocidTmpFilePathURL) atomically:(true) encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)


########################################
#######ファイル選択
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 ocidHomeDirURL to appFileManager's homeDirectoryForCurrentUser()
#デスクトップの場合
set ocidDefaultLocationURL to ocidHomeDirURL's URLByAppendingPathComponent:("Desktop") isDirectory:true
#ダウンロードフォルダの場合
#set ocidDefaultLocationURL to ocidHomeDirURL's URLByAppendingPathComponent:("Downloads") isDirectory:true
#フォントフォルダの場合
#set ocidDefaultLocationURL to ocidHomeDirURL's URLByAppendingPathComponent:("Library/Fonts") isDirectory:true
#エイリアスパスにする
set aliasDefaultLocation to (ocidDefaultLocationURL's absoluteURL()) as alias
set listUTI to {"public.item"}
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 strSaveFileName to (strFileName & ".html") as text
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
set aliasSaveFilePath to (choose file name with prompt "htmlのファイル名を付けてください" default name strSaveFileName 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
set strErrorFilePath to (strSaveFilePath & ".json") as text

########################################
###【1】データ取得 JSON出力

try
  set strCommandText to ("\"" & strBinPath & "\" -json \"" & strFilePath & "\"") as text
  set strResponseJosn to (do shell script strCommandText) as text
on error
  try
    set strCommandText to ("\"" & strBinPath & "\" -json \"" & strFilePath & "\" > \"" & strErrorFilePath & "\"") as text
    set strResponseJosn to (do shell script strCommandText) as text
  on error
    set strCommandText to ("/bin/cat \"" & strErrorFilePath & "\"") as text
    set strResponseJosn to (do shell script strCommandText) as text
log "たぶんexiftoolの非対応のファイルタイプですA"
  end try
end try
if strResponseJosn is "" then
return "たぶんexiftoolの非対応のファイルタイプですB"
end if
###【2】NSStringにテキストに格納して
set ocidReadDataJson to refMe's NSString's stringWithString:strResponseJosn
###【3】NSConcreteMutableDataに変換
set ocidReadDataUTF to ocidReadDataJson's dataUsingEncoding:(refMe's NSUTF8StringEncoding)
###【4】NSInlineDataデータ初期化
set ocidReadData to (refMe's NSData's alloc()'s initWithData:(ocidReadDataUTF))
###【5】NSJSONSerialization
set listJSONSerialization to (refMe's NSJSONSerialization's JSONObjectWithData:ocidReadData options:0 |error|:(reference))
set ocidJsonData to (item 1 of listJSONSerialization)
-->(*__NSSingleObjectArrayI*)
####解説
(*
exiftoolの書き出すJSONはrootがArray構造から始まっているので
PlistにするにはDictに変換なりする必要がある
幸い『[{}]』といったシングルArray構造なので
Arrayから最初のOBJECTを取り出せばDICTレコード構造になる
*)
set ocidJsonDict to (ocidJsonData's firstObject())
-->(*__NSDictionaryI*)
###【6】レコードをNSDictionaryとして格納
set ocidJsonDict to (refMe's NSDictionary's alloc()'s initWithDictionary:ocidJsonDict)
#AllKeys
set ocidAllKeyArray to ocidJsonDict's allKeys()
#並び替えソート
set ocidAllKeySortedArray to ocidAllKeyArray's sortedArrayUsingSelector:("localizedStandardCompare:")

##############################
# XML 生成開始
##############################
#XML初期化
set ocidXMLDoc to refMe's NSXMLDocument's alloc()'s init()
ocidXMLDoc's setDocumentContentKind:(refMe's NSXMLDocumentHTMLKind)
# DTD付与
set ocidDTD to refMe's NSXMLDTD's alloc()'s init()
ocidDTD's setName:("html")
ocidXMLDoc's setDTD:(ocidDTD)
# XML主要部分を生成
set strTitleText to ("【ExifTool】: " & strFileName & " :メタデータ一覧") as text
set ocidRootElement to doMakeRootElement(strTitleText)
#ボディエレメント
set ocidBodyElement to refMe's NSXMLElement's elementWithName:("body")
#ヘッダー
set ocidHeaderElement to refMe's NSXMLElement's elementWithName:("header")
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("id") stringValue:("header")
ocidHeaderElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("class") stringValue:("body_header")
ocidHeaderElement's addAttribute:(ocidAddNode)
ocidBodyElement's addChild:(ocidHeaderElement)
#アーティクル
set ocidArticleElement to refMe's NSXMLElement's elementWithName:("article")
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("id") stringValue:("article")
ocidArticleElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("class") stringValue:("body_article")
ocidArticleElement's addAttribute:(ocidAddNode)
ocidBodyElement's addChild:(ocidArticleElement)
#フッター
set ocidFooterElement to refMe's NSXMLElement's elementWithName:("footer")
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("id") stringValue:("footer")
ocidFooterElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("class") stringValue:("body_footer")
ocidFooterElement's addAttribute:(ocidAddNode)
#リンク付与(不要なら削除可)
set ocidAElement to refMe's NSXMLElement's elementWithName:("a")
set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("href") stringValue:("https://quicktimer.cocolog-nifty.com/"))
(ocidAElement's addAttribute:(ocidAddNode))
set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("target") stringValue:("_blank"))
(ocidAElement's addAttribute:(ocidAddNode))
set strContents to ("AppleScriptで生成しました") as text
(ocidAElement's setStringValue:(strContents))
ocidFooterElement's addChild:(ocidAElement)
ocidBodyElement's addChild:(ocidFooterElement)

##############################
# TABLE コンテンツ部分生成開始
##############################
#テーブル部生成開始
set ocidTableElement to refMe's NSXMLElement's elementWithName:("table")
###【caption】
set ocidCaptionElement to refMe's NSXMLElement's elementWithName:("caption")
ocidCaptionElement's setStringValue:(strTitleText)
ocidTableElement's addChild:(ocidCaptionElement)
###【colgroup】
set ocidColgroupElement to refMe's NSXMLElement's elementWithName:("colgroup")
#テーブルのタイトル部
set listColName to {"行番号", "項目名", "値"} as list
#タイトル部の数だけ繰り返し
repeat with itemColName in listColName
  ###【col】col生成
  set ocidAddElement to (refMe's NSXMLElement's elementWithName:("col"))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:(itemColName))
(ocidAddElement's addAttribute:(ocidAddNode))
(ocidColgroupElement's addChild:(ocidAddElement))
end repeat
#テーブルエレメントに追加
ocidTableElement's addChild:(ocidColgroupElement)
###【thead】
set ocidTheadElement to refMe's NSXMLElement's elementWithName:("thead")
#TR
set ocidTrElement to refMe's NSXMLElement's elementWithName:("tr")
#タイトル部の数だけ繰り返し
repeat with itemColName in listColName
  #ここはTDではなくてTHを利用
  set ocidAddElement to (refMe's NSXMLElement's elementWithName:("th"))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:(itemColName))
(ocidAddElement's addAttribute:(ocidAddNode))
  #値を入れる
(ocidAddElement's setStringValue:(itemColName))
  #TH→TRにセット
(ocidTrElement's addChild:(ocidAddElement))
end repeat
#TRをTHEADにセット
ocidTheadElement's addChild:(ocidTrElement)
#THEADをテーブルにセット
ocidTableElement's addChild:(ocidTheadElement)
###【tbody】
set ocidTbodyElement to refMe's NSXMLElement's elementWithName:("tbody")
#行番号
set numCntLineNo to 1 as integer
#ファイルのパスの数だけ繰り返し
repeat with itemKeyName in ocidAllKeySortedArray
  #TRの開始
  set ocidTrElement to (refMe's NSXMLElement's elementWithName:("tr"))
  #【行番号】をTHでセット
  set strZeroSupp to ("00") as text
  set strZeroSupp to ("00" & numCntLineNo) as text
  set strLineNO to (text -3 through -1 of strZeroSupp) as text
  set ocidThElement to (refMe's NSXMLElement's elementWithName:("th"))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("行番号"))
(ocidThElement's addAttribute:(ocidAddNode))
(ocidThElement's setStringValue:(strLineNO))
(ocidTrElement's addChild:(ocidThElement))
  #【項目名=KEY名】をTDでセット
  set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td"))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("項目名"))
(ocidTdElement's setStringValue:(itemKeyName))
(ocidTdElement's addAttribute:(ocidAddNode))
  #TDをTRにセット
(ocidTrElement's addChild:(ocidTdElement))
  #【値=Value】TD
  #値の取得
  set ocidValue to (ocidJsonDict's valueForKey:(itemKeyName))
  set strValueClass to className() of ocidValue as text
  set strValue to "" as text
  if strValueClass contains "Array" then
    set strValue to (ocidValue's componentsJoinedByString:(", "))
  else
    set strValue to ocidValue as text
  end if
  #
  set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td"))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("値"))
(ocidTdElement's setStringValue:(strValue))
(ocidTdElement's addAttribute:(ocidAddNode))
  #TDをTRにセット
(ocidTrElement's addChild:(ocidTdElement))
  #出来上がったTRをTBODYにセット
(ocidTbodyElement's addChild:(ocidTrElement))
  #
  set numCntLineNo to (numCntLineNo + 1) as integer
end repeat
#TBODYをテーブルにセット
ocidTableElement's addChild:(ocidTbodyElement)
###【tfoot】 TRで
set ocidTfootElement to refMe's NSXMLElement's elementWithName:("tfoot")
set ocidTrElement to refMe's NSXMLElement's elementWithName:("tr")
#項目数を取得して
set numCntCol to (count of listColName) as integer
#colspan指定して1行でセット
set ocidThElement to (refMe's NSXMLElement's elementWithName:("th"))
set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("テーブルの終わり"))
(ocidThElement's addAttribute:(ocidAddNode))
set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("colspan") stringValue:(numCntCol as text))
(ocidThElement's addAttribute:(ocidAddNode))
set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("scope") stringValue:("row"))
(ocidThElement's addAttribute:(ocidAddNode))
#項目キーの数
set numCntKey to (count of ocidAllKeySortedArray) as integer
set strValue to ("メタデータの数は:" & numCntKey & " 件でした") as text
ocidThElement's setStringValue:(strValue)
#THをTRにセットして
ocidTrElement's addChild:(ocidThElement)
#TRをTFOOTにセット
ocidTfootElement's addChild:(ocidTrElement)
#TFOOTをテーブルにセット
ocidTableElement's addChild:(ocidTfootElement)
# 出来上がったテーブルをArticleエレメントにセット
ocidArticleElement's addChild:(ocidTableElement)
#ルートエレメントにセット
ocidRootElement's addChild:(ocidBodyElement)
##############################
# TABLE
##############################
#ROOTエレメントをXMLにセット
ocidXMLDoc's setRootElement:(ocidRootElement)
#読み取りやすい表示
set ocidXMLdata to ocidXMLDoc's XMLDataWithOptions:(refMe's NSXMLNodePrettyPrint)
#保存
set listDone to ocidXMLdata's writeToURL:(ocidSaveFilePathURL) options:(refMe's NSDataWritingAtomic) |error|:(reference)
#保存先を開く
set ocidContainerDirPathURL to ocidSaveFilePathURL's URLByDeletingLastPathComponent()
set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
set boolDone to appSharedWorkspace's openURL:(ocidContainerDirPathURL)
(*
####テキストエディタで開く
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 {URL:strOpenURL}
  tell front window
activate
  end tell
end tell
####




##############################
# 基本的なHTMLの構造
##############################
to doMakeRootElement(argStrTitleText)
  set strTitleText to argStrTitleText as text
  #
  set ocidRootElement to refMe's NSXMLElement's elementWithName:("html")
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("lang") stringValue:("ja")
ocidRootElement's addAttribute:(ocidAddNode)
  #
  set ocidHeadElement to refMe's NSXMLElement's elementWithName:("head")
  #
  set ocidAddElement to refMe's NSXMLElement's elementWithName:("title")
ocidAddElement's setStringValue:(strTitleText)
ocidHeadElement's addChild:(ocidAddElement)
  # http-equiv
  set ocidAddElement to refMe's NSXMLElement's elementWithName:("meta")
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("http-equiv") stringValue:("Content-Type")
ocidAddElement's addAttribute:(ocidAddNode)
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("content") stringValue:("text/html; charset=UTF-8")
ocidAddElement's addAttribute:(ocidAddNode)
ocidHeadElement's addChild:(ocidAddElement)
  #
  set ocidAddElement to refMe's NSXMLElement's elementWithName:("meta")
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("http-equiv") stringValue:("Content-Style-Type")
ocidAddElement's addAttribute:(ocidAddNode)
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("content") stringValue:("text/css")
ocidAddElement's addAttribute:(ocidAddNode)
ocidHeadElement's addChild:(ocidAddElement)
  #
  set ocidAddElement to refMe's NSXMLElement's elementWithName:("meta")
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("http-equiv") stringValue:("Content-Script-Type")
ocidAddElement's addAttribute:(ocidAddNode)
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("content") stringValue:("text/javascript")
ocidAddElement's addAttribute:(ocidAddNode)
ocidHeadElement's addChild:(ocidAddElement)
  #
  set ocidAddElement to refMe's NSXMLElement's elementWithName:("meta")
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("name") stringValue:("viewport")
ocidAddElement's addAttribute:(ocidAddNode)
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("content") stringValue:("width=720")
ocidAddElement's addAttribute:(ocidAddNode)
ocidHeadElement's addChild:(ocidAddElement)
  #
  set ocidAddElement to refMe's NSXMLElement's elementWithName:("style")
ocidAddElement's setStringValue:("body { margin: 10px; background-color: #FFFFFF; } table { border-spacing: 0; caption-side: top; font-family: system-ui; } thead th { border: solid 1px #666666; padding: .5ch 1ch; border-block-width: 1px 0; border-inline-width: 1px 0; &:first-of-type { border-start-start-radius: .5em } &:last-of-type { border-start-end-radius: .5em; border-inline-end-width: 1px } } tbody td { word-wrap: break-word;max-width: 360px;border-spacing: 0; border: solid 1px #666666; padding: .5ch 1ch; border-block-width: 1px 0; border-inline-width: 1px 0; &:last-of-type { border-inline-end-width: 1px } } tbody th { border-spacing: 0; border: solid 1px #666666; padding: .5ch 1ch; border-block-width: 1px 0; border-inline-width: 1px 0; } tbody tr:nth-of-type(odd) { background: #F2F2F2; } .kind_string { font-size: 0.75em; } .date_string { font-size: 0.5em; } tfoot th { border: solid 1px #666666; padding: .5ch 1ch; &:first-of-type { border-end-start-radius: .5em } &:last-of-type { border-end-end-radius: .5em; border-inline-end-width: 1px } }")
ocidHeadElement's addChild:(ocidAddElement)
  #
ocidRootElement's addChild:(ocidHeadElement)
  #
return ocidRootElement
end doMakeRootElement


##############################
# exiftoolインストール
##############################
to doInstallBin()
  set strVerURL to ("https://exiftool.org/ver.txt") as text
  set strInstrallDirPath to ("~/bin/exiftool") as text
  ###インストール先
  set ocidInstrallDirPathStr to refMe's NSString's stringWithString:(strInstrallDirPath)
  set ocidInstrallDirPath to ocidInstrallDirPathStr's stringByStandardizingPath()
  set ocidInstrallDirPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidInstrallDirPath) isDirectory:true)
  ###フォルダを作る
  set appFileManager to refMe's NSFileManager's defaultManager()
  set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
  set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidInstrallDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
  set strInstrallDirPath to (ocidInstrallDirPathURL's |path|()) as text
  ###バージョンテキストURL
  set ocidVerURLStr to refMe's NSString's stringWithString:(strVerURL)
  set ocidVerURL to refMe's NSURL's alloc()'s initWithString:(ocidVerURLStr)
  set ocidVerText to refMe's NSString's stringWithContentsOfURL:(ocidVerURL) encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)
  set strVer to (item 1 of ocidVerText) as text
  ###URLとファイル名の整形
  set strDmgName to ("ExifTool-" & strVer & ".dmg") as text
  set strPkgName to ("ExifTool-" & strVer & ".pkg") as text
  set strVoluemPath to ("/Volumes/ExifTool-" & strVer & "") as text
  set strPkgPath to ("" & strVoluemPath & "/" & strPkgName & "/Contents/Archive.pax.gz") as text
  set strURL to ("https://exiftool.org/" & strDmgName & "") as text
  set ocidURLStr to refMe's NSString's stringWithString:(strURL)
  set ocidURL to refMe's NSURL's alloc()'s initWithString:(ocidURLStr)
  ###ダウンロードディレクトリ
  set appFileManager to refMe's NSFileManager's defaultManager()
  set ocidTempDirURL to appFileManager's temporaryDirectory()
  set ocidUUID to refMe's NSUUID's alloc()'s init()
  set ocidUUIDString to ocidUUID's UUIDString
  set ocidSaveDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:true
  ###フォルダを作る
  set appFileManager to refMe's NSFileManager's defaultManager()
  set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
  set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
  ###保存URL
  set ocidSaveDmgFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strDmgName)
  set strSaveDmgFilePathURL to (ocidSaveDmgFilePathURL's |path|()) as text
  ###ダウンロード
  set ocidOption to refMe's NSDataReadingMappedAlways
  set listDone to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidURL) options:(ocidOption) |error|:(reference)
  set ocidDmgData to (item 1 of listDone)
  ###保存
  set ocidOption to refMe's NSDataWritingAtomic
  set listDone to ocidDmgData's writeToURL:(ocidSaveDmgFilePathURL) options:(ocidOption) |error|:(reference)
log item 1 of listDone
  ####ディスクイメージマウント
strSaveDmgFilePathURL
  set strCommandText to ("/usr/bin/hdiutil attach \"" & strSaveDmgFilePathURL & "\" -noverify -nobrowse -noautoopen") as text
do shell script strCommandText
  ###解凍先ディレクトリを作成
  set ocidExpandPkgDirPathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:("Expand")
  set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
  set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidExpandPkgDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
  set strExpandPkgDirPathURL to (ocidExpandPkgDirPathURL's |path|()) as text
  ###解凍
  set strCoommandText to "/usr/bin/bsdtar -xzf \"" & strPkgPath & "\" -C \"" & strExpandPkgDirPathURL & "\"" as text
do shell script strCoommandText
  ###ディスクイメージアンマウンド
  set strCoommandText to "/usr/bin/hdiutil detach \"" & strVoluemPath & "\" -force" as text
do shell script strCoommandText
  ###ユーザーディレクトリにコピー
  set ocidDittoDirPathURL to ocidExpandPkgDirPathURL's URLByAppendingPathComponent:("usr/local/bin")
  set strDittoDirPathURL to (ocidDittoDirPathURL's |path|()) as text
  set strCoommandText to "/usr/bin/ditto \"" & strDittoDirPathURL & "\" \"" & strInstrallDirPath & "\"" as text
do shell script strCoommandText
end doInstallBin


|

[exiftool]Exif2HTMLv3 exiftoolのExif情報をHTMLで表示する。 exiftoolインストール付き(たいぶ修正)


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
# インストールされていない場合インストール処理をします
# exiftoolをインストールしたくない人は実行しないでください
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use framework "UniformTypeIdentifiers"
use scripting additions

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

########################################
### 設定項目
### exiftoolへのパス
########################################
#一般的にはパスはこちら
# set strExifPath to "/usr/local/bin/exiftool/exiftool" as text
#自分用
set strExifPath to "~/bin/exiftool/exiftool" as text


#exiftoolパス処理
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 boolDirExists to appFileManager's fileExistsAtPath:(ocidExifPath) isDirectory:(false)
if boolDirExists = true then
log "インストール済み"
else if boolDirExists = false then
log "インストールされていません"
doInstallBin()
end if

########################################
####出力先/var/folders/XX/(再起動時に削除されます)
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
ocidAttrDict's setValue:(511) 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 ocidHomeDirURL to appFileManager's homeDirectoryForCurrentUser()
#デスクトップの場合
set ocidDefaultLocationURL to ocidHomeDirURL's URLByAppendingPathComponent:("Desktop") isDirectory:true
#ダウンロードフォルダの場合
#set ocidDefaultLocationURL to ocidHomeDirURL's URLByAppendingPathComponent:("Downloads") isDirectory:true
#フォントフォルダの場合
#set ocidDefaultLocationURL to ocidHomeDirURL's URLByAppendingPathComponent:("Library/Fonts") isDirectory:true
#エイリアスパスにする
set aliasDefaultLocation to (ocidDefaultLocationURL's absoluteURL()) as alias
set listUTI to {"public.item"}
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 strSaveFileName to (strFileName & ".html") as text
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
set aliasSaveFilePath to (choose file name with prompt "htmlのファイル名を付けてください" default name strSaveFileName 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
set strErrorFilePath to (strSaveFilePath & ".json") as text

########################################
###【1】データ取得 JSON出力
try
  set strCommandText to ("\"" & strExifPath & "\" -json \"" & strFilePath & "\"") as text
  set strResponseJosn to (do shell script strCommandText) as text
on error
  try
    set strCommandText to ("\"" & strExifPath & "\" -json \"" & strFilePath & "\" > \"" & strErrorFilePath & "\"") as text
    set strResponseJosn to (do shell script strCommandText) as text
  on error
    set strCommandText to ("/bin/cat \"" & strErrorFilePath & "\"") as text
    set strResponseJosn to (do shell script strCommandText) as text
log "たぶんexiftoolの非対応のファイルタイプですA"
  end try
end try
if strResponseJosn is "" then
return "たぶんexiftoolの非対応のファイルタイプですB"
end if
###【2】NSStringにテキストに格納して
set ocidReadDataJson to refMe's NSString's stringWithString:strResponseJosn
###【3】NSConcreteMutableDataに変換
set ocidReadDataUTF to ocidReadDataJson's dataUsingEncoding:(refMe's NSUTF8StringEncoding)
###【4】NSInlineDataデータ初期化
set ocidReadData to (refMe's NSData's alloc()'s initWithData:(ocidReadDataUTF))
###【5】NSJSONSerialization
set listJSONSerialization to (refMe's NSJSONSerialization's JSONObjectWithData:ocidReadData options:0 |error|:(reference))
set ocidJsonData to (item 1 of listJSONSerialization)
-->(*__NSSingleObjectArrayI*)
####解説
(*
exiftoolの書き出すJSONはrootがArray構造から始まっているので
PlistにするにはDictに変換なりする必要がある
幸い『[{}]』といったシングルArray構造なので
Arrayから最初のOBJECTを取り出せばDICTレコード構造になる
*)
set ocidJsonDict to (ocidJsonData's firstObject())
-->(*__NSDictionaryI*)
###【6】レコードをNSDictionaryとして格納
set ocidJsonDict to (refMe's NSDictionary's alloc()'s initWithDictionary:ocidJsonDict)
#AllKeys
set ocidAllKeyArray to ocidJsonDict's allKeys()
#並び替えソート
set ocidAllKeySortedArray to ocidAllKeyArray's sortedArrayUsingSelector:("localizedStandardCompare:")

##############################
# XML 生成開始
##############################
#XML初期化
set ocidXMLDoc to refMe's NSXMLDocument's alloc()'s init()
ocidXMLDoc's setDocumentContentKind:(refMe's NSXMLDocumentHTMLKind)
# DTD付与
set ocidDTD to refMe's NSXMLDTD's alloc()'s init()
ocidDTD's setName:("html")
ocidXMLDoc's setDTD:(ocidDTD)
# XML主要部分を生成
set strTitleText to ("【ExifTool】: " & strFileName & " :メタデータ一覧") as text
set ocidRootElement to doMakeRootElement(strTitleText)
#ボディエレメント
set ocidBodyElement to refMe's NSXMLElement's elementWithName:("body")
#ヘッダー
set ocidHeaderElement to refMe's NSXMLElement's elementWithName:("header")
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("id") stringValue:("header")
ocidHeaderElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("class") stringValue:("body_header")
ocidHeaderElement's addAttribute:(ocidAddNode)
ocidBodyElement's addChild:(ocidHeaderElement)
#アーティクル
set ocidArticleElement to refMe's NSXMLElement's elementWithName:("article")
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("id") stringValue:("article")
ocidArticleElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("class") stringValue:("body_article")
ocidArticleElement's addAttribute:(ocidAddNode)
ocidBodyElement's addChild:(ocidArticleElement)
#フッター
set ocidFooterElement to refMe's NSXMLElement's elementWithName:("footer")
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("id") stringValue:("footer")
ocidFooterElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("class") stringValue:("body_footer")
ocidFooterElement's addAttribute:(ocidAddNode)
#リンク付与(不要なら削除可)
set ocidAElement to refMe's NSXMLElement's elementWithName:("a")
set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("href") stringValue:("https://quicktimer.cocolog-nifty.com/"))
(ocidAElement's addAttribute:(ocidAddNode))
set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("target") stringValue:("_blank"))
(ocidAElement's addAttribute:(ocidAddNode))
set strContents to ("AppleScriptで生成しました") as text
(ocidAElement's setStringValue:(strContents))
ocidFooterElement's addChild:(ocidAElement)
ocidBodyElement's addChild:(ocidFooterElement)

##############################
# TABLE コンテンツ部分生成開始
##############################
#テーブル部生成開始
set ocidTableElement to refMe's NSXMLElement's elementWithName:("table")
###【caption】
set ocidCaptionElement to refMe's NSXMLElement's elementWithName:("caption")
ocidCaptionElement's setStringValue:(strTitleText)
ocidTableElement's addChild:(ocidCaptionElement)
###【colgroup】
set ocidColgroupElement to refMe's NSXMLElement's elementWithName:("colgroup")
#テーブルのタイトル部
set listColName to {"行番号", "項目名", "値"} as list
#タイトル部の数だけ繰り返し
repeat with itemColName in listColName
  ###【col】col生成
  set ocidAddElement to (refMe's NSXMLElement's elementWithName:("col"))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:(itemColName))
(ocidAddElement's addAttribute:(ocidAddNode))
(ocidColgroupElement's addChild:(ocidAddElement))
end repeat
#テーブルエレメントに追加
ocidTableElement's addChild:(ocidColgroupElement)
###【thead】
set ocidTheadElement to refMe's NSXMLElement's elementWithName:("thead")
#TR
set ocidTrElement to refMe's NSXMLElement's elementWithName:("tr")
#タイトル部の数だけ繰り返し
repeat with itemColName in listColName
  #ここはTDではなくてTHを利用
  set ocidAddElement to (refMe's NSXMLElement's elementWithName:("th"))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:(itemColName))
(ocidAddElement's addAttribute:(ocidAddNode))
  #値を入れる
(ocidAddElement's setStringValue:(itemColName))
  #TH→TRにセット
(ocidTrElement's addChild:(ocidAddElement))
end repeat
#TRをTHEADにセット
ocidTheadElement's addChild:(ocidTrElement)
#THEADをテーブルにセット
ocidTableElement's addChild:(ocidTheadElement)
###【tbody】
set ocidTbodyElement to refMe's NSXMLElement's elementWithName:("tbody")
#行番号
set numCntLineNo to 1 as integer
#ファイルのパスの数だけ繰り返し
repeat with itemKeyName in ocidAllKeySortedArray
  #TRの開始
  set ocidTrElement to (refMe's NSXMLElement's elementWithName:("tr"))
  #【行番号】をTHでセット
  set strZeroSupp to ("00") as text
  set strZeroSupp to ("00" & numCntLineNo) as text
  set strLineNO to (text -3 through -1 of strZeroSupp) as text
  set ocidThElement to (refMe's NSXMLElement's elementWithName:("th"))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("行番号"))
(ocidThElement's addAttribute:(ocidAddNode))
(ocidThElement's setStringValue:(strLineNO))
(ocidTrElement's addChild:(ocidThElement))
  #【項目名=KEY名】をTDでセット
  set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td"))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("項目名"))
(ocidTdElement's setStringValue:(itemKeyName))
(ocidTdElement's addAttribute:(ocidAddNode))
  #TDをTRにセット
(ocidTrElement's addChild:(ocidTdElement))
  #【値=Value】TD
  #値の取得
  set ocidValue to (ocidJsonDict's valueForKey:(itemKeyName))
  set strValueClass to className() of ocidValue as text
  set strValue to "" as text
  if strValueClass contains "Array" then
    set strValue to (ocidValue's componentsJoinedByString:(", "))
  else
    set strValue to ocidValue as text
  end if
  #
  set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td"))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("値"))
(ocidTdElement's setStringValue:(strValue))
(ocidTdElement's addAttribute:(ocidAddNode))
  #TDをTRにセット
(ocidTrElement's addChild:(ocidTdElement))
  #出来上がったTRをTBODYにセット
(ocidTbodyElement's addChild:(ocidTrElement))
  #
  set numCntLineNo to (numCntLineNo + 1) as integer
end repeat
#TBODYをテーブルにセット
ocidTableElement's addChild:(ocidTbodyElement)
###【tfoot】 TRで
set ocidTfootElement to refMe's NSXMLElement's elementWithName:("tfoot")
set ocidTrElement to refMe's NSXMLElement's elementWithName:("tr")
#項目数を取得して
set numCntCol to (count of listColName) as integer
#colspan指定して1行でセット
set ocidThElement to (refMe's NSXMLElement's elementWithName:("th"))
set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("テーブルの終わり"))
(ocidThElement's addAttribute:(ocidAddNode))
set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("colspan") stringValue:(numCntCol as text))
(ocidThElement's addAttribute:(ocidAddNode))
set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("scope") stringValue:("row"))
(ocidThElement's addAttribute:(ocidAddNode))
#項目キーの数
set numCntKey to (count of ocidAllKeySortedArray) as integer
set strValue to ("メタデータの数は:" & numCntKey & " 件でした") as text
ocidThElement's setStringValue:(strValue)
#THをTRにセットして
ocidTrElement's addChild:(ocidThElement)
#TRをTFOOTにセット
ocidTfootElement's addChild:(ocidTrElement)
#TFOOTをテーブルにセット
ocidTableElement's addChild:(ocidTfootElement)
# 出来上がったテーブルをArticleエレメントにセット
ocidArticleElement's addChild:(ocidTableElement)
#ルートエレメントにセット
ocidRootElement's addChild:(ocidBodyElement)
##############################
# TABLE
##############################
#ROOTエレメントをXMLにセット
ocidXMLDoc's setRootElement:(ocidRootElement)
#読み取りやすい表示
set ocidXMLdata to ocidXMLDoc's XMLDataWithOptions:(refMe's NSXMLNodePrettyPrint)
#保存
set listDone to ocidXMLdata's writeToURL:(ocidSaveFilePathURL) options:(refMe's NSDataWritingAtomic) |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:"JSON2HTMLv3"}
  tell window 1
open location strOpenURL
  end tell
end tell
####
set ocidContainerDirPathURL to ocidSaveFilePathURL's URLByDeletingLastPathComponent()
set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
set boolDone to appSharedWorkspace's openURL:(ocidContainerDirPathURL)


##############################
# 基本的なHTMLの構造
##############################
to doMakeRootElement(argStrTitleText)
  set strTitleText to argStrTitleText as text
  #
  set ocidRootElement to refMe's NSXMLElement's elementWithName:("html")
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("lang") stringValue:("ja")
ocidRootElement's addAttribute:(ocidAddNode)
  #
  set ocidHeadElement to refMe's NSXMLElement's elementWithName:("head")
  #
  set ocidAddElement to refMe's NSXMLElement's elementWithName:("title")
ocidAddElement's setStringValue:(strTitleText)
ocidHeadElement's addChild:(ocidAddElement)
  # http-equiv
  set ocidAddElement to refMe's NSXMLElement's elementWithName:("meta")
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("http-equiv") stringValue:("Content-Type")
ocidAddElement's addAttribute:(ocidAddNode)
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("content") stringValue:("text/html; charset=UTF-8")
ocidAddElement's addAttribute:(ocidAddNode)
ocidHeadElement's addChild:(ocidAddElement)
  #
  set ocidAddElement to refMe's NSXMLElement's elementWithName:("meta")
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("http-equiv") stringValue:("Content-Style-Type")
ocidAddElement's addAttribute:(ocidAddNode)
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("content") stringValue:("text/css")
ocidAddElement's addAttribute:(ocidAddNode)
ocidHeadElement's addChild:(ocidAddElement)
  #
  set ocidAddElement to refMe's NSXMLElement's elementWithName:("meta")
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("http-equiv") stringValue:("Content-Script-Type")
ocidAddElement's addAttribute:(ocidAddNode)
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("content") stringValue:("text/javascript")
ocidAddElement's addAttribute:(ocidAddNode)
ocidHeadElement's addChild:(ocidAddElement)
  #
  set ocidAddElement to refMe's NSXMLElement's elementWithName:("meta")
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("name") stringValue:("viewport")
ocidAddElement's addAttribute:(ocidAddNode)
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("content") stringValue:("width=720")
ocidAddElement's addAttribute:(ocidAddNode)
ocidHeadElement's addChild:(ocidAddElement)
  #
  set ocidAddElement to refMe's NSXMLElement's elementWithName:("style")
ocidAddElement's setStringValue:("body { margin: 10px; background-color: #FFFFFF; } table { border-spacing: 0; caption-side: top; font-family: system-ui; } thead th { border: solid 1px #666666; padding: .5ch 1ch; border-block-width: 1px 0; border-inline-width: 1px 0; &:first-of-type { border-start-start-radius: .5em } &:last-of-type { border-start-end-radius: .5em; border-inline-end-width: 1px } } tbody td { word-wrap: break-word;max-width: 360px;border-spacing: 0; border: solid 1px #666666; padding: .5ch 1ch; border-block-width: 1px 0; border-inline-width: 1px 0; &:last-of-type { border-inline-end-width: 1px } } tbody th { border-spacing: 0; border: solid 1px #666666; padding: .5ch 1ch; border-block-width: 1px 0; border-inline-width: 1px 0; } tbody tr:nth-of-type(odd) { background: #F2F2F2; } .kind_string { font-size: 0.75em; } .date_string { font-size: 0.5em; } tfoot th { border: solid 1px #666666; padding: .5ch 1ch; &:first-of-type { border-end-start-radius: .5em } &:last-of-type { border-end-end-radius: .5em; border-inline-end-width: 1px } }")
ocidHeadElement's addChild:(ocidAddElement)
  #
ocidRootElement's addChild:(ocidHeadElement)
  #
return ocidRootElement
end doMakeRootElement


##############################
# exiftoolインストール
##############################
to doInstallBin()
  set strVerURL to ("https://exiftool.org/ver.txt") as text
  set strInstrallDirPath to ("~/bin/exiftool") as text
  ###インストール先
  set ocidInstrallDirPathStr to refMe's NSString's stringWithString:(strInstrallDirPath)
  set ocidInstrallDirPath to ocidInstrallDirPathStr's stringByStandardizingPath()
  set ocidInstrallDirPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidInstrallDirPath) isDirectory:true)
  ###フォルダを作る
  set appFileManager to refMe's NSFileManager's defaultManager()
  set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
  set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidInstrallDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
  set strInstrallDirPath to (ocidInstrallDirPathURL's |path|()) as text
  ###バージョンテキストURL
  set ocidVerURLStr to refMe's NSString's stringWithString:(strVerURL)
  set ocidVerURL to refMe's NSURL's alloc()'s initWithString:(ocidVerURLStr)
  set ocidVerText to refMe's NSString's stringWithContentsOfURL:(ocidVerURL) encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)
  set strVer to (item 1 of ocidVerText) as text
  ###URLとファイル名の整形
  set strDmgName to ("ExifTool-" & strVer & ".dmg") as text
  set strPkgName to ("ExifTool-" & strVer & ".pkg") as text
  set strVoluemPath to ("/Volumes/ExifTool-" & strVer & "") as text
  set strPkgPath to ("" & strVoluemPath & "/" & strPkgName & "/Contents/Archive.pax.gz") as text
  set strURL to ("https://exiftool.org/" & strDmgName & "") as text
  set ocidURLStr to refMe's NSString's stringWithString:(strURL)
  set ocidURL to refMe's NSURL's alloc()'s initWithString:(ocidURLStr)
  ###ダウンロードディレクトリ
  set appFileManager to refMe's NSFileManager's defaultManager()
  set ocidTempDirURL to appFileManager's temporaryDirectory()
  set ocidUUID to refMe's NSUUID's alloc()'s init()
  set ocidUUIDString to ocidUUID's UUIDString
  set ocidSaveDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:true
  ###フォルダを作る
  set appFileManager to refMe's NSFileManager's defaultManager()
  set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
  set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
  ###保存URL
  set ocidSaveDmgFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strDmgName)
  set strSaveDmgFilePathURL to (ocidSaveDmgFilePathURL's |path|()) as text
  ###ダウンロード
  set ocidOption to refMe's NSDataReadingMappedAlways
  set listDone to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidURL) options:(ocidOption) |error|:(reference)
  set ocidDmgData to (item 1 of listDone)
  ###保存
  set ocidOption to refMe's NSDataWritingAtomic
  set listDone to ocidDmgData's writeToURL:(ocidSaveDmgFilePathURL) options:(ocidOption) |error|:(reference)
log item 1 of listDone
  ####ディスクイメージマウント
strSaveDmgFilePathURL
  set strCommandText to ("/usr/bin/hdiutil attach \"" & strSaveDmgFilePathURL & "\" -noverify -nobrowse -noautoopen") as text
do shell script strCommandText
  ###解凍先ディレクトリを作成
  set ocidExpandPkgDirPathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:("Expand")
  set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
  set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidExpandPkgDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
  set strExpandPkgDirPathURL to (ocidExpandPkgDirPathURL's |path|()) as text
  ###解凍
  set strCoommandText to "/usr/bin/bsdtar -xzf \"" & strPkgPath & "\" -C \"" & strExpandPkgDirPathURL & "\"" as text
do shell script strCoommandText
  ###ディスクイメージアンマウンド
  set strCoommandText to "/usr/bin/hdiutil detach \"" & strVoluemPath & "\" -force" as text
do shell script strCoommandText
  ###ユーザーディレクトリにコピー
  set ocidDittoDirPathURL to ocidExpandPkgDirPathURL's URLByAppendingPathComponent:("usr/local/bin")
  set strDittoDirPathURL to (ocidDittoDirPathURL's |path|()) as text
  set strCoommandText to "/usr/bin/ditto \"" & strDittoDirPathURL & "\" \"" & strInstrallDirPath & "\"" as text
do shell script strCoommandText
end doInstallBin


|

[exiftool]Exif2HTMLv3 exiftoolのExif情報をHTMLで表示する(たいぶ修正)


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use framework "UniformTypeIdentifiers"
use scripting additions

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

########################################
### 設定項目
### exiftoolへのパス
########################################
#一般的にはパスはこちら
# set strExifPath to "/usr/local/bin/exiftool/exiftool" as text
#自分用
set strExifPath to "~/bin/exiftool/exiftool" as text


#exiftoolパス処理
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

########################################
####出力先/var/folders/XX/(再起動時に削除されます)
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
ocidAttrDict's setValue:(511) 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 ocidHomeDirURL to appFileManager's homeDirectoryForCurrentUser()
#デスクトップの場合
set ocidDefaultLocationURL to ocidHomeDirURL's URLByAppendingPathComponent:("Desktop") isDirectory:true
#ダウンロードフォルダの場合
#set ocidDefaultLocationURL to ocidHomeDirURL's URLByAppendingPathComponent:("Downloads") isDirectory:true
#フォントフォルダの場合
#set ocidDefaultLocationURL to ocidHomeDirURL's URLByAppendingPathComponent:("Library/Fonts") isDirectory:true
#エイリアスパスにする
set aliasDefaultLocation to (ocidDefaultLocationURL's absoluteURL()) as alias
set listUTI to {"public.item"}
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 strSaveFileName to (strFileName & ".html") as text
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
set aliasSaveFilePath to (choose file name with prompt "htmlのファイル名を付けてください" default name strSaveFileName 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
set strErrorFilePath to (strSaveFilePath & ".json") as text

########################################
###【1】データ取得 JSON出力
try
  set strCommandText to ("\"" & strExifPath & "\" -json \"" & strFilePath & "\"") as text
  set strResponseJosn to (do shell script strCommandText) as text
on error
  try
    set strCommandText to ("\"" & strExifPath & "\" -json \"" & strFilePath & "\" > \"" & strErrorFilePath & "\"") as text
    set strResponseJosn to (do shell script strCommandText) as text
  on error
    set strCommandText to ("/bin/cat \"" & strErrorFilePath & "\"") as text
    set strResponseJosn to (do shell script strCommandText) as text
log "たぶんexiftoolの非対応のファイルタイプですA"
  end try
end try
if strResponseJosn is "" then
return "たぶんexiftoolの非対応のファイルタイプですB"
end if
###【2】NSStringにテキストに格納して
set ocidReadDataJson to refMe's NSString's stringWithString:strResponseJosn
###【3】NSConcreteMutableDataに変換
set ocidReadDataUTF to ocidReadDataJson's dataUsingEncoding:(refMe's NSUTF8StringEncoding)
###【4】NSInlineDataデータ初期化
set ocidReadData to (refMe's NSData's alloc()'s initWithData:(ocidReadDataUTF))
###【5】NSJSONSerialization
set listJSONSerialization to (refMe's NSJSONSerialization's JSONObjectWithData:ocidReadData options:0 |error|:(reference))
set ocidJsonData to (item 1 of listJSONSerialization)
-->(*__NSSingleObjectArrayI*)
####解説
(*
exiftoolの書き出すJSONはrootがArray構造から始まっているので
PlistにするにはDictに変換なりする必要がある
幸い『[{}]』といったシングルArray構造なので
Arrayから最初のOBJECTを取り出せばDICTレコード構造になる
*)
set ocidJsonDict to (ocidJsonData's firstObject())
-->(*__NSDictionaryI*)
###【6】レコードをNSDictionaryとして格納
set ocidJsonDict to (refMe's NSDictionary's alloc()'s initWithDictionary:ocidJsonDict)
#AllKeys
set ocidAllKeyArray to ocidJsonDict's allKeys()
#並び替えソート
set ocidAllKeySortedArray to ocidAllKeyArray's sortedArrayUsingSelector:("localizedStandardCompare:")

##############################
# XML 生成開始
##############################
#XML初期化
set ocidXMLDoc to refMe's NSXMLDocument's alloc()'s init()
ocidXMLDoc's setDocumentContentKind:(refMe's NSXMLDocumentHTMLKind)
# DTD付与
set ocidDTD to refMe's NSXMLDTD's alloc()'s init()
ocidDTD's setName:("html")
ocidXMLDoc's setDTD:(ocidDTD)
# XML主要部分を生成
set strTitleText to ("【ExifTool】: " & strFileName & " :メタデータ一覧") as text
set ocidRootElement to doMakeRootElement(strTitleText)
#ボディエレメント
set ocidBodyElement to refMe's NSXMLElement's elementWithName:("body")
#ヘッダー
set ocidHeaderElement to refMe's NSXMLElement's elementWithName:("header")
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("id") stringValue:("header")
ocidHeaderElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("class") stringValue:("body_header")
ocidHeaderElement's addAttribute:(ocidAddNode)
ocidBodyElement's addChild:(ocidHeaderElement)
#アーティクル
set ocidArticleElement to refMe's NSXMLElement's elementWithName:("article")
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("id") stringValue:("article")
ocidArticleElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("class") stringValue:("body_article")
ocidArticleElement's addAttribute:(ocidAddNode)
ocidBodyElement's addChild:(ocidArticleElement)
#フッター
set ocidFooterElement to refMe's NSXMLElement's elementWithName:("footer")
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("id") stringValue:("footer")
ocidFooterElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("class") stringValue:("body_footer")
ocidFooterElement's addAttribute:(ocidAddNode)
#リンク付与(不要なら削除可)
set ocidAElement to refMe's NSXMLElement's elementWithName:("a")
set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("href") stringValue:("https://quicktimer.cocolog-nifty.com/"))
(ocidAElement's addAttribute:(ocidAddNode))
set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("target") stringValue:("_blank"))
(ocidAElement's addAttribute:(ocidAddNode))
set strContents to ("AppleScriptで生成しました") as text
(ocidAElement's setStringValue:(strContents))
ocidFooterElement's addChild:(ocidAElement)
ocidBodyElement's addChild:(ocidFooterElement)

##############################
# TABLE コンテンツ部分生成開始
##############################
#テーブル部生成開始
set ocidTableElement to refMe's NSXMLElement's elementWithName:("table")
###【caption】
set ocidCaptionElement to refMe's NSXMLElement's elementWithName:("caption")
ocidCaptionElement's setStringValue:(strTitleText)
ocidTableElement's addChild:(ocidCaptionElement)
###【colgroup】
set ocidColgroupElement to refMe's NSXMLElement's elementWithName:("colgroup")
#テーブルのタイトル部
set listColName to {"行番号", "項目名", "値"} as list
#タイトル部の数だけ繰り返し
repeat with itemColName in listColName
  ###【col】col生成
  set ocidAddElement to (refMe's NSXMLElement's elementWithName:("col"))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:(itemColName))
(ocidAddElement's addAttribute:(ocidAddNode))
(ocidColgroupElement's addChild:(ocidAddElement))
end repeat
#テーブルエレメントに追加
ocidTableElement's addChild:(ocidColgroupElement)
###【thead】
set ocidTheadElement to refMe's NSXMLElement's elementWithName:("thead")
#TR
set ocidTrElement to refMe's NSXMLElement's elementWithName:("tr")
#タイトル部の数だけ繰り返し
repeat with itemColName in listColName
  #ここはTDではなくてTHを利用
  set ocidAddElement to (refMe's NSXMLElement's elementWithName:("th"))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:(itemColName))
(ocidAddElement's addAttribute:(ocidAddNode))
  #値を入れる
(ocidAddElement's setStringValue:(itemColName))
  #TH→TRにセット
(ocidTrElement's addChild:(ocidAddElement))
end repeat
#TRをTHEADにセット
ocidTheadElement's addChild:(ocidTrElement)
#THEADをテーブルにセット
ocidTableElement's addChild:(ocidTheadElement)
###【tbody】
set ocidTbodyElement to refMe's NSXMLElement's elementWithName:("tbody")
#行番号
set numCntLineNo to 1 as integer
#ファイルのパスの数だけ繰り返し
repeat with itemKeyName in ocidAllKeySortedArray
  #TRの開始
  set ocidTrElement to (refMe's NSXMLElement's elementWithName:("tr"))
  #【行番号】をTHでセット
  set strZeroSupp to ("00") as text
  set strZeroSupp to ("00" & numCntLineNo) as text
  set strLineNO to (text -3 through -1 of strZeroSupp) as text
  set ocidThElement to (refMe's NSXMLElement's elementWithName:("th"))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("行番号"))
(ocidThElement's addAttribute:(ocidAddNode))
(ocidThElement's setStringValue:(strLineNO))
(ocidTrElement's addChild:(ocidThElement))
  #【項目名=KEY名】をTDでセット
  set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td"))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("項目名"))
(ocidTdElement's setStringValue:(itemKeyName))
(ocidTdElement's addAttribute:(ocidAddNode))
  #TDをTRにセット
(ocidTrElement's addChild:(ocidTdElement))
  #【値=Value】TD
  #値の取得
  set ocidValue to (ocidJsonDict's valueForKey:(itemKeyName))
  set strValueClass to className() of ocidValue as text
  set strValue to "" as text
  if strValueClass contains "Array" then
    set strValue to (ocidValue's componentsJoinedByString:(", "))
  else
    set strValue to ocidValue as text
  end if
  #
  set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td"))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("値"))
(ocidTdElement's setStringValue:(strValue))
(ocidTdElement's addAttribute:(ocidAddNode))
  #TDをTRにセット
(ocidTrElement's addChild:(ocidTdElement))
  #出来上がったTRをTBODYにセット
(ocidTbodyElement's addChild:(ocidTrElement))
  #
  set numCntLineNo to (numCntLineNo + 1) as integer
end repeat
#TBODYをテーブルにセット
ocidTableElement's addChild:(ocidTbodyElement)
###【tfoot】 TRで
set ocidTfootElement to refMe's NSXMLElement's elementWithName:("tfoot")
set ocidTrElement to refMe's NSXMLElement's elementWithName:("tr")
#項目数を取得して
set numCntCol to (count of listColName) as integer
#colspan指定して1行でセット
set ocidThElement to (refMe's NSXMLElement's elementWithName:("th"))
set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("テーブルの終わり"))
(ocidThElement's addAttribute:(ocidAddNode))
set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("colspan") stringValue:(numCntCol as text))
(ocidThElement's addAttribute:(ocidAddNode))
set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("scope") stringValue:("row"))
(ocidThElement's addAttribute:(ocidAddNode))
#項目キーの数
set numCntKey to (count of ocidAllKeySortedArray) as integer
set strValue to ("メタデータの数は:" & numCntKey & " 件でした") as text
ocidThElement's setStringValue:(strValue)
#THをTRにセットして
ocidTrElement's addChild:(ocidThElement)
#TRをTFOOTにセット
ocidTfootElement's addChild:(ocidTrElement)
#TFOOTをテーブルにセット
ocidTableElement's addChild:(ocidTfootElement)
# 出来上がったテーブルをArticleエレメントにセット
ocidArticleElement's addChild:(ocidTableElement)
#ルートエレメントにセット
ocidRootElement's addChild:(ocidBodyElement)
##############################
# TABLE
##############################
#ROOTエレメントをXMLにセット
ocidXMLDoc's setRootElement:(ocidRootElement)
#読み取りやすい表示
set ocidXMLdata to ocidXMLDoc's XMLDataWithOptions:(refMe's NSXMLNodePrettyPrint)
#保存
set listDone to ocidXMLdata's writeToURL:(ocidSaveFilePathURL) options:(refMe's NSDataWritingAtomic) |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:"JSON2HTMLv3"}
  tell window 1
open location strOpenURL
  end tell
end tell
####
set ocidContainerDirPathURL to ocidSaveFilePathURL's URLByDeletingLastPathComponent()
set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
set boolDone to appSharedWorkspace's openURL:(ocidContainerDirPathURL)


##############################
# 基本的なHTMLの構造
##############################
to doMakeRootElement(argStrTitleText)
  set strTitleText to argStrTitleText as text
  #
  set ocidRootElement to refMe's NSXMLElement's elementWithName:("html")
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("lang") stringValue:("ja")
ocidRootElement's addAttribute:(ocidAddNode)
  #
  set ocidHeadElement to refMe's NSXMLElement's elementWithName:("head")
  #
  set ocidAddElement to refMe's NSXMLElement's elementWithName:("title")
ocidAddElement's setStringValue:(strTitleText)
ocidHeadElement's addChild:(ocidAddElement)
  # http-equiv
  set ocidAddElement to refMe's NSXMLElement's elementWithName:("meta")
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("http-equiv") stringValue:("Content-Type")
ocidAddElement's addAttribute:(ocidAddNode)
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("content") stringValue:("text/html; charset=UTF-8")
ocidAddElement's addAttribute:(ocidAddNode)
ocidHeadElement's addChild:(ocidAddElement)
  #
  set ocidAddElement to refMe's NSXMLElement's elementWithName:("meta")
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("http-equiv") stringValue:("Content-Style-Type")
ocidAddElement's addAttribute:(ocidAddNode)
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("content") stringValue:("text/css")
ocidAddElement's addAttribute:(ocidAddNode)
ocidHeadElement's addChild:(ocidAddElement)
  #
  set ocidAddElement to refMe's NSXMLElement's elementWithName:("meta")
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("http-equiv") stringValue:("Content-Script-Type")
ocidAddElement's addAttribute:(ocidAddNode)
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("content") stringValue:("text/javascript")
ocidAddElement's addAttribute:(ocidAddNode)
ocidHeadElement's addChild:(ocidAddElement)
  #
  set ocidAddElement to refMe's NSXMLElement's elementWithName:("meta")
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("name") stringValue:("viewport")
ocidAddElement's addAttribute:(ocidAddNode)
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("content") stringValue:("width=720")
ocidAddElement's addAttribute:(ocidAddNode)
ocidHeadElement's addChild:(ocidAddElement)
  #
  set ocidAddElement to refMe's NSXMLElement's elementWithName:("style")
ocidAddElement's setStringValue:("body { margin: 10px; background-color: #FFFFFF; } table { border-spacing: 0; caption-side: top; font-family: system-ui; } thead th { border: solid 1px #666666; padding: .5ch 1ch; border-block-width: 1px 0; border-inline-width: 1px 0; &:first-of-type { border-start-start-radius: .5em } &:last-of-type { border-start-end-radius: .5em; border-inline-end-width: 1px } } tbody td { word-wrap: break-word;max-width: 360px;border-spacing: 0; border: solid 1px #666666; padding: .5ch 1ch; border-block-width: 1px 0; border-inline-width: 1px 0; &:last-of-type { border-inline-end-width: 1px } } tbody th { border-spacing: 0; border: solid 1px #666666; padding: .5ch 1ch; border-block-width: 1px 0; border-inline-width: 1px 0; } tbody tr:nth-of-type(odd) { background: #F2F2F2; } .kind_string { font-size: 0.75em; } .date_string { font-size: 0.5em; } tfoot th { border: solid 1px #666666; padding: .5ch 1ch; &:first-of-type { border-end-start-radius: .5em } &:last-of-type { border-end-end-radius: .5em; border-inline-end-width: 1px } }")
ocidHeadElement's addChild:(ocidAddElement)
  #
ocidRootElement's addChild:(ocidHeadElement)
  #
return ocidRootElement
end doMakeRootElement

|

exiftool

公式サイト
https://exiftool.org/



インストール
[applescript] ExifToolインストール
https://quicktimer.cocolog-nifty.com/icefloe/2024/01/post-e7e51d.html
[bash] ExifToolインストール
https://quicktimer.cocolog-nifty.com/icefloe/2024/01/post-c9eb3a.html


画像系
[exiftool] exiftoolのhtmlDumpの内容をHTMLで保存する(画像系専用)
https://quicktimer.cocolog-nifty.com/icefloe/2024/01/post-53a674.html
汎用
[exiftool] exiftoolで取得したメタデータをHTML表示
https://quicktimer.cocolog-nifty.com/icefloe/2024/01/post-467814.html
[exiftool] XML(XML書き出し)
https://quicktimer.cocolog-nifty.com/icefloe/2022/10/post-57b1e3.html


フォント関連
FontExporter モリサワ1.5対応
https://quicktimer.cocolog-nifty.com/icefloe/2023/09/post-699f23.html
[Fonts]ファミリー名のフォルダを作ってフォントを中に入れる
https://quicktimer.cocolog-nifty.com/icefloe/2023/05/post-2efa6c.html



PDF
[PDF]メタデータ タイトル設定
https://quicktimer.cocolog-nifty.com/icefloe/2024/01/post-963eed.html

[exiftool]PDFのメタデータ全部削除
https://quicktimer.cocolog-nifty.com/icefloe/2024/01/post-ced377.html

|

[PDF]メタデータ タイトル設定


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
(*
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.6"
use framework "Foundation"
use framework "PDFKit"
use framework "Quartz"
use scripting additions

property refMe : a reference to current application


#####
#設定項目
# set strBinPath to ("/usr/local/bin/exiftool") as text --通常はこちら
set strBinPath to ("~/bin/exiftool/exiftool") as text


set objFileManager to refMe's NSFileManager's defaultManager()


##############################
#####ダイアログを前面に出す
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder"
activate
  end tell
else
  tell current application
activate
  end tell
end if
#######################################
#####ファイル選択ダイアログ
#######################################
###ダイアログのデフォルト
set ocidUserDesktopPath to (objFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set aliasDefaultLocation to ocidUserDesktopPath as alias
tell application "Finder"
end tell
set listChooseFileUTI to {"com.adobe.pdf"}
set strPromptText to "PDFファイルを選んでください" as text
set listAliasFilePath to (choose file with prompt strPromptText default location (aliasDefaultLocation) of type listChooseFileUTI with invisibles and multiple selections allowed without showing package contents) as list

#######################################
## クリップボードの中身取り出し
#######################################
###初期化
set appPasteboard to refMe's NSPasteboard's generalPasteboard()
set ocidPastBoardTypeArray to appPasteboard's types
###テキストがあれば
set boolContain to ocidPastBoardTypeArray's containsObject:"public.utf8-plain-text"
if boolContain = true then
  ###値を格納する
  tell application "Finder"
    set strReadString to (the clipboard as text) as text
  end tell
  ###Finderでエラーしたら
else
  set boolContain to ocidPastBoardTypeArray's containsObject:"NSStringPboardType"
  if boolContain = true then
    set ocidReadString to ocidPasteboard's readObjectsForClasses:({refMe's NSString}) options:(missing value)
    set strReadString to ocidReadString as text
  else
log "テキストなし"
    set aliasFirstFilePath to (item 1 of listAliasFilePath) as alias
    tell application "Finder"
      set strFirstFileName to name of aliasFirstFilePath as text
    end tell
    set strReadString to strFirstFileName as text
  end if
end if
########################
##ダイアログを前面に出す
set strName to (name of current application) as text
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
########################
##ダイアログ
set aliasIconPath to (POSIX file "/System/Library/CoreServices/Tips.app/Contents/Resources/AppIcon.icns") as alias
set strTitle to ("入力してください") as text
set strMes to ("タイトルを入力してください\r") as text
set recordResult to (display dialog strMes with title strTitle default answer strReadString buttons {"キャンセル", "OK"} default button "OK" cancel button "キャンセル" giving up after 30 with icon aliasIconPath without hidden answer)
if (gave up of recordResult) is true then
return "時間切れです"
else if (button returned of recordResult) is "キャンセル" then
return "キャンセルです"
else
  set strReturnedText to (text returned of recordResult) as text
end if
set ocidReturnedText to refMe's NSString's stringWithString:(strReturnedText)
########################
##改行を取る
set ocidReturned to ocidReturnedText's stringByReplacingOccurrencesOfString:("\r") withString:("")
set ocidReturnedText to ocidReturned's stringByReplacingOccurrencesOfString:("\n") withString:("")
set strSetText to ocidReturnedText as string
#####BIN path
set ocidBinPathStr to refMe's NSString's stringWithString:(strBinPath)
set ocidBinPath to ocidBinPathStr's stringByStandardizingPath()
set ocidBinPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidBinPath) isDirectory:false)
set strBinPath to ocidBinPathURL's |path| as text


#######################################
###ダイアログで選択した書類の数だけ繰り返し
#######################################
repeat with itemAliasFilePath in listAliasFilePath
  set strFilePath to POSIX path of itemAliasFilePath as text
  set ocidFilePathStr to (refMe's NSString's stringWithString:strFilePath)
  set ocidFilePath to ocidFilePathStr's stringByStandardizingPath
  set strFileName to ocidFilePath's lastPathComponent() as text
  set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false)
  #####PDFDocumentとして読み込み
  set ocidActivDoc to (refMe's PDFDocument's alloc()'s initWithURL:ocidFilePathURL)
  ########################################
  #####暗号化チェック
  set boolEncrypted to ocidActivDoc's isEncrypted()
  if boolEncrypted is true then
    set strMes to "エラー:" & strFileName & "暗号化されています" as text
display alert strMes buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 3
return "暗号化されているので変更できません"
  end if
  ########################################
  #####ロック確認
  set boolLocked to ocidActivDoc's isLocked()
  if boolLocked is true then
    set strMes to "エラー:" & strFileName & "パスワードでロックされています" as text
display alert strMes buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 3
return "パスワードでロックされているので変更できません"
  end if
  ########################################
  #####アトリビュートを取得して
  set ocidAttributes to ocidActivDoc's documentAttributes()
  ######可変ディクショナリに格納
  set ocidAttrDict to (refMe's NSMutableDictionary's alloc()'s initWithDictionary:ocidAttributes)
log ocidAttrDict as record
  ###Titleキーの内容を設定
(ocidAttrDict's setValue:(ocidReturnedText) forKey:"Title")
(ocidAttrDict's setValue:"" forKey:"Creator")
  #####値を変更したレコードをセットする
(ocidActivDoc's setDocumentAttributes:ocidAttrDict)
  ##################
  ###保存
  ##################
(ocidActivDoc's writeToURL:ocidFilePathURL)
  ####解放
  set ocidActivDoc to ""
  set ocidDocAttrDict to ""
  ##################
  ### exifToolでXMPを削除
  ##################
  set strCommandText to ("\"" & strBinPath & "\" -m -overwrite_original -title=\"" & strSetText & "\" -xmp:Title=\"" & strSetText & "\" -xmp:dc:Title=\"" & strSetText & "\" -IPTC:ObjectName=\"" & strSetText & "\" \"" & strFilePath & "\"") as text
  try
do shell script strCommandText
  end try
end repeat


return "処理終了"






|

[exiftool]PDFのメタデータ全部削除


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
(*
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.6"
use framework "Foundation"
use framework "PDFKit"
use framework "Quartz"
use scripting additions

property refMe : a reference to current application


#####
#設定項目
# set strBinPath to ("/usr/local/bin/exiftool") as text --通常はこちら
set strBinPath to ("~/bin/exiftool/exiftool") as text


set objFileManager to refMe's NSFileManager's defaultManager()
#
set ocidBinPathStr to refMe's NSString's stringWithString:(strBinPath)
set ocidBinPath to ocidBinPathStr's stringByStandardizingPath()
set ocidBinPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidBinPath) isDirectory:false)
set strBinPath to ocidBinPathURL's |path| as text

##############################
#####ダイアログを前面に出す
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder"
activate
  end tell
else
  tell current application
activate
  end tell
end if
#######################################
#####ファイル選択ダイアログ
#######################################
###ダイアログのデフォルト
set ocidUserDesktopPath to (objFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set aliasDefaultLocation to ocidUserDesktopPath as alias
tell application "Finder"
end tell
set listChooseFileUTI to {"com.adobe.pdf"}
set strPromptText to "PDFファイルを選んでください" as text
set listAliasFilePath to (choose file with prompt strPromptText default location (aliasDefaultLocation) of type listChooseFileUTI with invisibles and multiple selections allowed without showing package contents) as list
#######################################
###ダイアログで選択した書類の数だけ繰り返し
#######################################
repeat with itemAliasFilePath in listAliasFilePath
  set strFilePath to POSIX path of itemAliasFilePath as text
  set ocidFilePathStr to (refMe's NSString's stringWithString:strFilePath)
  set ocidFilePath to ocidFilePathStr's stringByStandardizingPath
  set strFileName to ocidFilePath's lastPathComponent() as text
  set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false)
  #####PDFDocumentとして読み込み
  set ocidActivDoc to (refMe's PDFDocument's alloc()'s initWithURL:ocidFilePathURL)
  ########################################
  #####暗号化チェック
  set boolEncrypted to ocidActivDoc's isEncrypted()
  if boolEncrypted is true then
    set strMes to "エラー:" & strFileName & "暗号化されています" as text
display alert strMes buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 3
return "暗号化されているので変更できません"
  end if
  ########################################
  #####ロック確認
  set boolLocked to ocidActivDoc's isLocked()
  if boolLocked is true then
    set strMes to "エラー:" & strFileName & "パスワードでロックされています" as text
display alert strMes buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 3
return "パスワードでロックされているので変更できません"
  end if
  ########################################
  #####アトリビュートを取得して
  set ocidAttributes to ocidActivDoc's documentAttributes()
  ######可変ディクショナリに格納
  set ocidAttrDict to (refMe's NSMutableDictionary's alloc()'s initWithDictionary:ocidAttributes)
log ocidAttrDict as record
  ###Titleキーの内容をブランクにする
(ocidAttrDict's setValue:"" forKey:"Title")
(ocidAttrDict's setValue:"" forKey:"Creator")
(ocidAttrDict's setValue:"" forKey:"Author")
(ocidAttrDict's setValue:"" forKey:"Keywords")
(ocidAttrDict's setValue:"" forKey:"Producer")
(ocidAttrDict's setValue:"" forKey:"Subject")
(ocidAttrDict's setValue:"" forKey:"ModificationDate")
(ocidAttrDict's setValue:"" forKey:"CreationDate")
  
  #####値を変更したレコードをセットする
(ocidActivDoc's setDocumentAttributes:ocidAttrDict)
  ##################
  ###保存
  ##################
(ocidActivDoc's writeToURL:ocidFilePathURL)
  ####解放
  set ocidActivDoc to ""
  set ocidDocAttrDict to ""
  ##################
  ### exifToolでXMPを削除
  ##################
  set strCommandText to ("\"" & strBinPath & "\" -overwrite_original -all= \"" & strFilePath & "\"") as text
  try
do shell script strCommandText
  end try
end repeat


return "処理終了"






|

[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


|

その他のカテゴリー

Acrobat Acrobat Annotation Acrobat Dialog Acrobat Form Acrobat JS Acrobat Open Acrobat Plugin Acrobat python Acrobat Reader Acrobat Sequ Acrobat Stamps Admin Admin Account Admin Apachectl Admin configCode Admin Device Management Admin LaunchServices Admin Locationd Admin loginitem Admin Maintenance Admin Permission Admin Pkg Admin Power Management Admin Printer Admin SetUp Admin SMB Admin System Information Admin Tools Admin Users Admin Volumes Adobe Apple AppleScript AppleScript Guide AppleScript Accessibility AppleScript AppKit AppleScript Applications AppleScript AppStore AppleScript Archive AppleScript Attributes AppleScript Automator AppleScript AVAsset AppleScript AVconvert AppleScript AVFoundation AppleScript AVURLAsset AppleScript BackUp AppleScript Barcode AppleScript Bash AppleScript Basic AppleScript Basic Path AppleScript Bluetooth AppleScript BOX AppleScript Browser AppleScript Calendar AppleScript CD/DVD AppleScript Choose AppleScript Chrome AppleScript CIImage AppleScript CloudStorage AppleScript Color AppleScript com.apple.LaunchServices.OpenWith AppleScript Console AppleScript Contacts AppleScript CotEditor AppleScript CURL AppleScript current application AppleScript Date&Time AppleScript delimiters AppleScript Desktop AppleScript Device AppleScript Disk AppleScript do shell script AppleScript Dock AppleScript DropBox AppleScript eMail AppleScript Encode Decode AppleScript Error AppleScript EXIFData AppleScript ffmpeg AppleScript File AppleScript Finder AppleScript Firefox AppleScript Folder AppleScript Fonts AppleScript GIF AppleScript HTML AppleScript Icon AppleScript Illustrator AppleScript Image Events AppleScript Image2PDF AppleScript ImageOptim Applescript iWork AppleScript Javascript AppleScript Jedit AppleScript Json AppleScript Label AppleScript List AppleScript locationd AppleScript LRC AppleScript LSSharedFileList AppleScript m3u8 AppleScript MakePDF AppleScript Map AppleScript Math AppleScript Microsoft AppleScript Microsoft Edge AppleScript Microsoft Excel AppleScript Mobileconfig AppleScript Mouse AppleScript Movie AppleScript Music AppleScript NetWork AppleScript Notes AppleScript NSArray AppleScript NSBitmapImageRep AppleScript NSBundle AppleScript NSCFBoolean AppleScript NSCharacterSet AppleScript NSColor AppleScript NSColorList AppleScript NSData AppleScript NSDictionary AppleScript NSError AppleScript NSEvent AppleScript NSFileAttributes AppleScript NSFileManager AppleScript NSFont AppleScript NSFontManager AppleScript NSImage AppleScript NSIndex AppleScript NSKeyedArchiver AppleScript NSKeyedUnarchiver AppleScript NSLocale AppleScript NSMutableArray AppleScript NSMutableDictionary AppleScript NSMutableString AppleScript NSNotFound AppleScript NSNumber AppleScript NSOpenPanel AppleScript NSPasteboard AppleScript NSPDFImageRep AppleScript NSpoint AppleScript NSPredicate AppleScript NSRange AppleScript NSRegularExpression AppleScript NSRunningApplication AppleScript NSScreen AppleScript NSSize AppleScript NSString AppleScript NSStringCompareOptions AppleScript NSTask AppleScript NSTimeZone AppleScript NSURL AppleScript NSURL File AppleScript NSURLBookmark AppleScript NSURLComponents AppleScript NSURLResourceKey AppleScript NSUserDefaults AppleScript NSUUID AppleScript NSView AppleScript NSWorkspace AppleScript Numbers AppleScript OAuth AppleScript ObjC AppleScript OneDrive AppleScript Osax AppleScript PDF AppleScript PDFAnnotationWidget AppleScript PDFContext AppleScript PDFDisplayBox AppleScript PDFDocumentPermissions AppleScript PDFKit AppleScript PDFnUP AppleScript PDFOutline AppleScript Photos AppleScript Photoshop AppleScript Plist System Events AppleScript PostScript AppleScript prefPane AppleScript Preview AppleScript Python AppleScript QR AppleScript QR Decode AppleScript QuickLook AppleScript QuickTime AppleScript record AppleScript Regular Expression AppleScript Reminders AppleScript ReName AppleScript Repeat AppleScript RTF AppleScript Safari AppleScript SaveFile AppleScript ScreenCapture AppleScript ScreenSaver AppleScript Script Editor AppleScript Script Menu AppleScript Shortcuts AppleScript Shortcuts Events AppleScript Sort AppleScript Sound AppleScript Spotlight AppleScript SRT AppleScript StandardAdditions AppleScript stringByApplyingTransform AppleScript System Events AppleScript System Settings AppleScript TemporaryItems AppleScript Terminal AppleScript Text AppleScript Text CSV AppleScript Text TSV AppleScript TextEdit AppleScript Translate AppleScript Trash AppleScript Twitter AppleScript UI AppleScript Unit Conversion AppleScript UTType AppleScript valueForKeyPath AppleScript Video AppleScript VisionKit AppleScript Visual Studio Code AppleScript webarchive AppleScript webp AppleScript Wifi AppleScript XML AppleScript XML EPUB AppleScript XML OPML AppleScript XML Plist AppleScript XML RSS AppleScript XML SVG AppleScript XML TTML AppleScript XML webloc AppleScript YouTube AppleScript Zero Suppress Applications Barcode OnLine Tools CityCode Design iPhone List Logs lsappinfo Memo Music perl PlistBuddy pluginkit postalcode ReadMe SF Symbols character id SF Symbols Entity sips Skype Slack sqlite TCC Tools Typography Video Wacom zoom