« [python3]インストールしていないフォントのpostscript名を取得する(TTC・OTC対応) | トップページ | [Font]NameiD »

[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


|

« [python3]インストールしていないフォントのpostscript名を取得する(TTC・OTC対応) | トップページ | [Font]NameiD »

AppleScript EXIFData」カテゴリの記事