20260611

【Adobe Font Development Kit for OpenType】tx テキストダンプ・ヘルパースクリプト

【Adobe Font Development Kit for OpenType】tx テキストダンプ・ヘルパースクリプト

NOTE記事一覧ですnote.com
 

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

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