EXIFData

[PDF]PDFのメタデータの取り出し方法いろいろ(デモ)


AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#! /usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004#
005# 
006#  com.cocolog-nifty.quicktimer.icefloe
007----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
008use AppleScript version "2.8"
009use framework "Foundation"
010use framework "AppKit"
011use framework "PDFKit"
012use scripting additions
013
014property refMe : a reference to current application
015
016################
017#パス
018set strName to (name of current application) as text
019if strName is "osascript" then
020  tell application "Finder" to activate
021else
022  tell current application to activate
023end if
024#
025set appFileManager to refMe's NSFileManager's defaultManager()
026set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
027set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
028set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
029###ANY
030set listUTI to {"public.data"}
031set strMes to ("ファイルを選んでください") as text
032set strPrompt to ("ファイルを選んでください") as text
033try
034  ### ファイル選択時
035  set aliasFilePath to (choose file strMes with prompt strPrompt default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias
036on error
037  log "エラーしました"
038  return "エラーしました"
039end try
040#入力ファイル
041set strFilePath to (POSIX path of aliasFilePath) as text
042set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
043set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
044set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
045set ocidFileName to ocidFilePathURL's lastPathComponent()
046#出力ファイル
047set appFileManager to refMe's NSFileManager's defaultManager()
048set ocidTempDirURL to appFileManager's temporaryDirectory()
049set ocidUUID to refMe's NSUUID's alloc()'s init()
050set ocidUUIDString to ocidUUID's UUIDString
051set ocidSaveDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:true
052#
053set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
054# 777-->511 755-->493 700-->448 766-->502
055ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
056set listDone to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error| :(reference)
057if (item 1 of listDone) is true then
058  log "正常処理"
059else if (item 2 of listDone) ≠ (missing value) then
060  set strErrorNO to (item 2 of listDone)'s code() as text
061  set strErrorMes to (item 2 of listDone)'s localizedDescription() as text
062  refMe's NSLog("■:" & strErrorNO & strErrorMes)
063  return "エラーしました" & strErrorNO & strErrorMes
064end if
065#
066set ocidTMPFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(ocidFileName) isDirectory:(false)
067set ocidBaseFilePathURL to ocidTMPFilePathURL's URLByDeletingPathExtension()
068set ocidSaveFilePathURL to ocidBaseFilePathURL's URLByAppendingPathExtension:("xmp")
069set strSaveFilePath to (ocidSaveFilePathURL's |path|()) as text
070################
071#getResourceValue 作成日やアクセス権等一般的な項目はこれで取れる
072#pdf:KeywordsといったPDFのプロパティ
073set listResponse to (ocidFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLContentModificationDateKey) |error| :(reference))
074
075if (item 1 of listResponse) is true then
076  set ocidModificationDate to (item 2 of listResponse)
077  log ocidModificationDate as date
078else if (item 1 of listResponse) is false then
079  set strErrorNO to (item 3 of listDone)'s code() as text
080  set strErrorMes to (item 3 of listDone)'s localizedDescription() as text
081  refMe's NSLog("■:" & strErrorNO & strErrorMes)
082  return "エラーしました" & strErrorNO & strErrorMes
083end if
084
085################
086#NSData's
087set ocidOption to (refMe's NSDataReadingMappedIfSafe)
088set listResponse to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidFilePathURL) options:(ocidOption) |error| :(reference)
089if (item 2 of listResponse) = (missing value) then
090  log "正常処理"
091  set ocidReadData to (item 1 of listResponse)
092else if (item 2 of listResponse) ≠ (missing value) then
093  set strErrorNO to (item 2 of listDone)'s code() as text
094  set strErrorMes to (item 2 of listDone)'s localizedDescription() as text
095  refMe's NSLog("■:" & strErrorNO & strErrorMes)
096  return "エラーしました" & strErrorNO & strErrorMes
097end if
098
099################
100#ドキュメントをNSDataから取得
101set ocidActivDoc to refMe's PDFDocument's alloc()'s initWithData:(ocidReadData)
102
103################
104#アトリビュートを取得して
105set ocidAttributes to ocidActivDoc's documentAttributes()
106set listKeys to ocidAttributes's allKeys() as list
107
108repeat with itemKey in listKeys
109  log itemKey as text
110  if itemKey contains "Date" then
111    log (ocidAttributes's valueForKey:(itemKey)) as date
112  else if itemKey contains "Keywords" then
113    log (ocidAttributes's valueForKey:(itemKey)) as list
114  else
115    log (ocidAttributes's valueForKey:(itemKey)) as text
116  end if
117end repeat
118################
119#Finderコメント
120set aliasFilePath to (ocidFilePathURL's absoluteURL()) as alias
121tell application "Finder"
122  tell file aliasFilePath
123    log comment as text
124  end tell
125end tell
126
127################
128#XMP取得
129try
130  #コマンド
131  set strCommandText to ("/usr/bin/awk  -v start=\"<x:xmpmeta\" -v end=\"</x:xmpmeta>\" '$0 ~ start, $0 ~ end' \"" & strFilePath & "\"") as text
132  set strXMP to (do shell script strCommandText) as text
133on error
134  return "エラーしました"
135end try
136set ocidTMPstring to refMe's NSString's stringWithString:(strXMP)
137#改行をUNIXに強制
138set ocidXMPstring to (ocidTMPstring's stringByReplacingOccurrencesOfString:("\r\n") withString:("\n"))
139set ocidXMPstring to (ocidXMPstring's stringByReplacingOccurrencesOfString:("\r") withString:("\n"))
140set ocidXMPstring to (ocidXMPstring's stringByReplacingOccurrencesOfString:("\n\n") withString:("\n"))
141
142#XMLDocに
143set ocidOption to (refMe's NSXMLNodePreserveAll) + (refMe's NSXMLDocumentTidyXML)
144set listResponse to refMe's NSXMLDocument's alloc()'s initWithXMLString:(ocidXMPstring) options:(ocidOption) |error| :(reference)
145if (item 2 of listResponse) = (missing value) then
146  log "正常処理"
147  set ocidXMLDoc to (item 1 of listResponse)
148else if (item 2 of listResponse) ≠ (missing value) then
149  log (item 2 of listResponse)'s code() as text
150  log (item 2 of listResponse)'s localizedDescription() as text
151  log "NSXMLDocumentエラー 警告がありました"
152  set ocidXMLDoc to (item 1 of listResponse)
153end if
154#ROOTを取り出して
155set ocidRootElement to ocidXMLDoc's rootElement()
156#値を表示
157log ocidRootElement's stringValue() as list
AppleScriptで生成しました

|

[NSImageEXIFData] NSImageのEXIFDataの取得


AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#! /usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004# com.cocolog-nifty.quicktimer.icefloe
005----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
006use AppleScript version "2.8"
007use framework "Foundation"
008use framework "Quartz"
009use framework "CoreImage"
010use framework "AppKit"
011use scripting additions
012
013property refMe : a reference to current application
014
015on run
016  
017  set aliasIconPass to (POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/MultipleItemsIcon.icns") as alias
018  set strDialogText to "ドロップしても利用できます"
019  set strTitleText to "画像ファイルを選んでください"
020  set listButton to {"ファイルを選びます", "キャンセル"} as list
021  display dialog strDialogText buttons listButton default button 1 cancel button 2 with title strTitleText with icon aliasIconPass giving up after 1 with hidden answer
022  
023  set aliasDefaultLocation to (path to desktop folder from user domain) as alias
024  set listChooseFileUTI to {"public.image"}
025  set strPromptText to "イメージファイルを選んでください" as text
026  set strPromptMes to "イメージファイルを選んでください" as text
027  set listAliasFilePath to (choose file strPromptMes with prompt strPromptText default location (aliasDefaultLocation) of type listChooseFileUTI with showing package contents, invisibles and multiple selections allowed) as list
028  
029  -->値をOpenに渡たす
030  open listAliasFilePath
031end run
032
033
034on open listAliasFilePath
035  
036  ##########################
037  ###出力用のテキスト
038  set ocidOutPutString to refMe's NSMutableString's alloc()'s initWithCapacity:(0)
039  
040  ####ファイルの数だけ繰り返し
041  repeat with itemAliasFilePath in listAliasFilePath
042    ####まずはUNIXパスにして
043    set strFilePath to (POSIX path of itemAliasFilePath) as text
044    set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath))
045    set ocidFilePath to ocidFilePathStr's stringByStandardizingPath
046    set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath))
047    
048    #####################
049    #### 本処理
050    ####データ読み込み NSDATA
051    set ocidOption to (refMe's NSDataReadingMappedIfSafe)
052    set listReadData to (refMe's NSData's dataWithContentsOfURL:(ocidFilePathURL) options:(ocidOption) |error| :(reference))
053    set ocidReadData to (item 1 of listReadData)
054    #
055    set ocidReadImageRep to (refMe's NSBitmapImageRep's alloc()'s initWithData:(ocidReadData))
056    #主にカメラデータとしてのEXIFを取得するので
057    #色々な種類のEXIF情報を取得できるわけでは無い
058    set ocidExifDict to (ocidReadImageRep's valueForProperty:(refMe's NSImageEXIFData))
059    log ocidExifDict as record
060    set ocidAllKeys to ocidExifDict's allKeys()
061    repeat with itemKey in ocidAllKeys
062      set ocidGetValue to (ocidExifDict's valueForKey:(itemKey))
063      set strClassName to ocidGetValue's className() as text
064      log itemKey
065      log strClassName
066      if (strClassName) contains "Data" then
067        #Dataは処理しない
068      else if (strClassName) contains "Array" then
069        #Arrayは処理しない
070      else if (strClassName) contains "Dict" then
071        #DICTは処理しない
072      else
073        set strSetVale to ((itemKey as text) & ":\t" & ocidGetValue) as text
074        (ocidOutPutString's appendString:(strSetVale))
075        (ocidOutPutString's appendString:("\n"))
076      end if
077    end repeat
078    ######
079    set ocidColorSpace to ocidReadImageRep's colorSpace()
080    log ocidColorSpace
081    set ocidColorSpaceName to ocidReadImageRep's colorSpaceName()
082    log ocidColorSpaceName as text
083    (ocidOutPutString's appendString:(ocidColorSpaceName))
084    (ocidOutPutString's appendString:("\n"))
085    #
086    set strColorName to ocidColorSpace's localizedName as text
087    set numColorNO to ocidColorSpace's colorSpaceModel as integer
088    log strColorName
089    (ocidOutPutString's appendString:(strColorName))
090    (ocidOutPutString's appendString:("\n"))
091    log numColorNO
092    (ocidOutPutString's appendString:(numColorNO as text))
093    (ocidOutPutString's appendString:("\n"))
094    
095    (*
096  https://quicktimer.cocolog-nifty.com/icefloe/2024/02/post-38db59.html
097  
098NSColorSpaceModelUnknown(0): 未知のカラーモデル
099NSColorSpaceModelGray(1): グレースケールカラーモデル
100NSColorSpaceModelRGB(3): RGBカラーモデル
101NSColorSpaceModelCMYK(4): CMYKカラーモデル
102NSColorSpaceModelLAB(5): CIELABカラーモデル
103NSColorSpaceModelDeviceN(6): デバイスNカラーモデル
104NSColorSpaceModelIndexed(7): インデックスカラーモデル
105NSColorSpaceModelPattern(8): パターンカラーモデル
106  *)
107    
108    ###テキスト保存先(再起動時に自動で削除されます)
109    set appFileManager to refMe's NSFileManager's defaultManager()
110    set ocidTempDirURL to appFileManager's temporaryDirectory()
111    set ocidUUID to refMe's NSUUID's alloc()'s init()
112    set ocidUUIDString to ocidUUID's UUIDString
113    set ocidSaveDirPathURL to (ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:true)
114    #
115    set ocidAttrDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
116    # 777-->511 755-->493 700-->448 766-->502
117    (ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions))
118    set listDone to (appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error| :(reference))
119    if (item 1 of listDone) is true then
120      log "createDirectoryAtURL 正常処理"
121    else if (item 2 of listDone) ≠ (missing value) then
122      log (item 2 of listDone)'s code() as text
123      log (item 2 of listDone)'s localizedDescription() as text
124      return "createDirectoryAtURL エラーしました"
125    end if
126    
127    ###パス
128    set strFileName to "NSimageProperties.txt" as text
129    set ocidSaveFilePathURL to (ocidSaveDirPathURL's URLByAppendingPathComponent:(strFileName) isDirectory:false)
130    ###保存
131    set listDone to (ocidOutPutString's writeToURL:(ocidSaveFilePathURL) atomically:(true) encoding:(refMe's NSUTF8StringEncoding) |error| :(reference))
132    if (item 1 of listDone) is true then
133      log "writeToURL 正常処理"
134    else if (item 2 of listDone) ≠ (missing value) then
135      log (item 2 of listDone)'s code() as text
136      log (item 2 of listDone)'s localizedDescription() as text
137      log ocidOutPutString as text
138      return "writeToURL エラーしました"
139    end if
140    ##開く
141    
142    set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
143    set boolDone to (appSharedWorkspace's openURL:(ocidSaveFilePathURL))
144    if (boolDone) is true then
145      return "openURL 正常処理"
146    else if (boolDone) is false then
147      return "openURL エラーしました"
148    end if
149    
150    
151  end repeat
152  
153  
154  
155  
156end open
AppleScriptで生成しました

|

HEICのOrientation (画像の表示の回転)


AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#! /usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#HEICはPDFと同様に 表示の回転 をセットできる
004(* HEICのOrientationの値
0051: "天地向反転無 0"
0062: "天地向左右反転 0"
0073: "天地逆180度回転 180"
0084: "天地逆180度回転 左右反転 180"
0095: "左90度回転左右反転 270"
0106: "右90度回転 90"
0117: "右90度回転左右反転 90"
0128: "左90度回転 270"
013https://developer.apple.com/documentation/imageio/cgimagepropertyorientation
014*)
015#com.cocolog-nifty.quicktimer.icefloe
016----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
017use AppleScript version "2.8"
018use framework "Foundation"
019use framework "CoreImage"
020use framework "AppKit"
021use scripting additions
022
023property refMe : a reference to current application
024
025set recordOrientation to {|1|:"天地向反転無 0", |2|:"天地向左右反転 0", |3|:"天地逆180度回転 180", |4|:"天地逆180度回転 左右反転 180", |5|:"左90度回転左右反転 270", |6|:"右90度回転 90", |7|:"右90度回転左右反転 90", |8|:"左90度回転 270"} as record
026set ocidOrientationDict to refMe's NSDictionary's dictionaryWithDictionary:(recordOrientation)
027
028log (refMe's kCGImagePropertyOrientationUp) as integer
029-->1
030log (refMe's kCGImagePropertyOrientationUpMirrored) as integer
031-->2
032log (refMe's kCGImagePropertyOrientationDown) as integer
033-->3
034log (refMe's kCGImagePropertyOrientationDownMirrored) as integer
035-->4
036log (refMe's kCGImagePropertyOrientationLeftMirrored) as integer
037-->5
038log (refMe's kCGImagePropertyOrientationRight) as integer
039-->6
040log (refMe's kCGImagePropertyOrientationRightMirrored) as integer
041-->7
042log (refMe's kCGImagePropertyOrientationLeft) as integer
043-->8
044
045
046##パス
047set strFilePath to ("/System/Library/Desktop Pictures/Hello Metallic Blue.heic") as text
048set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
049set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
050set ocidFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:(false)
051
052###################################
053#読み込みNSDATA
054set ocidOption to (refMe's NSDataReadingMappedIfSafe)
055set listResponse to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidFilePathURL) options:(ocidOption) |error| :(reference)
056if (item 2 of listResponse) = (missing value) then
057  log "正常処理"
058  set ocidReadData to (item 1 of listResponse)
059else if (item 2 of listResponse) ≠ (missing value) then
060  log (item 2 of listResponse)'s code() as text
061  log (item 2 of listResponse)'s localizedDescription() as text
062  return "エラーしました"
063end if
064
065###################################
066#propertiesから取得する方法
067#CIImageに読み込んで
068set ocidCIImageData to (refMe's CIImage's imageWithData:(ocidReadData) options:(missing value))
069#メタデータ
070set ocidOripertesDict to ocidCIImageData's |properties|()
071#回転
072set ocidOrientation to ocidOripertesDict's valueForKey:("Orientation")
073set strOrientation to ocidOrientation as text
074if strOrientation is not "1" then
075  log "画像に表示の回転がセットされています"
076  log (ocidOrientationDict's valueForKey:(strOrientation)) as text
077else
078  log "画像は現在天地向きです"
079  log (ocidOrientationDict's valueForKey:(strOrientation)) as text
080end if
081
082
AppleScriptで生成しました

|

[CIImage]画像のメタデータを取得 表示する(テキスト表示簡易版)


AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#! /usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#com.cocolog-nifty.quicktimer.icefloe
004#
005----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
006use AppleScript version "2.8"
007use framework "Foundation"
008use framework "CoreImage"
009use framework "AppKit"
010use scripting additions
011
012property refMe : a reference to current application
013
014
015
016on run
017  
018  set aliasIconPass to (POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/MultipleItemsIcon.icns") as alias
019  set strDialogText to "ドロップしても利用できます"
020  set strTitleText to "画像ファイルを選んでください"
021  set listButton to {"ファイルを選びます", "キャンセル"} as list
022  display dialog strDialogText buttons listButton default button 1 cancel button 2 with title strTitleText with icon aliasIconPass giving up after 1 with hidden answer
023  
024  set aliasDefaultLocation to (path to desktop folder from user domain) as alias
025  set listChooseFileUTI to {"public.image"}
026  set strPromptText to "イメージファイルを選んでください" as text
027  set strPromptMes to "イメージファイルを選んでください" as text
028  set listAliasFilePath to (choose file strPromptMes with prompt strPromptText default location (aliasDefaultLocation) of type listChooseFileUTI with showing package contents, invisibles and multiple selections allowed) as list
029  -->値をOpenに渡たす
030  open listAliasFilePath
031end run
032
033
034on open listAliasFilePath
035  ###出力用のテキスト
036  set ocidOutPutString to refMe's NSMutableString's alloc()'s initWithCapacity:(0)
037  #画像の数だけ繰り返し
038  repeat with itemAliasFilePath in listAliasFilePath
039    ###入力ファイルパス
040    set aliasFilePath to itemAliasFilePath as alias
041    set strFilePath to (POSIX path of aliasFilePath) as text
042    (ocidOutPutString's appendString:(strFilePath))
043    (ocidOutPutString's appendString:("\n"))
044    set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath))
045    set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
046    set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
047    ###イメージ読み込み
048    set ocidImageData to (refMe's CIImage's imageWithContentsOfURL:(ocidFilePathURL))
049    set ocidPropertiesDict to ocidImageData's |properties|()
050    set ocidAllKeys to ocidPropertiesDict's allKeys()
051    ###プロパティの数だけ繰り返す
052    repeat with itemKey in ocidAllKeys
053      if (itemKey as text) contains "{" then
054        set ocidValueDict to (ocidPropertiesDict's objectForKey:(itemKey))
055        set ocidValueAllKeys to ocidValueDict's allKeys()
056        repeat with itemValueKey in ocidValueAllKeys
057          set ocidChilValue to (ocidValueDict's objectForKey:(itemValueKey))
058          if (ocidChilValue's className() as text) contains "Array" then
059            log "Arrayの場合は何もしない"
060          else if (ocidChilValue's className() as text) contains "Data" then
061            log "Dataの場合は何もしない"
062          else if (ocidChilValue's className() as text) contains "Dict" then
063            log "Dictの場合は何もしない"
064          else
065            set strSetValue to (itemValueKey as text) & " : " & (ocidChilValue as text)
066            (ocidOutPutString's appendString:(strSetValue))
067            (ocidOutPutString's appendString:("\n"))
068          end if
069        end repeat
070      else
071        set ocidValue to (ocidPropertiesDict's valueForKey:(itemKey))
072        set strSetValue to (itemKey as text) & " : " & (ocidValue as text)
073        (ocidOutPutString's appendString:(strSetValue))
074        (ocidOutPutString's appendString:("\n"))
075      end if
076    end repeat
077    (ocidOutPutString's appendString:("\n"))
078    (ocidOutPutString's appendString:("\n"))
079  end repeat
080  
081  ###テキスト保存先(再起動時に自動で削除されます)
082  set appFileManager to refMe's NSFileManager's defaultManager()
083  set ocidTempDirURL to appFileManager's temporaryDirectory()
084  set ocidUUID to refMe's NSUUID's alloc()'s init()
085  set ocidUUIDString to ocidUUID's UUIDString
086  set ocidSaveDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:true
087  #
088  set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
089  # 777-->511 755-->493 700-->448 766-->502
090  ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
091  set listDone to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error| :(reference)
092  if (item 1 of listDone) is true then
093    log "createDirectoryAtURL 正常処理"
094  else if (item 2 of listDone) ≠ (missing value) then
095    log (item 2 of listDone)'s code() as text
096    log (item 2 of listDone)'s localizedDescription() as text
097    return "createDirectoryAtURL エラーしました"
098  end if
099  
100  ###パス
101  set strFileName to "CIimageProperties.txt" as text
102  set ocidSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strFileName) isDirectory:false
103  ###保存
104  set listDone to ocidOutPutString's writeToURL:(ocidSaveFilePathURL) atomically:(true) encoding:(refMe's NSUTF8StringEncoding) |error| :(reference)
105  if (item 1 of listDone) is true then
106    log "writeToURL 正常処理"
107  else if (item 2 of listDone) ≠ (missing value) then
108    log (item 2 of listDone)'s code() as text
109    log (item 2 of listDone)'s localizedDescription() as text
110    log ocidOutPutString as text
111    return "writeToURL エラーしました"
112  end if
113  ##開く
114  
115  set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
116  set boolDone to appSharedWorkspace's openURL:(ocidSaveFilePathURL)
117  if (boolDone) is true then
118    return "openURL 正常処理"
119  else if (boolDone) is false then
120    return "openURL エラーしました"
121  end if
122  
123end open
AppleScriptで生成しました

|

[exiftool]拡張子の無いファイルに拡張子をつける


AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#! /usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004# exiftoolの判定はまぁ9割は正しいかな
005# com.cocolog-nifty.quicktimer.icefloe
006----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
007##自分環境がos12なので2.8にしているだけです
008use AppleScript version "2.8"
009use framework "Foundation"
010use scripting additions
011
012property refMe : a reference to current application
013set appFileManager to refMe's NSFileManager's defaultManager()
014
015################################################
016###設定項目 ffmpegへのパス
017#set strBinFilePath to ("/usr/local/bin/exiftool/exiftool") as text
018set strBinFilePath to ("~/bin/exiftool/exiftool") as text
019################################################
020set ocidBinPathStr to refMe's NSString's stringWithString:(strBinFilePath)
021set ocidBinPath to ocidBinPathStr's stringByStandardizingPath()
022set strBinFilePath to ocidBinPath as text
023
024#############################
025###入力ファイル
026#############################
027tell current application
028  set strName to name as text
029end tell
030####スクリプトメニューから実行したら
031if strName is "osascript" then
032  tell application "Finder" to activate
033else
034  tell current application to activate
035end if
036############ デフォルトロケーション
037set appFileManager to refMe's NSFileManager's defaultManager()
038set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
039set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
040set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
041####UTIリスト
042set listUTI to {"public.item"}
043####ダイアログを出す
044set listAliasFilePath to (choose file with prompt "ファイルを選んでください" default location (aliasDefaultLocation) of type listUTI with invisibles, showing package contents and multiple selections allowed) as list
045
046repeat with itemFilePath in listAliasFilePath
047  
048  ###入力ファイル
049  set strFilePath to (POSIX path of itemFilePath) as text
050  set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath))
051  set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
052  set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
053  #拡張子を取る
054  set ocidBaseFilePathURL to ocidFilePathURL's URLByDeletingPathExtension()
055  
056  #############################
057  #拡張子の取得
058  set strCommandText to ("\"" & strBinFilePath & "\"  -FileTypeExtension \"" & strFilePath & "\"") as text
059  try
060    #コマンド実行
061    set strResponse to (do shell script strCommandText) as text
062    #戻り値をスペース区切りでリストにして
063    set AppleScript's text item delimiters to " "
064    set listResponse to every text item of strResponse
065    set AppleScript's text item delimiters to ""
066    #最後の項目が戻り値としての拡張子
067    set strExtension to last item of listResponse
068  on error
069    set strExtension to "" as text
070  end try
071  #拡張子を付与して
072  set ocidSaveFilePathURL to (ocidBaseFilePathURL's URLByAppendingPathExtension:(strExtension))
073  #移動でリネーム
074  set listDone to (appFileManager's moveItemAtURL:(ocidFilePathURL) toURL:(ocidSaveFilePathURL) |error| :(reference))
075  
076  if (item 1 of listDone) is true then
077    log "正常処理"
078  else if (item 2 of listDone) ≠ (missing value) then
079    log (item 2 of listDone)'s code() as text
080    log (item 2 of listDone)'s localizedDescription() as text
081    return "エラーしました"
082  end if
083  
084end repeat
085
086
087
088return
AppleScriptで生成しました

|

[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


|

[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


|

その他のカテゴリー

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