20260611

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

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

NOTE記事一覧ですnote.com
 

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

fontsetplot-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/fontsetplot" -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/fontsetplot") 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#PT指定36
089set strCmd to ("PATH=\\\"$HOME/Library/Python/3.12/bin:$PATH\\\";\\\"" & strBinFilePath & "\\\" -pt 36 -o \\\"" & strSaveFilePath & "\\\" \\\"" & strFilePath & "\\\"") as text
090#フォント指定無し
091set strCmd to ("PATH=\\\"$HOME/Library/Python/3.12/bin:$PATH\\\";\\\"" & strBinFilePath & "\\\" -o \\\"" & strSaveFilePath & "\\\" \\\"" & strFilePath & "\\\"") as text
092
093
094log (return & strCmd & return)
095#コマンド実行
096set strExecCommand to ("/bin/zsh -c \"" & strCmd & "\"") as text
097try
098   set strResponse to (do shell script strExecCommand) as text
099on error
100   log "osascript でエラーしました"
101   return false
102end try
103
104#################
105#
106set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
107set boolDone to appSharedWorkspace's openURL:(ocidContainerDirPathURL)
108#
109set ocidOpenURLsArray to refMe's NSMutableArray's alloc()'s init()
110(ocidOpenURLsArray's addObject:(ocidSaveFilePathURL))
111appSharedWorkspace's activateFileViewerSelectingURLs:(ocidOpenURLsArray)
112
113
114return "終了"
115
116
117
118
119########################
120#パスのエスケープ
121to doPathEscape(strFilePath)
122   set strFilePath to strFilePath as text
123   set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
124   set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
125   set ocidFilePathURL to refMe's NSURL's fileURLWithPath:(ocidFilePath) isDirectory:(false)
126   set listEscChar to {"\\", "\"", "$", "`"} as list
127   repeat with itemEscChar in listEscChar
128      set ocidFilePath to (ocidFilePath's stringByReplacingOccurrencesOfString:(itemEscChar) withString:("\\\\\\" & itemEscChar & ""))
129   end repeat
130   set ocidFilePath to (ocidFilePath's stringByReplacingOccurrencesOfString:("!") withString:("\\\"'!'\\\""))
131   
132   return ocidFilePath
133end doPathEscape
AppleScriptで生成しました