20260611

【Adobe Font Development Kit for OpenType】tx 全文字PDFダンプ・ヘルパースクリプト

【Adobe Font Development Kit for OpenType】tx 全文字PDFダンプ・ヘルパースクリプト

NOTE記事一覧ですnote.com
 

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

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