« ファイル名のフォルダを作って中に入れる(拡張子が複数ある場合の処理を変更) | トップページ | [NSXML]HTML生成基本部分(更新) »

[exiftool]メタ情報をHTMLで表示(だいぶ改修した)


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
# exiftoolmを
# インストールされていない場合インストール処理をします
# 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

on run
  tell application "Finder"
    set aliasDesktopPath to path to desktop folder from user domain as alias
  end tell
  set listAliasFilePath to (choose file with prompt "ファイルを選んでください" default location aliasDesktopPath of type {"public.item"} with multiple selections allowed and showing package contents without invisibles) as list
open listAliasFilePath
end run


on open listAliasFilePath
  #一般的にはパスはこちら
  # 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 appFileManager to refMe's NSFileManager's defaultManager()
  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 aliasTemporaryItems to (ocidTemporaryItemsPathURL's absoluteURL()) as alias
  set strTempDirPath to ocidTemporaryItemsPathURL's absoluteString() as text
  
  ##フォルダがなければ作る
  set boolDirExists to appFileManager's fileExistsAtPath:(ocidTemporaryItemsPathURL's |path|()) isDirectory:(true)
  if boolDirExists = true then
log "起動時に削除されるフォルダはすでにあります"
  else if boolDirExists = false then
log "起動時に削除されるフォルダを作ります"
    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)
  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 ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
    set ocidFileName to ocidFilePathURL's lastPathComponent()
    #保存先
    set ocidBaseFilePathURL to (ocidTemporaryItemsPathURL's URLByAppendingPathComponent:(ocidFileName))
    set ocidSaveFilePathURL to (ocidBaseFilePathURL's URLByAppendingPathExtension:("html"))
    #コマンド整形
    set strCommandText to ("\"" & strExifPath & "\" -lang ja \"" & strFilePath & "\"") as text
    #コマンド実行
    try
      set strResponseExif to (do shell script strCommandText) as text
    on error
      set strResponseExif to ("エラーが発生しました : Unknown file type")
    end try
    #戻り値
    set ocidExifStrings to (refMe's NSString's stringWithString:(strResponseExif))
    ##インテント除去
    set ocidReplacedStrings to (ocidExifStrings's stringByReplacingOccurrencesOfString:(" ") withString:(""))
    #改行をUNIXに強制
    set ocidExifStrings to (ocidReplacedStrings's stringByReplacingOccurrencesOfString:("\n\r") withString:("\n"))
    set ocidExifStrings to (ocidExifStrings's stringByReplacingOccurrencesOfString:("\r") withString:("\n"))
    set ocidExifStrings to (ocidExifStrings's stringByReplacingOccurrencesOfString:("\n\n") withString:("\n"))
    #改行でリストに
    set ocidChrSet to (refMe's NSCharacterSet's characterSetWithCharactersInString:("\n"))
    set ocidMainArray to (ocidExifStrings's componentsSeparatedByCharactersInSet:(ocidChrSet))
    #出力用のDICT
    set ocidExifDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
    #リストの数だけ繰り返し
    repeat with itemArray in ocidMainArray
      set ocidSubArray to (itemArray's componentsSeparatedByString:(": "))
      set ocidSetKey to (ocidSubArray's objectAtIndex:(0))
      set ocidSetValue to (ocidSubArray's objectAtIndex:(1))
(ocidExifDict's setValue:(ocidSetValue) forKey:(ocidSetKey))
    end repeat
    #DICTからキーを取得して
    set ocidAllKey to ocidExifDict's allKeys()
    #ソートしておく
    set ocidSortedKeyArray to (ocidAllKey's sortedArrayUsingSelector:("localizedStandardCompare:"))
    
    ##############################
    # XML 生成開始
    ##############################
    # タイトル
    set strTitleText to ("【ExifTool】: " & (ocidFileName as text) & " :メタデータ一覧") as text
    ########################################
    #headerに渡すエレメント
    set ocidSetHeaderElement to (refMe's NSXMLElement's elementWithName:("div"))
    set ocidH3Element to (refMe's NSXMLElement's elementWithName:("h3"))
(ocidH3Element's setStringValue:(strTitleText))
(ocidSetHeaderElement's addChild:(ocidH3Element))
    
    ########################################
    #footerに渡すエレメント
    set ocidSetFooterElement to (refMe's NSXMLElement's elementWithName:("div"))
    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))
(ocidSetFooterElement's addChild:(ocidAElement))
    
    ########################################
    #articleに渡すエレメント
    set ocidSetArticleElement to (refMe's NSXMLElement's elementWithName:("div"))
    set ocidH3Element to (refMe's NSXMLElement's elementWithName:("h5"))
(ocidH3Element's setStringValue:(strCommandText))
(ocidSetArticleElement's addChild:(ocidH3Element))
    ########################################
    #テーブル部生成開始
    set ocidTableElement to (refMe's NSXMLElement's elementWithName:("table"))
    #########【caption】
    set ocidCaptionElement to (refMe's NSXMLElement's elementWithName:("caption"))
    set strCaptionText to ((ocidFileName as text) & " : メタデータ一覧") as text
(ocidCaptionElement's setStringValue:(strCaptionText))
(ocidTableElement's addChild:(ocidCaptionElement))
    #########【colgroup】
    set ocidColgroupElement to (refMe's NSXMLElement's elementWithName:("colgroup"))
    #########【col】col生成
    #項目番号
    set ocidAddElement to (refMe's NSXMLElement's elementWithName:("col"))
    set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("LineNo"))
(ocidAddElement's addAttribute:(ocidAddNode))
(ocidColgroupElement's addChild:(ocidAddElement))
    #キー
    set ocidAddElement to (refMe's NSXMLElement's elementWithName:("col"))
    set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("キー名"))
(ocidAddElement's addAttribute:(ocidAddNode))
(ocidColgroupElement's addChild:(ocidAddElement))
    #値
    set ocidAddElement to (refMe's NSXMLElement's elementWithName:("col"))
    set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("値"))
(ocidAddElement's addAttribute:(ocidAddNode))
(ocidColgroupElement's addChild:(ocidAddElement))
    #テーブルエレメントに追加
(ocidTableElement's addChild:(ocidColgroupElement))
    #########【thead】
    set ocidTheadElement to (refMe's NSXMLElement's elementWithName:("thead"))
    set ocidTrElement to (refMe's NSXMLElement's elementWithName:("tr"))
    #項目番号
    set ocidAddElement to (refMe's NSXMLElement's elementWithName:("th"))
    set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("lineNo"))
(ocidAddElement's addAttribute:(ocidAddNode))
    set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("id") stringValue:("lineNo"))
(ocidAddElement's addAttribute:(ocidAddNode))
    set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("scope") stringValue:("col"))
(ocidAddElement's addAttribute:(ocidAddNode))
(ocidAddElement's setStringValue:("\"))
(ocidTrElement's addChild:(ocidAddElement))
    #キー
    set ocidAddElement to (refMe's NSXMLElement's elementWithName:("th"))
    set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("key"))
(ocidAddElement's addAttribute:(ocidAddNode))
    set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("id") stringValue:("key"))
(ocidAddElement's addAttribute:(ocidAddNode))
    set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("scope") stringValue:("col"))
(ocidAddElement's addAttribute:(ocidAddNode))
(ocidAddElement's setStringValue:("キー名"))
(ocidTrElement's addChild:(ocidAddElement))
    #値
    set ocidAddElement to (refMe's NSXMLElement's elementWithName:("th"))
    set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("value"))
(ocidAddElement's addAttribute:(ocidAddNode))
    set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("id") stringValue:("value"))
(ocidAddElement's addAttribute:(ocidAddNode))
    set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("scope") stringValue:("col"))
(ocidAddElement's addAttribute:(ocidAddNode))
(ocidAddElement's setStringValue:("値"))
(ocidTrElement's addChild:(ocidAddElement))
    #TRをTHEADにセット
(ocidTheadElement's addChild:(ocidTrElement))
    #THEADをテーブルにセット
(ocidTableElement's addChild:(ocidTheadElement))
    ########################################
    set numLineNo to 1 as integer
    #【tbody】
    set ocidTbodyElement to (refMe's NSXMLElement's elementWithName:("tbody"))
    repeat with itemArray in ocidSortedKeyArray
      set ocidExifValue to (ocidExifDict's valueForKey:(itemArray))
      #TRの開始
      set ocidTrElement to (refMe's NSXMLElement's elementWithName:("tr"))
      ####項番処理
      set ocidThElement to (refMe's NSXMLElement's elementWithName:("th"))
      set strSetValue to ("項目番号:" & numLineNo) as text
      set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:(strSetValue))
(ocidThElement's addAttribute:(ocidAddNode))
      set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("headers") stringValue:("LineNo"))
(ocidThElement's addAttribute:(ocidAddNode))
      set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("scope") stringValue:("col"))
(ocidThElement's addAttribute:(ocidAddNode))
(ocidThElement's setStringValue:(numLineNo as text))
(ocidTrElement's addChild:(ocidThElement))
      ####キー
      set ocidThElement to (refMe's NSXMLElement's elementWithName:("th"))
      set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:(itemArray as text))
(ocidThElement's addAttribute:(ocidAddNode))
      set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("headers") stringValue:("key"))
(ocidThElement's addAttribute:(ocidAddNode))
      set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("scope") stringValue:("col"))
(ocidThElement's addAttribute:(ocidAddNode))
      set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("class") stringValue:("tbody_th_title"))
(ocidThElement's addAttribute:(ocidAddNode))
(ocidThElement's setStringValue:(itemArray as text))
(ocidTrElement's addChild:(ocidThElement))
      ####値
      set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td"))
      set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:(ocidExifValue as text))
(ocidTdElement's addAttribute:(ocidAddNode))
      set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("headers") stringValue:("value"))
(ocidTdElement's addAttribute:(ocidAddNode))
(ocidTdElement's setStringValue:(ocidExifValue as text))
(ocidTrElement's addChild:(ocidTdElement))
      #
(ocidTbodyElement's addChild:(ocidTrElement))
      set numLineNo to numLineNo + 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"))
    #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:(3))
(ocidThElement's addAttribute:(ocidAddNode))
    set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("scope") stringValue:("row"))
(ocidThElement's addAttribute:(ocidAddNode))
    #
    set strContents to ("項目数 : " & (numLineNo as text)) as text
(ocidThElement's setStringValue:(strContents))
    #THをTRにセットして
(ocidTrElement's addChild:(ocidThElement))
    #TRをTFOOTにセット
(ocidTfootElement's addChild:(ocidTrElement))
    #TFOOTをテーブルにセット
(ocidTableElement's addChild:(ocidTfootElement))
    #テーブルをアーティクルにセット
(ocidSetArticleElement's addChild:(ocidTableElement))
    ##############################
    #HTMLにする
    ##############################
    set ocidHTML to doMakeRootElement({ocidSetHeaderElement, ocidSetArticleElement, ocidSetFooterElement, strTitleText})
    ##############################
    #保存
    ##############################
    #読み取りやすい表示
    set ocidXMLdata to (ocidHTML's XMLDataWithOptions:(refMe's NSXMLNodePrettyPrint))
    #保存
    set listDone to (ocidXMLdata's writeToURL:(ocidSaveFilePathURL) options:(refMe's NSDataWritingAtomic) |error|:(reference))
    set aliasFilePath to (ocidSaveFilePathURL's absoluteURL()) as alias
    ####【6】ブラウザで開く
    tell application "Finder"
open location aliasFilePath
    end tell
    (*
####【6】 テキストエディットで開く
tell application "TextEdit"
activate
open file aliasFilePath
end tell
*)
    
  end repeat
end open




############################################################
# 基本的なHTMLの構造
(*
doMakeRootElement({argHeaderContents, argArticleContents, argFooterContents,argTitleText})
HTMLのBODY部
header
article
footerにそれぞれAddchildするデータをリストで渡す
戻り値はRootエレメントにセットされた
NSXMLDocumentを戻すので 保存すればOK
*)
############################################################
to doMakeRootElement({argHeaderContents, argArticleContents, argFooterContents, argTitleText})
  #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)
  #
  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:(argTitleText)
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; } .tbody_th_title{text-align: left;} 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)
  #
  #ボディエレメント
  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)
ocidHeaderElement's addChild:(argHeaderContents)
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)
ocidArticleElement's addChild:(argArticleContents)
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)
ocidFooterElement's addChild:(argFooterContents)
ocidBodyElement's addChild:(ocidFooterElement)
  #ボディをROOTエレメントにセット
ocidRootElement's addChild:(ocidBodyElement)
  #ROOTをXMLにセット
ocidXMLDoc's setRootElement:(ocidRootElement)
  #値を戻す
return ocidXMLDoc
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


|

« ファイル名のフォルダを作って中に入れる(拡張子が複数ある場合の処理を変更) | トップページ | [NSXML]HTML生成基本部分(更新) »

AppleScript EXIFData」カテゴリの記事