« [Muisc]Music用パネルアップデート | トップページ | [macos14]タッチIDを有効にする »

[MDLS]フォントの詳細情報(すこし修正)


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

#!/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
set appFileManager to refMe's NSFileManager's defaultManager()

###################################
#####入力ダイアログ
###################################
set ocidUserLibraryPathURLArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidUserLibraryPathURL to ocidUserLibraryPathURLArray's firstObject()
set ocidFilePathURL to ocidUserLibraryPathURL's URLByAppendingPathComponent:("Fonts") isDirectory:true
set aliasDefaultLocation to (ocidFilePathURL's absoluteURL()) as alias
set listUTI to {"public.font"}
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
set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to refMe's NSURL's fileURLWithPath:(ocidFilePath)

set strFontFilePath to ocidFilePathURL's absoluteString() as text


###ファイル名取得 と 保存用ファイル名
set ocidFileName to (ocidFilePathURL's lastPathComponent)
set strFileName to ocidFileName as text
set ocidBaseFileName to ocidFileName's stringByDeletingPathExtension
set ocidHtmlFileName to ocidBaseFileName's stringByAppendingPathExtension:"html"
set strExtensionName to ocidHtmlFileName's pathExtension() as text

############################
####出力先(再起動時に削除されます)
set ocidTemporaryDirPathURL to appFileManager's temporaryDirectory
set ocidVarFoldersDirURL to ocidTemporaryDirPathURL's URLByDeletingLastPathComponent()
set ocidTemporaryItemsPathURL to ocidVarFoldersDirURL's URLByAppendingPathComponent:("TemporaryItems")
###
set ocidUUID to refMe's NSUUID's alloc()'s init()
set strUUID to ocidUUID's UUIDString as text
set ocidSaveDirPathURL to ocidTemporaryItemsPathURL's URLByAppendingPathComponent:(strUUID)
###
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
# 777-->511 755-->493 700-->448 766-->502
ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
###保存HTML
set ocidHTMLFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(ocidHtmlFileName)
set strHTMLFilePath to ocidHTMLFilePathURL's |path|() as text
###保存PLIST
set ocidPlistFileName to ocidBaseFileName's stringByAppendingPathExtension:("plist")
set ocidPlistFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(ocidPlistFileName) isDirectory:false
set strPlistFilePath to ocidPlistFilePathURL's |path|() as text
###PLIST生成
set theCommandText to ("/usr/bin/mdls \"" & strFilePath & "\" -plist \"" & strPlistFilePath & "\"") as text
do shell script theCommandText
##############
##PLISTを読み込んでDICTに
set ocidPlistFilePathStr to refMe's NSString's stringWithString:(strPlistFilePath)
set ocidPlistFilePath to ocidPlistFilePathStr's stringByStandardizingPath()
set ocidPlistFilePathURL to refMe's NSURL's fileURLWithPath:(ocidPlistFilePath)
set ocidPlistDictM to refMe's NSMutableDictionary's alloc()'s initWithContentsOfURL:(ocidPlistFilePathURL)



########################################
#######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: 5px;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>[MDLS]" & 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> MDLS情報:" & strFileName & "</caption><thead title=\"表の項目について\"><tr><th title=\"項目の番号が最初\" style=\"width: 36px;\" scope=\"row\" >項番</th><th title=\"キーの名前が2番目\" scope=\"col\">キーの名前</th><th title=\"キーの値は3番目になっています\" scope=\"col\">キーの値</th></thead><tbody title=\"表の始まりです\">" as text
(ocidHTMLString's appendString:strTableHeader)

###ファイル名
set numLineNO to 1 as number
set strKey to "_kMDItemDisplayNameWithExtensions" as text
set strValue to (ocidPlistDictM's valueForKey:strKey) as text
set strKey to doHtmlEntitiesEnc(strKey)
set strValue to doHtmlEntitiesEnc(strValue)

set strHTMLTag to "<tr><th title=\"項番:" & strKey & "\" scope=\"row\">" & numLineNO & "</th><td title=\"キー:" & strKey & "について\">" & strKey & "</td><td title=\"キー:" & strKey & "の値\">" & strValue & "</td></tr>" as text
(ocidHTMLString's appendString:strHTMLTag)

###ファイル名表示名
set numLineNO to numLineNO + 1 as number
set strKey to "kMDItemDisplayName" as text
set strValue to (ocidPlistDictM's valueForKey:strKey) as text
set strKey to doHtmlEntitiesEnc(strKey)
set strValue to doHtmlEntitiesEnc(strValue)
set strHTMLTag to "<tr><th title=\"項番:" & strKey & "\" scope=\"row\">" & numLineNO & "</th><td title=\"キー:" & strKey & "について\">" & strKey & "</td><td title=\"キー:" & strKey & "の値\">" & strValue & "</td></tr>" as text
(ocidHTMLString's appendString:strHTMLTag)

###UTI
set numLineNO to numLineNO + 1 as number
set strKey to "kMDItemContentType" as text
set strValue to (ocidPlistDictM's valueForKey:strKey) as text
set strKey to doHtmlEntitiesEnc(strKey)
set strValue to doHtmlEntitiesEnc(strValue)
set strHTMLTag to "<tr><th title=\"項番:" & strKey & "\" scope=\"row\">" & numLineNO & "</th><td title=\"キー:" & strKey & "について\">" & strKey & "</td><td title=\"キー:" & strKey & "の値\">" & strValue & "</td></tr>" as text
(ocidHTMLString's appendString:strHTMLTag)

###種類
set numLineNO to numLineNO + 1 as number
set strKey to "kMDItemKind" as text
set strValue to (ocidPlistDictM's valueForKey:strKey) as text
set strKey to doHtmlEntitiesEnc(strKey)
set strValue to doHtmlEntitiesEnc(strValue)
set strHTMLTag to "<tr><th title=\"項番:" & strKey & "\" scope=\"row\">" & numLineNO & "</th><td title=\"キー:" & strKey & "について\">" & strKey & "</td><td title=\"キー:" & strKey & "の値\">" & strValue & "</td></tr>" as text
(ocidHTMLString's appendString:strHTMLTag)

###バージョン
set numLineNO to numLineNO + 1 as number
set strKey to "kMDItemVersion" as text
set strValue to (ocidPlistDictM's valueForKey:strKey) as text
set strKey to doHtmlEntitiesEnc(strKey)
set strValue to doHtmlEntitiesEnc(strValue)
set strHTMLTag to "<tr><th title=\"項番:" & strKey & "\" scope=\"row\">" & numLineNO & "</th><td title=\"キー:" & strKey & "について\">" & strKey & "</td><td title=\"キー:" & strKey & "の値\">" & strValue & "</td></tr>" as text
(ocidHTMLString's appendString:strHTMLTag)

###著作
set numLineNO to numLineNO + 1 as number
set strKey to "kMDItemCopyright" as text
set strValue to (ocidPlistDictM's valueForKey:strKey) as text
set strKey to doHtmlEntitiesEnc(strKey)
set strValue to doHtmlEntitiesEnc(strValue)
set strHTMLTag to "<tr><th title=\"項番:" & strKey & "\" scope=\"row\">" & numLineNO & "</th><td title=\"キー:" & strKey & "について\">" & strKey & "</td><td title=\"キー:" & strKey & "の値\">" & strValue & "</td></tr>" as text
(ocidHTMLString's appendString:strHTMLTag)

###【Array】スタイル
set numLineNO to numLineNO + 1 as number
set strKey to "com_apple_ats_name_style" as text
set ocidValue to (ocidPlistDictM's valueForKey:strKey)
log className() of ocidValue as text
set strValue to ("") as text
repeat with itemValue in ocidValue
  set itemValueEnc to doHtmlEntitiesEnc(itemValue)
  set strValue to (strValue & itemValueEnc & "<br />") as text
end repeat

set strKey to doHtmlEntitiesEnc(strKey)
set strHTMLTag to "<tr><th title=\"項番:" & strKey & "\" scope=\"row\">" & numLineNO & "</th><td title=\"キー:" & strKey & "について\">" & strKey & "</td><td title=\"キー:" & strKey & "の値\">" & strValue & "</td></tr>" as text
(ocidHTMLString's appendString:strHTMLTag)

###【Array】ポストスクリプト名
set numLineNO to numLineNO + 1 as number
set strKey to "com_apple_ats_name_postscript" as text
set ocidValue to (ocidPlistDictM's valueForKey:strKey)
set strKey to doHtmlEntitiesEnc(strKey)
log className() of ocidValue as text
set strValue to ("") as text
repeat with itemValue in ocidValue
  set itemValueEnc to doHtmlEntitiesEnc(itemValue)
  set strValue to (strValue & itemValueEnc & "<br />") as text
end repeat

set strHTMLTag to "<tr><th title=\"項番:" & strKey & "\" scope=\"row\">" & numLineNO & "</th><td title=\"キー:" & strKey & "について\">" & strKey & "</td><td title=\"キー:" & strKey & "の値\" style=\"background-color: #eee;\">" & strValue & "</td></tr>" as text
(ocidHTMLString's appendString:strHTMLTag)

###【Array】フルネーム
set numLineNO to numLineNO + 1 as number
set strKey to "com_apple_ats_name_full" as text
set ocidValue to (ocidPlistDictM's valueForKey:strKey)
set strKey to doHtmlEntitiesEnc(strKey)
set strValue to ("") as text
repeat with itemValue in ocidValue
  set itemValueEnc to doHtmlEntitiesEnc(itemValue)
  set strValue to (strValue & itemValueEnc & "<br />") as text
end repeat
set strHTMLTag to "<tr><th title=\"項番:" & strKey & "\" scope=\"row\">" & numLineNO & "</th><td title=\"キー:" & strKey & "について\">" & strKey & "</td><td title=\"キー:" & strKey & "の値\">" & strValue & "</td></tr>" as text
(ocidHTMLString's appendString:strHTMLTag)

###【Array】ファミリー名
set numLineNO to numLineNO + 1 as number
set strKey to "com_apple_ats_name_family" as text
set ocidValue to (ocidPlistDictM's valueForKey:strKey)
set strKey to doHtmlEntitiesEnc(strKey)
set strValue to ("") as text
repeat with itemValue in ocidValue
  set itemValueEnc to doHtmlEntitiesEnc(itemValue)
  set strValue to (strValue & itemValueEnc & "<br />") as text
end repeat
set strHTMLTag to "<tr><th title=\"項番:" & strKey & "\" scope=\"row\">" & numLineNO & "</th><td title=\"キー:" & strKey & "について\">" & strKey & "</td><td title=\"キー:" & strKey & "の値\">" & strValue & "</td></tr>" as text
(ocidHTMLString's appendString:strHTMLTag)

###【Array】kMDItemFonts
set numLineNO to numLineNO + 1 as number
set strKey to "kMDItemFonts" as text
set ocidValue to (ocidPlistDictM's valueForKey:strKey)
set strKey to doHtmlEntitiesEnc(strKey)
set strValue to ("") as text
repeat with itemValue in ocidValue
  set itemValueEnc to doHtmlEntitiesEnc(itemValue)
  set strValue to (strValue & itemValueEnc & "<br />") as text
end repeat
set strHTMLTag to "<tr><th title=\"項番:" & strKey & "\" scope=\"row\">" & numLineNO & "</th><td title=\"キー:" & strKey & "について\">" & strKey & "</td><td title=\"キー:" & strKey & "の値\">" & strValue & "</td></tr>" as text
(ocidHTMLString's appendString:strHTMLTag)
###【Array】その他メタデータ
set numLineNO to numLineNO + 1 as number
set strKey to "com_apple_ats_names" as text
set ocidAtsArray to (ocidPlistDictM's valueForKey:strKey)
set strKey to doHtmlEntitiesEnc(strKey)
set strValue to doHtmlEntitiesEnc(strValue)
set strHTMLTag to "<tr><th title=\"項番:" & strKey & "\" scope=\"row\">" & numLineNO & "</th><td title=\"キー:" & strKey & "について\">" & strKey & "</td><td title=\"キー:" & strKey & "の値\"></td></tr>" as text
(ocidHTMLString's appendString:strHTMLTag)

repeat with itemAtsArray in ocidAtsArray
  set numLineNO to numLineNO + 1 as number
  set strKey to "com_apple_ats_names" as text
  set strValue to (itemAtsArray) as text
  set strKey to doHtmlEntitiesEnc(strKey)
  set strValue to doHtmlEntitiesEnc(strValue)
  set strHTMLTag to "<tr><th title=\"項番:" & strKey & "\" scope=\"row\">" & numLineNO & "</th><td title=\"キー:" & strKey & "(" & numLineNO & ")について\">" & strKey & "(" & numLineNO & ") </td><td title=\"キー:" & strKey & "の値\">" & strValue & "</td></tr>" as text
(ocidHTMLString's appendString:strHTMLTag)
  
end repeat


##
(*
set numLineNO to numLineNO + 1 as number
set strKey to "com_apple_ats_name_family" as text
set strFamily to (ocidPlistDictM's valueForKey:strKey)'s firstObject() as text

set strKey to "com_apple_ats_name_style" as text
set strStyle to (ocidPlistDictM's valueForKey:strKey)'s firstObject() as text

set strAddCss to ("<style>@font-face { font-family: '" & strFamily & "'; src: url('" & strFontFilePath & "') format('ttf');}</style>") as text

set strSampleText to (strAddCss & "<p style=\"font-family: '" & strFamily & "' !important; font-size: 24px; font-style:'" & strStyle & "' !important;\">ABCDEFGHIJKLMNOPQRSTUVWXYZ<br />abcdefghijklmnopqrstuvwxyz<br />0123456789</p>") as text

set strHTMLTag to "<tr><th title=\"項番:" & strKey & "\" scope=\"row\">" & numLineNO & "</th><td title=\"表示例\">表示例</td><td title=\"キー:表示例の値\">" & strSampleText & "</td></tr>" as text
(ocidHTMLString's appendString:strHTMLTag)

*)


###最後のtfoot項目
set numLineNO to numLineNO + 1 as number
set strHTMLTagFooter to "</tbody><tfoot title=\"表の終わりです\"><tr><th title=\"項番:" & numLineNO & "\" scope=\"row\">" & numLineNO & "</th><td title=\"キーの名前\">PlistToHTMLv2</td><td title=\"キー:PlistToHTMLの値\">" & (ocidFilePath as text) & "</td></tr></tfoot></table></div>" as text
###タグを全部追加して
(ocidHTMLString's appendString:strHTMLTagFooter)
ocidHTMLString's appendString:(strHtmlEndBody)

###ファイルに書き出し
set boolWritetoUrlArray to ocidHTMLString's writeToURL:(ocidHTMLFilePathURL) atomically:true encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)


####テキストエディタで開く
(*
tell application "TextEdit"
activate
open (ocidHTMLFilePathURL as alias)
end tell
*)

####サファリで開く
set strOpenURL to ocidHTMLFilePathURL's absoluteString() as text
tell application "Safari"
  activate
  make new document with properties {name:"MDLS2HTMLv2"}
  tell window 1
    open location strOpenURL
  end tell
end tell


to doHtmlEntitiesEnc(argTEXT)
  
  ###置換レコード
  ## set recordEntityMap to {|&|:"&amp;", |<|:"&lt;", |>|:"&gt;", |"|:"&quot;", |'|:"&apos;", |=|:"&#x3D;", |+|:"&#x2B;"} as record
  set recordEntityMap to {|<|:"&lt;", |>|:"&gt;", |"|:"&quot;", |'|:"&apos;", |=|:"&#x3D;", |+|:"&#x2B;", |©|:"&copy;", |®|:"&reg;", |™|:"&trade;", |€|:"&euro;", |£|:"&pound;", |¥|:"&yen;", |...|:"&hellip;"} as record
  ###ディクショナリにして
  set ocidEntityMap to refMe's NSDictionary's alloc()'s initWithDictionary:(recordEntityMap)
  ###キーの一覧を取り出します
  set ocidAllKeys to ocidEntityMap's allKeys()
  
  ##通常テキストの場合
  set strText to argTEXT as text
  ###選択中テキスト
  set ocidText to refMe's NSString's stringWithString:(strText)
  ###可変テキストにして
  set ocidTextM to refMe's NSMutableString's alloc()'s initWithCapacity:0
ocidTextM's setString:(ocidText)
  ###&だけ先に処理しておく
  set ocidTextM to (ocidTextM's stringByReplacingOccurrencesOfString:("&") withString:("&amp;"))
  ###取り出したキー一覧を順番に処理
  repeat with itemAllKey in ocidAllKeys
    set strItemKey to itemAllKey as text
    ##キーの値を取り出して
    set strValue to (ocidEntityMap's valueForKey:(itemAllKey)) as text
    ##置換
    set ocidTextM to (ocidTextM's stringByReplacingOccurrencesOfString:(strItemKey) withString:(strValue))
    ##次の変換に備える
    set ocidTextM to ocidTextM
  end repeat
  
return (ocidTextM as text)
end doHtmlEntitiesEnc
return

|

« [Muisc]Music用パネルアップデート | トップページ | [macos14]タッチIDを有効にする »

Fonts」カテゴリの記事