20260611

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

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

NOTE記事一覧ですnote.com
 

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

fontplot-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/fontplot" -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 ("pdf") 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/fontplot") 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 fonts 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 ("保存する名前を決めてください" & linefeed & "拡張子は【" & 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#################
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 & "\\\" -pt 36 -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で生成しました