
【ATS-FontValidator】JSONに出力する
【Safari・FireFox用Script Editorで開く】 |
| ソース | |
|---|---|
| 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 | |
| 011 | Validates font files are adequate to use with the OS. |
| 012 | If 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. |
| 026 | Warning: this may yield similar paths if 2 input directorys contain similar directory structures |
| 027 | |
| 028 | |
| 029 | |
| 030 | com.cocolog-nifty.quicktimer.icefloe *) |
| 031 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7-- |
| 032 | use AppleScript version "2.8" |
| 033 | use framework "Foundation" |
| 034 | use framework "AppKit" |
| 035 | use framework "UniformTypeIdentifiers" |
| 036 | use scripting additions |
| 037 | |
| 038 | property refMe : a reference to current application |
| 039 | |
| 040 | ############################# |
| 041 | # |
| 042 | set strBinPath to ("/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ATS.framework/Versions/A/Support/FontValidator") as text |
| 043 | ############################# |
| 044 | #ダイアログ |
| 045 | set appFileManager to refMe's NSFileManager's defaultManager() |
| 046 | set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask)) |
| 047 | set ocidDesktopDirPathURL to ocidURLsArray's firstObject() |
| 048 | set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias |
| 049 | # |
| 050 | set listUTI to {"public.font"} as list |
| 051 | set strMes to ("フォントを選択してください") as text |
| 052 | set strPrompt to ("フォントを選択してください") as text |
| 053 | try |
| 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 |
| 058 | on error strErrMes number numErrNo |
| 059 | log strErrMes & numErrNo |
| 060 | return false |
| 061 | end try |
| 062 | |
| 063 | # |
| 064 | set strFilePath to (POSIX path of aliasFilePath) as text |
| 065 | set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath)) |
| 066 | set ocidFilePath to ocidFilePathStr's stringByStandardizingPath() |
| 067 | set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:(false)) |
| 068 | # |
| 069 | set ocidFileName to ocidFilePathURL's lastPathComponent() |
| 070 | set ocidFileName to ocidFileName's decomposedStringWithCanonicalMapping() |
| 071 | set ocidBaseFileName to ocidFileName's stringByDeletingPathExtension() |
| 072 | |
| 073 | ############################# |
| 074 | # |
| 075 | set strFileExtension to ("json") as text |
| 076 | set strSaveFileName to (ocidBaseFileName's stringByAppendingPathExtension:(strFileExtension)) as text |
| 077 | # |
| 078 | set strMsg to ("保存先を指定してください") as text |
| 079 | set strPrompt to ("保存先を指定してください") as text |
| 080 | try |
| 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 |
| 085 | on error strErrMes number numErrNo |
| 086 | return strErrMes & numErrNo |
| 087 | end try |
| 088 | set strSaveFilePath to (POSIX path of aliasSaveFilePath) as text |
| 089 | set ocidSaveFilePath to refMe's NSString's stringWithString:(strSaveFilePath) |
| 090 | set ocidSaveFilePathURL to refMe's NSURL's fileURLWithPath:(ocidSaveFilePath) |
| 091 | set strFileExtensionName to ocidSaveFilePathURL's pathExtension() as text |
| 092 | #ダイアログで拡張子を取っちゃった時対策 |
| 093 | if strFileExtensionName is not strFileExtension then |
| 094 | set ocidSaveFilePathURL to ocidSaveFilePathURL's URLByAppendingPathExtension:(strFileExtension) |
| 095 | end if |
| 096 | set ocidSaveFilePath to ocidSaveFilePathURL's |path|() |
| 097 | |
| 098 | |
| 099 | ############################# |
| 100 | #エスケープ |
| 101 | set strBinPath to doPathEscape(strBinPath) |
| 102 | set ocidFilePath to doPathEscape(ocidFilePath) |
| 103 | set ocidSaveFilePath to doPathEscape(ocidSaveFilePath) |
| 104 | #コマンド整形 |
| 105 | set strCmd to ("\\\"" & strBinPath & "\\\" -dynamic -local -showSuccesses -showWarnings \\\"" & ocidFilePath & "\\\" -report_output \\\"" & ocidSaveFilePath & "\\\"") as text |
| 106 | log (return & strCmd & return) |
| 107 | set strExec to ("/bin/zsh -c \"" & strCmd & "\"") as text |
| 108 | try |
| 109 | set strResponse to (do shell script strExec) as text |
| 110 | on error |
| 111 | log "osascript でエラーしました" |
| 112 | return false |
| 113 | end try |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | return strResponse |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | ######################## |
| 129 | #パスのエスケープ |
| 130 | to 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 |
| 142 | end doPathEscape |
| 143 | |
| 144 | |
| AppleScriptで生成しました | |
