20260610

【ATS-FontValidator】JSONに出力する

【ATS-FontValidator】JSONに出力する

NOTE記事一覧ですnote.com
 

【Safari・FireFox用Script Editorで開く】 |

FontValidator2JSON.scpt.scpt
ソース
001#!/usr/bin/env osascript
002#coding: utf-8
003----+----1----+----2----+-----3----+----4----+----5----+----6----+----7--
004(*
005
006/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ATS.framework/Versions/A/Support/FontValidator 
007[-help -version -local -quiet -ios_only -pedantic 
008[-report -report_output OUTPUT_FILE_PATH -relative_path] 
009[FONT_FILE_OR_DIR_PATH]]
010
011Validates font files are adequate to use with the OS. 
012If a directory is specified, it recursively examines font files found
013
014-local          Performs all validation in-process. Default validation is performed by a separate process
015-quiet          Suppress progress information and errors
016-ios_only       Fonts not supported by iOS are treated as errors
017-duplicates     check for duplicates
018-dynamic        perform dynamic validation (runtime checks against ATS/CT APIs)
019-only_fonts     Any file that isn't a font file will be reported as an error
020-pedantic       Reports non-font files as errors
021-showSuccesses  Report shows names of successful tests
022-showWarnings   Report shows warnings
023-warningAsError Warning presence indicates validation failure. (-showWarnings implied)
024-report_output  Specify a file to hold the report. If not specified stdout will be used
025-relative_path  File paths in report are relative to the base path passed in. 
026Warning: this may yield similar paths if 2 input directorys contain similar directory structures
027
028
029
030com.cocolog-nifty.quicktimer.icefloe *)
031----+----1----+----2----+-----3----+----4----+----5----+----6----+----7--
032use AppleScript version "2.8"
033use framework "Foundation"
034use framework "AppKit"
035use framework "UniformTypeIdentifiers"
036use scripting additions
037
038property refMe : a reference to current application
039
040#############################
041#
042set strBinPath to ("/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ATS.framework/Versions/A/Support/FontValidator") as text
043#############################
044#ダイアログ
045set appFileManager to refMe's NSFileManager's defaultManager()
046set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
047set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
048set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
049#
050set listUTI to {"public.font"} as list
051set strMes to ("フォントを選択してください") as text
052set strPrompt to ("フォントを選択してください") as text
053try
054   tell application "SystemUIServer"
055      activate
056      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
057   end tell
058on error strErrMes number numErrNo
059   log strErrMes & numErrNo
060   return false
061end try
062
063#
064set strFilePath to (POSIX path of aliasFilePath) as text
065set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath))
066set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
067set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:(false))
068#
069set ocidFileName to ocidFilePathURL's lastPathComponent()
070set ocidFileName to ocidFileName's decomposedStringWithCanonicalMapping()
071set ocidBaseFileName to ocidFileName's stringByDeletingPathExtension()
072
073#############################
074#
075set strFileExtension to ("json") as text
076set strSaveFileName to (ocidBaseFileName's stringByAppendingPathExtension:(strFileExtension)) as text
077#
078set strMsg to ("保存先を指定してください") as text
079set strPrompt to ("保存先を指定してください") as text
080try
081   tell application "SystemUIServer"
082      activate
083      set aliasSaveFilePath to (choose file name strMsg default location aliasDefaultLocation default name strSaveFileName with prompt strPrompt) as «class furl»
084   end tell
085on error strErrMes number numErrNo
086   return strErrMes & numErrNo
087end try
088set strSaveFilePath to (POSIX path of aliasSaveFilePath) as text
089set ocidSaveFilePath to refMe's NSString's stringWithString:(strSaveFilePath)
090set ocidSaveFilePathURL to refMe's NSURL's fileURLWithPath:(ocidSaveFilePath)
091set strFileExtensionName to ocidSaveFilePathURL's pathExtension() as text
092#ダイアログで拡張子を取っちゃった時対策
093if strFileExtensionName is not strFileExtension then
094   set ocidSaveFilePathURL to ocidSaveFilePathURL's URLByAppendingPathExtension:(strFileExtension)
095end if
096set ocidSaveFilePath to ocidSaveFilePathURL's |path|()
097
098
099#############################
100#エスケープ
101set strBinPath to doPathEscape(strBinPath)
102set ocidFilePath to doPathEscape(ocidFilePath)
103set ocidSaveFilePath to doPathEscape(ocidSaveFilePath)
104#コマンド整形
105set strCmd to ("\\\"" & strBinPath & "\\\" -dynamic  -local -showSuccesses -showWarnings \\\"" & ocidFilePath & "\\\"  -report_output \\\"" & ocidSaveFilePath & "\\\"") as text
106log (return & strCmd & return)
107set strExec to ("/bin/zsh -c \"" & strCmd & "\"") as text
108try
109   set strResponse to (do shell script strExec) as text
110on error
111   log "osascript でエラーしました"
112   return false
113end try
114
115
116
117
118return strResponse
119
120
121
122
123
124
125
126
127
128########################
129#パスのエスケープ
130to doPathEscape(strFilePath)
131   set strFilePath to strFilePath as text
132   set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
133   set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
134   set ocidFilePathURL to refMe's NSURL's fileURLWithPath:(ocidFilePath) isDirectory:(false)
135   set listEscChar to {"\\", "\"", "$", "`"} as list
136   repeat with itemEscChar in listEscChar
137      set ocidFilePath to (ocidFilePath's stringByReplacingOccurrencesOfString:(itemEscChar) withString:("\\\\\\" & itemEscChar & ""))
138   end repeat
139   set ocidFilePath to (ocidFilePath's stringByReplacingOccurrencesOfString:("!") withString:("\\\"'!'\\\""))
140   
141   return ocidFilePath
142end doPathEscape
143
144
AppleScriptで生成しました