20260318

cpdf 2.9アップデート


cpdf 2.9アップデート

https://www.coherentpdf.com

【スクリプトエディタで開く】 |

[cpdf]バイナリーインストール.scpt
ソース
001#! /usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003(*
004cpdf ARM版
005https://github.com/coherentgraphics/cpdf-binaries
006バイナリーのインストール
007サイズも小さいので、入れ替えインストールします
008(古いバージョンはゴミ箱へ)
009
010インストール先は
011/Users/ユーザーID/Library/Application Support/bin/cpdf
012
013ちょっと変わっていますのでカスタマイズして利用してください
014インストール後にバイナリーを実行してヘルプ表示します
015
016cpdf は署名されていますので安心して利用できます
017
018v1 初回作成
019v1.1 入れ替え処理を入れた
020
021
022com.cocolog-nifty.quicktimer.icefloe *)
023----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
024use AppleScript version "2.8"
025use framework "Foundation"
026use framework "UniformTypeIdentifiers"
027use framework "AppKit"
028use scripting additions
029
030property refMe : a reference to current application
031##############################
032#設定項目
033#ダウンロードURL
034set strURL to ("https://codeload.github.com/coherentgraphics/cpdf-binaries/zip/refs/heads/master") as text
035#インストール先
036set strSaveDir to ("~/Library/Application Support/bin/cpdf") as text
037
038##############################
039#メタ文字
040set strLF to ("" & linefeed & "") as text
041set strCR to ("" & return & "") as text
042set strCRLF to ("" & return & linefeed & "") as text
043set strSpace to ("" & space & "") as text
044set strTab to ("" & tab & "") as text
045
046##############################
047#ダウンロード先(起動時に削除される項目)
048set appFileManager to refMe's NSFileManager's defaultManager()
049set ocidTempDirURL to appFileManager's temporaryDirectory()
050set ocidUUID to refMe's NSUUID's alloc()'s init()
051set ocidUUIDString to ocidUUID's UUIDString
052set ocidDownloadDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:true
053set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
054ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
055set listDone to appFileManager's createDirectoryAtURL:(ocidDownloadDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
056if (second item of listDone) ≠ (missing value) then
057   set strErrorNO to (second item of listDone)'s code() as text
058   set strErrorMes to (second item of listDone)'s localizedDescription() as text
059   refMe's NSLog("■:" & strErrorNO & strErrorMes)
060   return "エラーしました" & strErrorNO & strErrorMes
061end if
062set ocidDownloadFilePathURL to ocidDownloadDirPathURL's URLByAppendingPathComponent:("master.zip") isDirectory:(false)
063set strDownloadFilePath to (ocidDownloadFilePathURL's |path|()) as text
064set strExpandDirPath to (ocidDownloadDirPathURL's |path|()) as text
065
066
067##############################
068#保存先
069set ocidSaveDirPathStr to refMe's NSString's stringWithString:(strSaveDir)
070set ocidSaveDirPath to ocidSaveDirPathStr's stringByStandardizingPath()
071set ocidSaveDirPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidSaveDirPath) isDirectory:false)
072##############################
073#今あるものをゴミ箱へ
074set boolDirExists to appFileManager's fileExistsAtPath:(ocidSaveDirPath) isDirectory:(true)
075if (boolDirExists as boolean) is true then
076   set appFileManager to refMe's NSFileManager's defaultManager()
077   set listDone to (appFileManager's trashItemAtURL:(ocidSaveDirPathURL) resultingItemURL:(ocidDownloadDirPathURL) |error|:(reference))
078   if (second item of listDone) ≠ (missing value) then
079      set strErrorNO to (second item of listDone)'s code() as text
080      set strErrorMes to (second item of listDone)'s localizedDescription() as text
081      refMe's NSLog("■:" & strErrorNO & strErrorMes)
082      return "エラーしました" & strErrorNO & strErrorMes
083   end if
084end if
085
086
087##############################
088#新たにフォルダを作り直す
089ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
090set listDone to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
091if (second item of listDone) ≠ (missing value) then
092   set strErrorNO to (second item of listDone)'s code() as text
093   set strErrorMes to (second item of listDone)'s localizedDescription() as text
094   refMe's NSLog("■:" & strErrorNO & strErrorMes)
095   return "エラーしました" & strErrorNO & strErrorMes
096end if
097
098##############################
099#リダイレクト先
100set strCommandText to ("/usr/bin/curl -s -L -I -o /dev/null -w '%{url_effective}' \"" & strURL & "\"") as text
101try
102   set strRedirectURL to (do shell script strCommandText) as text
103on error
104   return "URLのリダイレクトの取得に失敗しました"
105end try
106
107##############################
108#ダウンロード
109set strCommandText to ("/usr/bin/curl -L -o \"" & strDownloadFilePath & "\" \"" & strRedirectURL & "\" --connect-timeout 20") as text
110try
111   set strResponse to (do shell script strCommandText) as text
112on error
113   return "ダウンロードに失敗しました"
114end try
115
116##############################
117#解凍
118set strCommandText to ("/usr/bin/bsdtar -xzf \"" & strDownloadFilePath & "\" -C \"" & strExpandDirPath & "\"") as text
119try
120   set strResponse to (do shell script strCommandText) as text
121on error
122   return "Zipの解凍に失敗しました"
123end try
124
125##############################
126#移動
127#解凍結果
128set ocidExpandBinFilePathURL to ocidDownloadDirPathURL's URLByAppendingPathComponent:("cpdf-binaries-master/OSX-ARM/cpdf") isDirectory:(false)
129#最終的なバイナリーの移動先
130set ocidDistBinFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:("cpdf") isDirectory:(false)
131#
132set listDone to (appFileManager's moveItemAtURL:(ocidExpandBinFilePathURL) toURL:(ocidDistBinFilePathURL) |error|:(reference))
133if (second item of listDone) ≠ (missing value) then
134   set strErrorNO to (second item of listDone)'s code() as text
135   set strErrorMes to (second item of listDone)'s localizedDescription() as text
136   refMe's NSLog("■:" & strErrorNO & strErrorMes)
137   #####
138   set listDone to (appFileManager's trashItemAtURL:(ocidDistBinFilePathURL) resultingItemURL:(ocidDistBinFilePathURL) |error|:(reference))
139   if (item 1 of listDone) is true then
140      set listDone to (appFileManager's moveItemAtURL:(ocidExpandBinFilePathURL) toURL:(ocidDistBinFilePathURL) |error|:(reference))
141      log "最新版と入れ替えました"
142      if (item 1 of listDone) is false then
143         set strErrorNO to (second item of listDone)'s code() as text
144         set strErrorMes to (second item of listDone)'s localizedDescription() as text
145         refMe's NSLog("■:" & strErrorNO & strErrorMes)
146         return "エラーしました" & strErrorNO & strErrorMes
147      end if
148   else
149      return "移動でエラーしました"
150   end if
151   
152end if
153
154##############################
155#実行チェック
156set strBinPath to (ocidDistBinFilePathURL's |path|()) as text
157tell application "Terminal"
158   launch
159   activate
160   #リターンで改行を送る=新規Window
161   set strCmd to ("" & strLF & strLF & "") as text
162   set objWindowID to (do script strCmd)
163   delay 1
164   #コマンド実行
165   set strCmd to ("\"" & strBinPath & "\"  -help") as text
166   log strCmd
167   do script strCmd in objWindowID
168end tell
169
170
171##############################
172# 保存先を開く
173set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
174set boolDone to appSharedWorkspace's openURL:(ocidSaveDirPathURL)
175
176
177##############################
178#解凍前のファイルをゴミ箱へ
179set appFileManager to refMe's NSFileManager's defaultManager()
180set listDone to (appFileManager's trashItemAtURL:(ocidDownloadDirPathURL) resultingItemURL:(ocidDownloadDirPathURL) |error|:(reference))
181if (second item of listDone) ≠ (missing value) then
182   set strErrorNO to (second item of listDone)'s code() as text
183   set strErrorMes to (second item of listDone)'s localizedDescription() as text
184   refMe's NSLog("■:" & strErrorNO & strErrorMes)
185   return "エラーしました" & strErrorNO & strErrorMes
186end if
187
188
189return true
AppleScriptで生成しました