« [applescript]bashでのテンポラリー キャッシュ ゴミ箱 起動時に削除する項目 | トップページ | [Bash]OneDriveアップデート »

[MDLS]フォント情報を表示する

こんな感じのHTMLを出力します
MDLS情報:A-OTF Jun Pro 101.otf
項番キーの名前キーの値
1_kMDItemDisplayNameWithExtensionsA-OTF Jun Pro 101.otf
2kMDItemDisplayNameA-OTF Jun Pro 101.otf
3kMDItemContentTypepublic.opentype-font
4kMDItemKindOpenType®フォント
5kMDItemVersionOTF 1.002;PS 1.001;Core 1.0.31;makeotf.lib1.4.1585;ATK150911JP M001
6kMDItemCopyrightFont ? Copyright 2002 Morisawa and Company Limited. All rights reserved.
7com_apple_ats_name_style101
8com_apple_ats_name_postscriptJun101Pro-Light
9com_apple_ats_name_full(En)A-OTF Jun Pro 101
10com_apple_ats_name_full(Jp)A-OTF じゅん Pro 101
11com_apple_ats_name_family(En)A-OTF Jun Pro
12com_apple_ats_name_family(Jp)A-OTF じゅん Pro
13com_apple_ats_names
14com_apple_ats_names(14) 101
15com_apple_ats_names(15) A-OTF Jun Pro
16com_apple_ats_names(16) A-OTF Jun Pro 101
17com_apple_ats_names(17) A-OTF じゅん Pro
18com_apple_ats_names(18) A-OTF じゅん Pro 101
19com_apple_ats_names(19) Font ? Copyright 2002 Morisawa and Company Limited. All rights reserved.
20com_apple_ats_names(20) Font © Copyright 2002 Morisawa and Company Limited. All rights reserved.
21com_apple_ats_names(21) Jun101Pro-Light
22com_apple_ats_names(22) Morisawa and Company Limited
23com_apple_ats_names(23) Morisawa and Company Limited 株式会社モリサワ
24com_apple_ats_names(24) OTF 1.002;PS 1.001;Core 1.0.31;makeotf.lib1.4.1585;ATK150911JP M001
25com_apple_ats_names(25) Regular
26com_apple_ats_names(26) 株式会社モリサワ
27PlistToHTMLv2/Users/XXXXXXXXXXX/Library/Fonts/A-OTF じゅん Pro/A-OTF Jun Pro 101.otf

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

#!/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 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 ocidHTMLFilePathURL to ocidTemporaryItemsPathURL's URLByAppendingPathComponent:(ocidHtmlFileName)
set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidTemporaryItemsPathURL) withIntermediateDirectories:true attributes:(missing value) |error|:(reference)

############################
##PLIST生成(再起動時に削除されます)
set ocidPlistFileName to ocidBaseFileName's stringByAppendingPathExtension:"plist"
set ocidPlistFilePathURL to ocidTemporaryDirPathURL's URLByAppendingPathComponent:(ocidPlistFileName) isDirectory:false
set strPlistFilePath to ocidPlistFilePathURL's |path|() as text
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 listReadData to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidPlistFilePathURL) options:(refMe's NSDataReadingMappedIfSafe) |error|:(reference)
set coidReadData to item 1 of listReadData
set ocidFromat to (refMe's NSPropertyListXMLFormat_v1_0)
set listPlistEditDataArray to refMe's NSPropertyListSerialization's propertyListWithData:(coidReadData) options:0 format:(ocidFromat) |error|:(reference)
set ocidPlistDictM to item 1 of listPlistEditDataArray


########################################
#######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;\">項番</th><th title=\"キーの名前が2番目\">キーの名前</th><th title=\"キーの値は3番目になっています\">キーの値</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 strHTMLTag to "<tr><td title=\"項番:" & strKey & "\">" & numLineNO & "</td><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 strHTMLTag to "<tr><td title=\"項番:" & strKey & "\">" & numLineNO & "</td><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 "kMDItemContentType" as text
set strValue to (ocidPlistDictM's valueForKey:strKey) as text
set strHTMLTag to "<tr><td title=\"項番:" & strKey & "\">" & numLineNO & "</td><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 strHTMLTag to "<tr><td title=\"項番:" & strKey & "\">" & numLineNO & "</td><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 strHTMLTag to "<tr><td title=\"項番:" & strKey & "\">" & numLineNO & "</td><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 strHTMLTag to "<tr><td title=\"項番:" & strKey & "\">" & numLineNO & "</td><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 "com_apple_ats_name_style" as text
set strValue to (ocidPlistDictM's valueForKey:strKey) as text
set strHTMLTag to "<tr><td title=\"項番:" & strKey & "\">" & numLineNO & "</td><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 "com_apple_ats_name_postscript" as text
set strValue to (ocidPlistDictM's valueForKey:strKey) as text
set strHTMLTag to "<tr><td title=\"項番:" & strKey & "\">" & numLineNO & "</td><td title=\"キー:" & strKey & "について\">" & strKey & "</td><td title=\"キー:" & strKey & "の値\" style=\"background-color: #eee;\">" & strValue & "</td></tr>" as text
(ocidHTMLString's appendString:strHTMLTag)

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

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

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

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

set numLineNO to numLineNO + 1 as number
set strKey to "com_apple_ats_names" as text
set ocidAtsArray to (ocidPlistDictM's valueForKey:strKey)
set strHTMLTag to "<tr><td title=\"項番:" & strKey & "\">" & numLineNO & "</td><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 strHTMLTag to "<tr><td title=\"項番:" & strKey & "\">" & numLineNO & "</td><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
###最後のtfoot項目
set strHTMLTagFooter to "</tbody><tfoot title=\"表の終わりです\"><tr><td title=\"項番:" & numLineNO & "\">" & numLineNO & "</td><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


return

|

« [applescript]bashでのテンポラリー キャッシュ ゴミ箱 起動時に削除する項目 | トップページ | [Bash]OneDriveアップデート »

AppleScript Fonts」カテゴリの記事