
【Adobe Font Development Kit for OpenType】tx テキストダンプ・ヘルパースクリプト
【Safari・FireFox用Script Editorで開く】 |
| ソース | |
|---|---|
| 001 | #!/usr/bin/env osascript |
| 002 | #coding: utf-8 |
| 003 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
| 004 | (* |
| 005 | AFDKO を先にインストール済みの必要があります |
| 006 | https://note.com/quicktimer/n/nef5d603f562c |
| 007 | |
| 008 | ヘルプ |
| 009 | "${HOME}/Library/Python/3.12/bin/tx" -h |
| 010 | -->proofpdf |
| 011 | https://adobe-type-tools.github.io/afdko/AFDKO-Overview.html#22-proofing |
| 012 | |
| 013 | com.cocolog-nifty.quicktimer.icefloe *) |
| 014 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
| 015 | use AppleScript version "2.8" |
| 016 | use framework "Foundation" |
| 017 | use framework "AppKit" |
| 018 | use framework "UniformTypeIdentifiers" |
| 019 | use scripting additions |
| 020 | property refMe : a reference to current application |
| 021 | |
| 022 | ################# |
| 023 | ##設定項目 |
| 024 | set strSaveExtension to ("txt") as text |
| 025 | |
| 026 | ################# |
| 027 | ##バイナリーへのパス |
| 028 | set appFileManager to refMe's NSFileManager's defaultManager() |
| 029 | set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSUserDomainMask)) |
| 030 | set ocidLibraryDirPathURL to ocidURLsArray's firstObject() |
| 031 | set ocidBinFilePathURL to ocidLibraryDirPathURL's URLByAppendingPathComponent:("Python/3.12/bin/tx") isDirectory:(false) |
| 032 | set strBinFilePath to ocidBinFilePathURL's |path|() as text |
| 033 | |
| 034 | ################# |
| 035 | ## ダイアログ関連 |
| 036 | set strName to (name of current application) as text |
| 037 | if strName is "osascript" then |
| 038 | tell application "Finder" to activate |
| 039 | else |
| 040 | tell current application to activate |
| 041 | end if |
| 042 | |
| 043 | tell application "Finder" |
| 044 | set aliasDefaultLocation to (path to desktop folder from user domain) as alias |
| 045 | end tell |
| 046 | set listUTI to {"public.truetype-ttf-font", "public.opentype-font"} as list |
| 047 | set strPromptText to "フォントファイルを選んでください" as text |
| 048 | set strMes to "選んでください" as text |
| 049 | set aliasFilePath to (choose file strMes with prompt strPromptText default location (aliasDefaultLocation) of type listUTI without invisibles, multiple selections allowed and showing package contents) as alias |
| 050 | |
| 051 | ####ファイルパス |
| 052 | set strFilePath to (POSIX path of aliasFilePath) as text |
| 053 | set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath) |
| 054 | set ocidFilePath to ocidFilePathStr's stringByStandardizingPath() |
| 055 | set ocidFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:(false) |
| 056 | set ocidContainerDirPathURL to ocidFilePathURL's URLByDeletingLastPathComponent() |
| 057 | set aliasContainerDirPath to (ocidContainerDirPathURL's absoluteURL()) as alias |
| 058 | # |
| 059 | set ocidBaseFilePathURL to ocidFilePathURL's URLByDeletingPathExtension() |
| 060 | set ocidSaveFilePathURL to ocidBaseFilePathURL's URLByAppendingPathExtension:(strSaveExtension) |
| 061 | set strBaseFileName to ocidSaveFilePathURL's lastPathComponent() as text |
| 062 | |
| 063 | ################# |
| 064 | ##保存先 ダイアログ関連 |
| 065 | set strPromptText to ("保存する名前を決めてください\n拡張子は【" & strSaveExtension & "】です") as text |
| 066 | set strMes to "名前を決めてください" as text |
| 067 | set aliasSaveFilePath to (choose file name default location aliasContainerDirPath default name strBaseFileName with prompt strPromptText) as «class furl» |
| 068 | ####ファイルパス |
| 069 | set strSaveFilePath to (POSIX path of aliasSaveFilePath) as text |
| 070 | set ocidSaveFilePathStr to refMe's NSString's stringWithString:(strSaveFilePath) |
| 071 | set ocidSaveFilePath to ocidSaveFilePathStr's stringByStandardizingPath() |
| 072 | set ocidSaveFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(ocidSaveFilePath) isDirectory:(false) |
| 073 | set ocidSaveContainerDirPathURL to ocidSaveFilePathURL's URLByDeletingLastPathComponent() |
| 074 | set ocidSaveBaseFilePathURL to ocidSaveFilePathURL's URLByDeletingPathExtension() |
| 075 | set strSaveFileExtension to ocidSaveFilePathURL's pathExtension() as text |
| 076 | if strSaveFileExtension is not strSaveExtension then |
| 077 | set ocidSaveFilePathURL to ocidSaveBaseFilePathURL's URLByAppendingPathExtension:(strSaveExtension) |
| 078 | end if |
| 079 | # |
| 080 | set strSaveFilePath to ocidSaveFilePathURL's |path|() as text |
| 081 | |
| 082 | ################# |
| 083 | #コマンド整形 |
| 084 | set strBinFilePath to doPathEscape(strBinFilePath) |
| 085 | set strFilePath to doPathEscape(strFilePath) |
| 086 | #リストのみ |
| 087 | set strCommandText to ("PATH=\\\"$HOME/Library/Python/3.12/bin:$PATH\\\";\\\"" & strBinFilePath & "\\\" -dump -0 -y \\\"" & strFilePath & "\\\" | grep nGlyphs") as text |
| 088 | ## |
| 089 | log (return & strCommandText & return) |
| 090 | #コマンド実行 |
| 091 | set strExecCommand to ("/bin/zsh -c \"" & strCommandText & "\" | awk '{print $2}'") as text |
| 092 | try |
| 093 | set strCntGlyphs to (do shell script strExecCommand) as text |
| 094 | on error |
| 095 | log "osascript でエラーしました" |
| 096 | return false |
| 097 | end try |
| 098 | |
| 099 | ################# |
| 100 | #コマンド整形 |
| 101 | |
| 102 | set strSaveFilePath to doPathEscape(strSaveFilePath) |
| 103 | |
| 104 | #リストのみ |
| 105 | set strCommandText to ("PATH=\\\"$HOME/Library/Python/3.12/bin:$PATH\\\";\\\"" & strBinFilePath & "\\\" -dump -1 -d -n -y \\\"" & strFilePath & "\\\" \\\"" & strSaveFilePath & "\\\"") as text |
| 106 | ## |
| 107 | log (return & strCommandText & return) |
| 108 | #コマンド実行 |
| 109 | set strExecCommand to ("/bin/zsh -c \"" & strCommandText & "\"") as text |
| 110 | try |
| 111 | set strResponse to (do shell script strExecCommand) as text |
| 112 | on error |
| 113 | log "osascript でエラーしました" |
| 114 | return false |
| 115 | end try |
| 116 | |
| 117 | ################# |
| 118 | # |
| 119 | set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace() |
| 120 | set boolDone to appSharedWorkspace's openURL:(ocidContainerDirPathURL) |
| 121 | # |
| 122 | set ocidOpenURLsArray to refMe's NSMutableArray's alloc()'s init() |
| 123 | (ocidOpenURLsArray's addObject:(ocidSaveFilePathURL)) |
| 124 | appSharedWorkspace's activateFileViewerSelectingURLs:(ocidOpenURLsArray) |
| 125 | |
| 126 | |
| 127 | return "終了" |
| 128 | |
| 129 | |
| 130 | |
| 131 | ######################## |
| 132 | #パスのエスケープ |
| 133 | to doPathEscape(strFilePath) |
| 134 | set strFilePath to strFilePath as text |
| 135 | set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath) |
| 136 | set ocidFilePath to ocidFilePathStr's stringByStandardizingPath() |
| 137 | set ocidFilePathURL to refMe's NSURL's fileURLWithPath:(ocidFilePath) isDirectory:(false) |
| 138 | set listEscChar to {"\\", "\"", "$", "`"} as list |
| 139 | repeat with itemEscChar in listEscChar |
| 140 | set ocidFilePath to (ocidFilePath's stringByReplacingOccurrencesOfString:(itemEscChar) withString:("\\\\\\" & itemEscChar & "")) |
| 141 | end repeat |
| 142 | set ocidFilePath to (ocidFilePath's stringByReplacingOccurrencesOfString:("!") withString:("\\\"'!'\\\"")) |
| 143 | |
| 144 | return ocidFilePath |
| 145 | end doPathEscape |
| AppleScriptで生成しました | |
