Admin Printer

ページを開けません エラー: HTTPS-Only”が有効になっているHTTP URLに対するリクエストだったため、ナビゲーションできませんでした”(WebKitErrorDomain:305)



ダウンロード - usehttpsonly.zip




202505290948231_1864x8502
CUPSのWEBインターフェイスを利用する場合や
ローカルのフォントを認識させる必要がある場合は
『ローカルファイルの制限を無効にする』をONにする必要がある場合もあります
202506010627241_1744x812
設定変更はターミナルでもOKです

CUPSのWEBUIを利用できるように
CUPSの設定の変更と
safariのセキュリティ設定を変更します


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

CUPSWEBUI設定とSafariの設定.scpt
ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003(*
004
005【重要】Safariの設定を変更します
006Safariを終了させてから実行してください
007
008CUPSWEBUIを利用できるように
009CUPSの設定の変更と
010safariのセキュリティ設定を変更します
011
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 scripting additions
019property refMe : a reference to current application
020
021
022########################
023#サンドボックス内
024set strFilePath to ("~/Library/Containers/com.apple.Safari/Data/Library/Preferences/com.apple.Safari.plist")
025set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
026set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
027set ocidFilePathURL to refMe's NSURL's fileURLWithPath:(ocidFilePath) isDirectory:(false)
028
029#Plistを開く
030set listResponse to refMe's NSMutableDictionary's alloc()'s initWithContentsOfURL:(ocidFilePathURL) |error|:(reference)
031if (item 2 of listResponse) = (missing value) then
032   set ocidPlistDict to (item 1 of listResponse)
033else if (item 2 of listResponse) ≠ (missing value) then
034   set strErrorNO to (item 2 of listResponse)'s code() as text
035   set strErrorMes to (item 2 of listResponse)'s localizedDescription() as text
036   refMe's NSLog("■" & strErrorNO & strErrorMes)
037   return "エラーしました" & strErrorNO & strErrorMes
038end if
039
040#値変更
041ocidPlistDict's setValue:(false as boolean) forKey:("UseHTTPSOnly")
042
043#保存
044set listDone to ocidPlistDict's writeToURL:(ocidFilePathURL) |error|:(reference)
045if (item 1 of listDone) is true then
046   log "writeToURL 正常処理"
047else if (item 2 of listDone) ≠ (missing value) then
048   set strErrorNO to (item 2 of listDone)'s code() as text
049   set strErrorMes to (item 2 of listDone)'s localizedDescription() as text
050   refMe's NSLog("■" & strErrorNO & strErrorMes)
051   return "writeToURL エラーしました" & strErrorNO & strErrorMes
052end if
053
054
055set ocidPlistDict to (missing value)
056
057########################
058#通常設定内も変更しておく
059set strFilePath to ("~/Library/Preferences/com.apple.Safari.plist")
060set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
061set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
062set ocidFilePathURL to refMe's NSURL's fileURLWithPath:(ocidFilePath) isDirectory:(false)
063
064#Plistを開く
065set listResponse to refMe's NSMutableDictionary's alloc()'s initWithContentsOfURL:(ocidFilePathURL) |error|:(reference)
066if (item 2 of listResponse) = (missing value) then
067   set ocidPlistDict to (item 1 of listResponse)
068else if (item 2 of listResponse) ≠ (missing value) then
069   set strErrorNO to (item 2 of listResponse)'s code() as text
070   set strErrorMes to (item 2 of listResponse)'s localizedDescription() as text
071   refMe's NSLog("■" & strErrorNO & strErrorMes)
072   return "エラーしました" & strErrorNO & strErrorMes
073end if
074
075#値変更
076ocidPlistDict's setValue:(false as boolean) forKey:("UseHTTPSOnly")
077
078#保存
079set listDone to ocidPlistDict's writeToURL:(ocidFilePathURL) |error|:(reference)
080if (item 1 of listDone) is true then
081   log "writeToURL 正常処理"
082else if (item 2 of listDone) ≠ (missing value) then
083   set strErrorNO to (item 2 of listDone)'s code() as text
084   set strErrorMes to (item 2 of listDone)'s localizedDescription() as text
085   refMe's NSLog("■" & strErrorNO & strErrorMes)
086   return "writeToURL エラーしました" & strErrorNO & strErrorMes
087end if
088
089########################
090#CUPS WEBUIを利用可能に
091try
092   set strComandText to ("/usr/sbin/cupsctl  WebInterface=YES") as text
093   log doZshShellScript(strComandText)
094end try
095
096
097
098##########################
099# ZSH】通常・実行
100to doZshShellScript(argCommandText)
101   #Asのテキストとして
102   set strCommandText to argCommandText as text
103   #NSstringにしてシングルクオトをエスケープ
104   set ocidCommandString to current application's NSMutableString's stringWithString:(strCommandText)
105   set ocidCommandString to (ocidCommandString's stringByReplacingOccurrencesOfString:("'") withString:("\\'"))
106   set strCommandText to ocidCommandString as text
107   log "\r" & strCommandText & "\r"
108   set strExec to ("/bin/zsh -c '" & strCommandText & "'") as text
109   log "\r" & strExec & "\r"
110   ##########
111   #コマンド実行
112   try
113      log "コマンド開始"
114      set strResnponse to (do shell script strExec) as text
115      log "コマンド終了"
116   on error strErroMsg number numErrorNo
117      return {false, strErroMsg, numErrorNo}
118   end try
119   return strResnponse
120end doZshShellScript
121
AppleScriptで生成しました

UseHTTPSOnly.bash

サンプルコード

サンプルソース(参考)
行番号ソース
001#!/bin/bash
002#com.cocolog-nifty.quicktimer.icefloe
003#set -x
004#export PATH=/usr/bin:/bin:/usr/sbin:/sbin
005
006#################################################
007#通常設定ファイル
008#通常のOS設定ならこの方法でサンドボックス環境の設定が変更になります
009
010/usr/bin/defaults read com.apple.Safari UseHTTPSOnly
011
012#この結果が 1 = TRUE = YES の場合は 0にします
013/usr/bin/defaults write com.apple.Safari UseHTTPSOnly -bool false
014
015/usr/bin/defaults read com.apple.Safari UseHTTPSOnly
016#-->この戻り値が0になればOK!
017
018#元に戻るHTTP通信遮断(推奨)の場合は
019/usr/bin/defaults write com.apple.Safari UseHTTPSOnly -bool true
020
021
022#################################################
023#サンドボックス環境の設定ファイル
024
025/usr/bin/defaults read ~/Library/Containers/com.apple.Safari/Data/Library/Preferences/com.apple.Safari.plist UseHTTPSOnly
026
027#この結果が 1 = TRUE = YES の場合は 0にします
028/usr/bin/defaults write ~/Library/Containers/com.apple.Safari/Data/Library/Preferences/com.apple.Safari.plist UseHTTPSOnly -bool false
029
030/usr/bin/defaults read ~/Library/Containers/com.apple.Safari/Data/Library/Preferences/com.apple.Safari.plist UseHTTPSOnly
031#-->この戻り値が0になればOK!
032
033#元に戻るHTTP通信遮断(推奨)の場合は
034/usr/bin/defaults write ~/Library/Containers/com.apple.Safari/Data/Library/Preferences/com.apple.Safari.plist UseHTTPSOnly -bool true
035
036#################################################
037#旧環境用の設定ファイル
038
039/usr/bin/defaults read ~/Library/Preferences/com.apple.Safari.plist UseHTTPSOnly
040
041#この結果が 1 = TRUE = YES の場合は 0にします
042/usr/bin/defaults write ~/Library/Preferences/com.apple.Safari.plist UseHTTPSOnly -bool false
043
044/usr/bin/defaults read ~/Library/Preferences/com.apple.Safari.plist UseHTTPSOnly
045#-->この戻り値が0になればOK!
046
047#元に戻るHTTP通信遮断(推奨)の場合は
048/usr/bin/defaults write ~/Library/Preferences/com.apple.Safari.plist UseHTTPSOnly -bool true
049
050
051exit 0
AppleScriptで生成しました

com.apple.Safari.UseHTTPSOnly.false.mobileconfig

サンプルコード

サンプルソース(参考)
行番号ソース
001<dict>
002<key>UseHTTPSOnly</key>
003<false/>
004<key>PayloadDisplayName</key>
005<string>Safari</string>
006<key>PayloadDescription</key>
007<string>UseHTTPSOnlyの値をFALSEにします
008http: で始まるURLにアクセス出来るようにします</string>
009<key>PayloadIdentifier</key>
010<string>com.apple.Safari.679569FD-C329-48A4-8848-97CDCCC6F6B0</string>
011<key>PayloadType</key>
012<string>com.apple.Safari</string>
013<key>PayloadUUID</key>
014<string>679569FD-C329-48A4-8848-97CDCCC6F6B0</string>
015<key>PayloadVersion</key>
016<integer>1</integer>
017</dict>
AppleScriptで生成しました

com.apple.Safari.UseHTTPSOnly.true.mobileconfig

サンプルコード

サンプルソース(参考)
行番号ソース
001<dict>
002<key>UseHTTPSOnly</key>
003<true/>
004<key>PayloadDisplayName</key>
005<string>Safari</string>
006<key>PayloadDescription</key>
007<string>UseHTTPSOnlyの値をTRUEにします
008http: で始まるURLにアクセス出来なくなる場合があります</string>
009<key>PayloadIdentifier</key>
010<string>com.apple.Safari.679569FD-C329-48A4-8848-97CDCCC6F6B0</string>
011<key>PayloadType</key>
012<string>com.apple.Safari</string>
013<key>PayloadUUID</key>
014<string>679569FD-C329-48A4-8848-97CDCCC6F6B0</string>
015<key>PayloadVersion</key>
016<integer>1</integer>
017</dict>
AppleScriptで生成しました

| | コメント (0)

PostScriptファイル書き出し用のPSプリンタ登録(v6 エラー制御を見直してmacOS15.4に対応した)

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

001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003(*
00420241118 macOS15でエラーになりにくいように少し手直し
00520250406 macOS15.4でエラーになるのに対応した
006
007【注意】CUPSプリンタシステムを初期化します
008プリンタをカスタマイズしている方は実行しないでください
009
010AcrobatPPDGitからダウンロードするように変更しました
011
012余白0のAcraobatプリンタとDS TRUEFLOW_Jプリンタ(PS書き出し用)を
013プリンタに登録します
014いわゆるバーチャルプリンタです。
015
016com.cocolog-nifty.quicktimer.icefloe *)
017----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
018use AppleScript version "2.8"
019use framework "Foundation"
020use framework "AppKit"
021use framework "PrintKit"
022use framework "UniformTypeIdentifiers"
023use scripting additions
024
025property refMe : a reference to current application
026
027set appFileManager to refMe's NSFileManager's defaultManager()
028
029#############################
030#   共有ディレクトリのPPDを廃止
031#   makequeuesでエラーになるため
032#############################
033#廃止予定ディレクトリパス
034set strTmpDirPath to "/Users/Shared/Library/Printers" as text
035set ocidTmpDirPathStr to refMe's NSString's stringWithString:(strTmpDirPath)
036set ocidTmpDirPath to ocidTmpDirPathStr's stringByStandardizingPath()
037set ocidTmpDirPathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(ocidTmpDirPath) isDirectory:(true)
038#フォルダ生成
039set appFileManager to refMe's NSFileManager's defaultManager()
040set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
041ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
042set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidTmpDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
043#注意喚起テキスト生成
044set strTmpFileName to ("このディレクトリは廃止になります.txt") as text
045set strTmpFilePathURL to ocidTmpDirPathURL's URLByAppendingPathComponent:(strTmpFileName) isDirectory:(false)
046set ocidTmpContentsString to refMe's NSString's stringWithString:("このディレクトリは廃止になります\n任意で削除してください")
047set listDone to ocidTmpContentsString's writeToURL:(strTmpFilePathURL) atomically:(true) encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)
048
049#############################
050###AcrobatPPDの有無を確認
051#############################
052#ユーザードメインのPPD保存先
053set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSUserDomainMask))
054set ocidLibraryDirPathURL to ocidURLsArray's firstObject()
055set ocidExtractDirPathURL to ocidLibraryDirPathURL's URLByAppendingPathComponent:("Printers/PPDs/Contents/Resources") isDirectory:(true)
056#
057ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
058set listDone to appFileManager's createDirectoryAtURL:(ocidExtractDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
059#
060set ocidSavePPDDirPathURL to ocidLibraryDirPathURL's URLByAppendingPathComponent:"Printers/PPDs/Contents/Resources/Acrobat" isDirectory:(true)
061set ocidPPDFilePathURL to ocidSavePPDDirPathURL's URLByAppendingPathComponent:"ADPDF9J.PPD" isDirectory:(false)
062############
063set boolFileExists to (appFileManager's fileExistsAtPath:(ocidPPDFilePathURL's |path|()) isDirectory:false)
064
065if boolFileExists is true then
066   log "PPDはインストール済み"
067else if boolFileExists is false then
068   ############ない場合はダウンロード
069   #AcrobatPPDTRUEFLOW_Jのみ
070   #set strZipFileURL to "https://force4u.cocolog-nifty.com/skywalker/files/acrobatppds.zip"
071   #Generic.ppd入り
072   #set strZipFileURL to "https://quicktimer.cocolog-nifty.com/icefloe/files/acrobatppds.zip"
073   #↑GITHUB
074   set strZipFileURL to "https://github.com/force4u/AppleScript/raw/refs/heads/main/Script%20Menu/Printers/Admin/VirtualPrinter/acrobatppds.zip"
075   set ocidZipFilePath to (refMe's NSString's stringWithString:strZipFileURL)
076   set ocidZipFilePathURL to refMe's NSURL's alloc()'s initWithString:ocidZipFilePath
077   set ocidOption to (refMe's NSDataReadingMappedIfSafe)
078   set listResponse to refMe's NSData's dataWithContentsOfURL:(ocidZipFilePathURL) options:(ocidOption) |error|:(reference)
079   if (item 2 of listResponse) = (missing value) then
080      log "NSData 正常処理"
081      set ocidZipData to (item 1 of listResponse)
082   else if (item 2 of listResponse) ≠ (missing value) then
083      set strErrorNO to (item 2 of listResponse)'s code() as text
084      set strErrorMes to (item 2 of listResponse)'s localizedDescription() as text
085      refMe's NSLog("■" & strErrorNO & strErrorMes)
086      return "エラーしました" & strErrorNO & strErrorMes
087   end if
088   #保存
089   set ocidTempDirURL to appFileManager's temporaryDirectory()
090   set ocidUUID to refMe's NSUUID's alloc()'s init()
091   set ocidUUIDString to ocidUUID's UUIDString
092   set ocidSaveZipDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:true
093   #
094   ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
095   set listDone to appFileManager's createDirectoryAtURL:(ocidSaveZipDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
096   #パス
097   set ocidSaveZipFilePathURL to ocidSaveZipDirPathURL's URLByAppendingPathComponent:"acrobatppds.zip" isDirectory:false
098   set ocidOption to (refMe's NSDataWritingAtomic)
099   set listDone to ocidZipData's writeToURL:(ocidSaveZipFilePathURL) options:(ocidOption) |error|:(reference)
100   if (item 1 of listDone) is true then
101      log "正常処理"
102   else if (item 2 of listDone) ≠ (missing value) then
103      set strErrorNO to (item 2 of listDone)'s code() as text
104      set strErrorMes to (item 2 of listDone)'s localizedDescription() as text
105      refMe's NSLog("■" & strErrorNO & strErrorMes)
106      return "エラーしました" & strErrorNO & strErrorMes
107   end if
108   
109   ########################
110   #### 解凍
111   ########################
112   set strZipFilePathURL to (ocidSaveZipFilePathURL's |path|()) as text
113   set strSaveDirPathURL to (ocidExtractDirPathURL's |path|()) as text
114   
115   ################
116   #コマンド実行
117   set strCommandText to ("/usr/bin/ditto -xk  \"" & strZipFilePathURL & "\"   \"" & strSaveDirPathURL & "\"") as text
118   set refResponse to doZshShellScript(strCommandText)
119   if refResponse is false then
120      return "ditto でエラーしました"
121   end if
122   
123end if
124
125#############################
126###Acrobatプリンタの有無を確認
127#############################
128
129set strQueName to ("PsPrinterAcrobat9J") as text
130set strModelName to ("PostScript書出用設定") as text
131set strDescriptionName to ("Adobe PDF J 3018.101") as text
132set ocidPPDFilePathURL to ocidSavePPDDirPathURL's URLByAppendingPathComponent:("ADPDF9J.PPD") isDirectory:(false)
133set strPPDFilePath to (ocidPPDFilePathURL's |path|()) as text
134
135################
136##リセット=削除
137set strCommandText to ("/usr/sbin/lpadmin -x \"" & strQueName & "\"") as text
138set refResponse to doZshShellScript(strCommandText)
139
140################
141#プリンタ登録
142set strCommandText to ("/usr/sbin/lpadmin -p \"" & strQueName & "\" -E -v \"lpd://localhost/\" -P \"" & strPPDFilePath & "\" -D \"" & strQueName & "\" -L \"" & strModelName & "\" -o printer-is-shared=false") as text
143set refResponse to doZshShellScript(strCommandText)
144if refResponse is false then
145   return "lpadmin プリンタ登録でエラーしました"
146end if
147
148################
149#プリンタ登録
150set strCommandText to ("/usr/sbin/cupsdisable  \"" & strQueName & "\"") as text
151set refResponse to doZshShellScript(strCommandText)
152if refResponse is false then
153   return "cupsdisable でエラーしました"
154end if
155
156#############################
157###PsPrinteTRUEFLOW_Jプリンタ
158#############################
159
160set strQueName to ("PsPrinteTRUEFLOW_J") as text
161set strModelName to ("PostScript書出用設定") as text
162set strDescriptionName to ("DS TRUEFLOW_J V1.4") as text
163set ocidPPDFilePathURL to ocidSavePPDDirPathURL's URLByAppendingPathComponent:("DS TRUEFLOW_J V1.4") isDirectory:(false)
164set strPPDFilePath to (ocidPPDFilePathURL's |path|()) as text
165
166################
167#リセット=削除
168set strCommandText to ("/usr/sbin/lpadmin -x \"" & strQueName & "\"") as text
169set refResponse to doZshShellScript(strCommandText)
170
171################
172#プリンタ登録
173set strCommandText to ("/usr/sbin/lpadmin -p \"" & strQueName & "\" -E -v \"lpd://localhost/\" -P \"" & strPPDFilePath & "\" -D \"" & strQueName & "\" -L \"" & strModelName & "\" -o printer-is-shared=false") as text
174set refResponse to doZshShellScript(strCommandText)
175if refResponse is false then
176   return "lpadmin プリンタ登録でエラーしました"
177end if
178
179################
180#停止させる
181set strCommandText to ("/usr/sbin/cupsdisable  \"" & strQueName & "\"") as text
182set refResponse to doZshShellScript(strCommandText)
183if refResponse is false then
184   return "cupsdisable でエラーしました"
185end if
186
187#############################
188###A:PsPrintersプリンタ削除
189#############################
190set strCommandText to ("/usr/sbin/lpadmin -x \"A:PsPrinters\"") as text
191set refResponse to doZshShellScript(strCommandText)
192if refResponse is false then
193   return "lpadmin プリンタ削除 でエラーしました"
194end if
195
196
197#############################
198###プリンタプールに追加
199#############################
200set strCommandText to ("/usr/sbin/lpadmin -p \"PsPrinterAcrobat9J\" -c \"A:PsPrinters\"") as text
201set refResponse to doZshShellScript(strCommandText)
202if refResponse is false then
203   return "lpadmin プリンタプールに追加 でエラーしました"
204end if
205
206set strCommandText to ("/usr/sbin/lpadmin -p \"PsPrinteTRUEFLOW_J\" -c \"A:PsPrinters\"") as text
207set refResponse to doZshShellScript(strCommandText)
208if refResponse is false then
209   return "lpadmin プリンタプールに追加 でエラーしました"
210end if
211
212
213#############################
214###プリンタプールの作成
215#############################
216set strCommandText to ("/usr/sbin/lpadmin  -p \"A:PsPrinters\" -L \"Psプリンタのプール(class\"") as text
217set refResponse to doZshShellScript(strCommandText)
218set strCommandText to ("/usr/sbin/lpadmin  -p \"A:PsPrinters\" -o printer-is-shared=false") as text
219set refResponse to doZshShellScript(strCommandText)
220set strCommandText to ("/usr/sbin/lpadmin  -p \"A:PsPrinters\" -u allow:all") as text
221set refResponse to doZshShellScript(strCommandText)
222set strCommandText to ("/usr/sbin/lpadmin  -p \"A:PsPrinters\" -E") as text
223set refResponse to doZshShellScript(strCommandText)
224set strCommandText to ("/usr/sbin/cupsdisable \"A:PsPrinters\"") as text
225set refResponse to doZshShellScript(strCommandText)
226
227
228#############################
229###デフォルトプリンタを指定する
230#############################
231set strCommandText to ("/usr/sbin/lpadmin  -d \"PsPrinterAcrobat9J\"") as text
232set refResponse to doZshShellScript(strCommandText)
233
234
235#############################
236### 初期設定 PLIST 書き換え
237#############################
238set ocidFalse to (refMe's NSNumber's numberWithBool:false)
239####設定ファイルのパス
240set ocidLibrariesPathURLArray to (appFileManager's URLsForDirectory:(refMe's NSAllLibrariesDirectory) inDomains:(refMe's NSUserDomainMask))
241set ocidLibrariesPathURL to item 1 of ocidLibrariesPathURLArray
242set ocidFilePathURL to ocidLibrariesPathURL's URLByAppendingPathComponent:"Preferences/org.cups.PrintingPrefs.plist" isDirectory:false
243#####PLISTの内容を読み込んで
244set ocidPlistDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
245set listReadPlistData to refMe's NSMutableDictionary's dictionaryWithContentsOfURL:ocidFilePathURL |error|:(reference)
246
247set ocidPlistDict to item 1 of listReadPlistData
248ocidPlistDict's setObject:ocidFalse forKey:("UseLastPrinter")
249set ocidLastUsedPrinter to ocidPlistDict's objectForKey:("LastUsedPrinters")
250
251if ocidLastUsedPrinter is not (missing value) then
252   ocidLastUsedPrinter's removeObjectAtIndex:0
253   set recordItemDict to {Network:"192.168.0.1", PrinterID:"PsPrinterAcrobat9J"} as record
254   ocidLastUsedPrinter's addObject:(recordItemDict)
255   ###書き込み用にバイナリーデータに変換
256   set ocidNSbplist to refMe's NSPropertyListBinaryFormat_v1_0
257   set ocidPlistEditDataArray to refMe's NSPropertyListSerialization's dataWithPropertyList:ocidPlistDict format:(ocidNSbplist) options:0 |error|:(reference)
258   set ocidPlistEditData to item 1 of ocidPlistEditDataArray
259   set boolWritetoUrlArray to ocidPlistEditData's writeToURL:(ocidFilePathURL) options:0 |error|:(reference)
260end if
261#############################
262#cupsctl プリンタ共有停止
263set strCommandText to ("/usr/sbin/cupsctl  --no-share-printers") as text
264set refResponse to doZshShellScript(strCommandText)
265
266
267#############################
268#CUPS WEBインターフェイスを有効化
269set strCommandText to ("/usr/sbin/cupsctl  WebInterface=YES") as text
270set refResponse to doZshShellScript(strCommandText)
271
272#############################
273#makequeues USB リバインド
274set strCommandText to ("/System/Library/SystemConfiguration/PrinterNotifications.bundle/Contents/MacOS/makequeues -r") as text
275set refResponse to doZshShellScript(strCommandText)
276
277#makequeues PPD リバインド
278set strCommandText to ("/System/Library/SystemConfiguration/PrinterNotifications.bundle/Contents/MacOS/makequeues -h") as text
279set refResponse to doZshShellScript(strCommandText)
280
281#makequeues LPD リバインド
282set strCommandText to ("/System/Library/SystemConfiguration/PrinterNotifications.bundle/Contents/MacOS/makequeues -k lpd") as text
283set refResponse to doZshShellScript(strCommandText)
284
285#makequeues IPP リバインド
286set strCommandText to ("/System/Library/SystemConfiguration/PrinterNotifications.bundle/Contents/MacOS/makequeues -k ipp") as text
287set refResponse to doZshShellScript(strCommandText)
288
289#makequeues IPP リバインド
290set strCommandText to ("\"/System/Library/Image Capture/Tools/use_updated_image_capture_software\"") as text
291set refResponse to doZshShellScript(strCommandText)
292
293#############################
294#CFPreferencesを再起動
295set strCommandText to ("/usr/bin/killall -HUP cfprefsd") as text
296set refResponse to doZshShellScript(strCommandText)
297
298#############################
299#CUPSプロセスを再起動
300set strCommandText to ("/usr/bin/killall -HUP com.apple.PrintKit.PrinterTool") as text
301set refResponse to doZshShellScript(strCommandText)
302
303####
304set strCommandText to ("/usr/bin/killall -HUP PrintUITool") as text
305set refResponse to doZshShellScript(strCommandText)
306
307####
308set strCommandText to ("/usr/bin/killall -HUP printtool") as text
309set refResponse to doZshShellScript(strCommandText)
310
311
312#############################
313#プリンタパネルを開く
314tell application id "com.apple.systempreferences" to quit
315delay 1
316set appWorkspace to refMe's NSWorkspace's sharedWorkspace()
317set ocidOpenURL to refMe's NSURL's URLWithString:"x-apple.systempreferences:com.apple.Print-Scan-Settings.extension"
318appWorkspace's openURL:ocidOpenURL
319
320#############################
321#CUPSを開く
322tell application "Safari"
323   activate
324   make new document with properties {name:"localhost:631"}
325   tell front document
326      open location "http://localhost:631/printers/"
327   end tell
328end tell
329
330#############################
331#プリントセンターを開く
332tell application id "com.apple.printcenter" to activate
333
334#############################
335#チェック
336set ocidPrinterNameArray to refMe's NSPrinter's printerNames()
337repeat with itemPrinterName in ocidPrinterNameArray
338   set ocidPsPrinter to (refMe's NSPrinter's printerWithName:(itemPrinterName))
339   set strPrinterName to ocidPsPrinter's |name|() as text
340   log "Name:" & strPrinterName
341   set strPrinterType to ocidPsPrinter's type() as text
342   log "Type:" & strPrinterType
343   set strPrinterLevel to ocidPsPrinter's languageLevel() as text
344   log "Level:" & strPrinterLevel
345   set strPrinterDescription to ocidPsPrinter's deviceDescription() as record
346   set ocidDescriptionDict to refMe's NSMutableDictionary's alloc()'s init()
347   (ocidDescriptionDict's setDictionary:(strPrinterDescription))
348   set ocidAllKeys to ocidDescriptionDict's allKeys()
349   repeat with itemkey in ocidAllKeys
350      set ocidValue to (ocidDescriptionDict's valueForKey:(itemkey))
351      log ("Description:" & itemkey & " value: " & ocidValue & "") as text
352   end repeat
353   #この値はDeprecatedなのでこれがエラーするようになったら
354   #仕様が変わったって事になります
355   log ocidPsPrinter's isColor() as boolean
356   log "---\r"
357   
358end repeat
359
360##########################
361# 【通常】ZSH 実行
362to doZshShellScript(argCommandText)
363   set strCommandText to argCommandText as text
364   log "\r" & strCommandText & "\r"
365   set strExec to ("/bin/zsh -c '" & strCommandText & "'") as text
366   log "\r" & strExec & "\r"
367   ##########
368   #コマンド実行
369   try
370      log "コマンド開始"
371      set strResnponse to (do shell script strExec) as text
372      log "コマンド終了"
373   on error
374      return false
375   end try
376   return strResnponse
377end doZshShellScript

| | コメント (0)

lpコマンドヘルパー lpコマンドを生成して印刷するv2

LP印刷する.scpt

AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003(*
004印刷
005lpにPDFを投げるだけの単機能
006com.cocolog-nifty.quicktimer.icefloe *)
007----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
008use AppleScript version "2.8"
009use framework "Foundation"
010use framework "AppKit"
011use framework "PDFKit"
012use framework "UniformTypeIdentifiers"
013use scripting additions
014
015property refMe : a reference to current application
016
017set appFileManager to refMe's NSFileManager's defaultManager()
018
019################
020#入力 ファイル
021set strName to (name of current application) as text
022if strName is "osascript" then
023  tell application "SystemUIServer" to activate
024else
025  tell current application to activate
026end if
027#デスクトップ
028set appFileManager to refMe's NSFileManager's defaultManager()
029set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
030set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
031set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
032#ダイアログ
033set listUTI to {"com.adobe.pdf"}
034set strMes to ("PDFファイルを選んでください") as text
035set strPrompt to ("PDFファイルを選んでください") as text
036try
037  tell application "SystemUIServer"
038    activate
039    set aliasFilePath to (choose file strMes with prompt strPrompt default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias
040  end tell
041on error
042  log "エラーしました"
043  return "エラーしました"
044end try
045
046################
047#入力ファイルパスURL
048set strFilePath to (POSIX path of aliasFilePath) as text
049set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
050set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
051set ocidFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:(false)
052
053################
054#ページ数取得
055set ocidActivDoc to refMe's PDFDocument's alloc()'s initWithURL:(ocidFilePathURL)
056set numCntPage to ocidActivDoc's pageCount() as integer
057set ocidActivDoc to (missing value)
058
059#############################
060#プリンタを取得
061set ocidPrinterNameArray to refMe's NSPrinter's printerNames()
062set listPrinterName to ocidPrinterNameArray as list
063set strName to (name of current application) as text
064if strName is "osascript" then
065  tell application "SystemUIServer" to activate
066else
067  tell current application to activate
068end if
069set strTitle to ("選んでください") as text
070set strPrompt to ("プリンタを選んでください") as text
071try
072  tell application "SystemUIServer"
073    activate
074    set objResponse to (choose from list listPrinterName with title strTitle with prompt strPrompt default items (item 1 of listPrinterName) OK button name "OK" cancel button name "キャンセル" with empty selection allowed without multiple selections allowed)
075  end tell
076on error
077  log "エラーしました"
078  return "エラーしました"
079end try
080if (class of objResponse) is boolean then
081  return "キャンセルしましたA"
082else if (class of objResponse) is list then
083  if objResponse is {} then
084    return "キャンセルしましたB"
085  else
086    set strPrinterName to (item 1 of objResponse) as text
087  end if
088end if
089
090#############################
091#対象のプリンタの用紙設定を読み込む
092set ocidPaperNameArray to doGetPaperNameArray(strPrinterName)
093set listPaperName to ocidPaperNameArray as list
094set strName to (name of current application) as text
095if strName is "osascript" then
096  tell application "SystemUIServer" to activate
097else
098  tell current application to activate
099end if
100###
101set strTitle to ("選んでください") as text
102set strPrompt to ("用紙を選んでください") as text
103try
104  tell application "SystemUIServer"
105    activate
106    set objResponse to (choose from list listPaperName with title strTitle with prompt strPrompt default items (item 1 of listPaperName) OK button name "OK" cancel button name "キャンセル" with empty selection allowed without multiple selections allowed)
107  end tell
108on error
109  log "エラーしました"
110  return "エラーしました"
111end try
112if (class of objResponse) is boolean then
113  return "キャンセルしましたA"
114else if (class of objResponse) is list then
115  if objResponse is {} then
116    return "キャンセルしましたB"
117  else
118    set strPaperName to (item 1 of objResponse) as text
119  end if
120end if
121
122
123set strLpCommand to ("/usr/bin/lp -d " & strPrinterName & " -o media=" & strPaperName & " -o fit-to-page -o position=center -o page-ranges=1-" & numCntPage & " \"" & strFilePath & "\"") as text
124
125##############################
126#####ダイアログ
127##############################
128set strName to (name of current application) as text
129if strName is "osascript" then
130  tell application "SystemUIServer" to activate
131else
132  tell current application to activate
133end if
134###アイコンパス
135set aliasIconPath to POSIX file "/System/Applications/Utilities/Print Center.app/Contents/Resources/AppIcon.icns" as alias
136set strMes to ("コマンドです\rコピーしてターミナルで実行するか\rこのまま実行するか\r選んでください") as text
137tell application "SystemUIServer"
138  activate
139  set recordResult to (display dialog strMes with title "選んでください" default answer strLpCommand buttons {"このまま印刷", "クリップボードにコピー", "キャンセル"} default button "クリップボードにコピー" cancel button "キャンセル" giving up after 20 with icon aliasIconPath without hidden answer)
140end tell
141
142
143
144
145if button returned of recordResult is "このまま印刷" then
146  log doZshShellScript(strLpCommand)
147end if
148###クリップボードコピー
149if button returned of recordResult is "クリップボードにコピー" then
150  set strText to (text returned of recordResult) as text
151  try
152    ####ペーストボード宣言
153    set appPasteboard to refMe's NSPasteboard's generalPasteboard()
154    set ocidText to (refMe's NSString's stringWithString:(strText))
155    appPasteboard's clearContents()
156    appPasteboard's setString:(ocidText) forType:(refMe's NSPasteboardTypeString)
157  on error
158    tell application "Finder"
159      set the clipboard to strText as text
160    end tell
161  end try
162end if
163
164
165
166
167##########################
168# 【通常】ZSH 実行
169to doZshShellScript(argCommandText)
170  set strCommandText to argCommandText as text
171  log "\r" & strCommandText & "\r"
172  set strExec to ("/bin/zsh -c '" & strCommandText & "'") as text
173  log "\r" & strExec & "\r"
174  ##########
175  #コマンド実行
176  try
177    log "コマンド開始"
178    set strResnponse to (do shell script strExec) as text
179    log "コマンド終了"
180  on error
181    return false
182  end try
183  return strResnponse
184end doZshShellScript
185
186
187################################
188#【サブ】用紙名取得 lpoptions
189to doGetPaperNameArray(argPrinterName)
190  set strCommandText to ("/usr/bin/lpoptions -p \"" & argPrinterName & "\" -l") as text
191  log "\r" & strCommandText & "\r"
192  set strExec to ("/bin/zsh -c '" & strCommandText & " | grep PageSize' ") as text
193  set strResponse to (do shell script strExec) as text
194  #
195  set ocidLpoptiionString to refMe's NSMutableString's alloc()'s init()
196  ocidLpoptiionString's setString:(strResponse)
197  set ocidLpoptiionString to (ocidLpoptiionString's stringByReplacingOccurrencesOfString:("*") withString:(""))
198  set ocidLpoptiionString to (ocidLpoptiionString's stringByReplacingOccurrencesOfString:("PageSize/Media Size: ") withString:(""))
199  set ocidLpoptiionString to (ocidLpoptiionString's stringByReplacingOccurrencesOfString:(" Custom.WIDTHxHEIGHT") withString:(""))
200  #
201  set ocidPaperNameArray to ocidLpoptiionString's componentsSeparatedByString:(" ")
202  log ocidPaperNameArray as list
203  return ocidPaperNameArray
204end doGetPaperNameArray
205
206return
207
208
AppleScriptで生成しました

|

ページ設定今昔

昔々は、ページ設定といえば
プリンターメーカー毎に実装が異なっていたけど
PPDsから用紙サイズを取得する仕組みとかは今とそうは変わらない

Os9prin4


今はUTF8で改行がLFが多いけど
当時はSJISのPPDsとかあった

macOS10.6ぐらいで、ほぼ今の機能と同じ内容で

Website_image00370227-200104

プリンタを選択することで
対象のプリンタのPPDsを読み込み
用紙設定=用紙サイズと印字エリア=プリンタ固有の余白を考慮したページ設定ができるようになった



プリンタの状態には3つあって
・最後に使ったプリンタ
・デフォルトのプリンタ
・その他のプリンタ

12_202502272312012_20250227231201

本来
『最後に使ったプリンタ』か『デフォルトのプリンタ』の内容が反映されるはずの
ページ設定ですが
macOS12から、利用者が意図して選択しない限り
『任意のプリンタ』がデフォルト値になったのが元凶なんです
202502270612291_1346x11502

これ
LPプリンタからIPPプリンタへの過渡期であることから
Appleが意図してそのままにしている可能性もあります



デフォルト値が反映されなくなったページ設定ですが
Apple的には新しい印刷画面のUIを使えば問題ないわけなのです

3_20250227232101

印刷画面内にページ設定の選択肢が出るようになっています

旧タイプの印刷UIを使っている『Adobe』は

2_20250227232201

ユーザーがページ設定画面から
ページ設定する必要があるわけなのです。
この旧印刷UI使っているのは
最近のソフトウェアでは、ほとんどなくなっていて
残っている=旧印刷UI使っているのは
『Adobe』と『LibreOffice』ぐらいなんです。

なので
『Adobe』のソフトから印刷する場合は
OS9、漢字トークのころと同じ
『ページ設定が必須』なんですね。

202502270612291_1346x1150


202502270612511_1332x732

202502270613072_1336x490


202502270613201_1332x676



202502281026361_1404x13022

そこでAcrobatは『ページサイズに合わせて用紙を選択』のオプションを作ったわけだけど

これ

印刷できなくなる組み合わせになるケースが多く

原稿となるPDFのページサイズがA4といった
プリンタにセットできる用紙サイズの場合は問題ないが

ちょっと変わったページサイズになると

とたんに印刷できない状態になる

アイディアは良かったけど

作り込みが足りない?って感じかなぁ

少し残念な機能になっている


まとめ
料金払ってベータテストしているようなAdobeのソフトは
『ページ設定』を意識して設定してから
印刷すると…
いった
ページ設定の話でした

|

[NSPrinter]ページサイズ・余白サイズの取得(考え中・もういき)

結局『用紙名』を『lpoptions』で取得しているので
ちょっとした敗北感があるけど
私のスキルではここまで
AppleScript内で完結しない…
用紙サイズやら余白やらまでは取得できるようになった
NSPrinter.scpt

AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004#
005#com.cocolog-nifty.quicktimer.icefloe
006----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
007use AppleScript version "2.8"
008use framework "Foundation"
009use framework "AppKit"
010use framework "PrintKit"
011use scripting additions
012
013property refMe : a reference to current application
014set appFileManager to refMe's NSFileManager's defaultManager()
015
016#############################
017#プリンタを取得
018set ocidPrinterArray to refMe's NSPrinter's printerNames()
019#プリンタの数だけ繰り返し
020repeat with itemPrinterName in ocidPrinterArray
021  #【NSPrinter】プリンタの名前でプリンタを再定義
022  set itemPrinter to (refMe's NSPrinter's printerWithName:(itemPrinterName))
023  log itemPrinter's languageLevel() as text
024  log itemPrinter's deviceDescription() as list
025  set strPrinterName to itemPrinter's |name|() as text
026  log itemPrinter's type() as text
027  #【NSPrintInfo
028  set ocidPrintInfo to refMe's NSPrintInfo's alloc()'s init()
029  set ocidPrintInfoDict to ocidPrintInfo's dictionary()
030  set ocidAllKeys to ocidPrintInfoDict's allKeys()
031  repeat with itemKey in ocidAllKeys
032    log itemKey as text
033    log (ocidPrintInfoDict's objectForKey:(itemKey)) as list
034  end repeat
035  set ocidPrinter to (ocidPrintInfoDict's objectForKey:("NSPrinter"))
036  set strPrinterName to ocidPrinter's |name|() as text
037  set ocidPaperNameArray to doGetPaperNameArray(strPrinterName)
038  
039  
040  repeat with itemPaperName in ocidPaperNameArray
041    set ocidItemPaper to (ocidPrinter's pageSizeForPaper:(itemPaperName))
042    log ocidItemPaper's width
043    log ocidItemPaper's height
044    #
045    set appPrintInfo to refMe's NSPrintInfo's alloc()'s init()
046    (appPrintInfo's setPrinter:(ocidPrinter))
047    (appPrintInfo's setPaperName:(itemPaperName))
048    
049    log appPrintInfo's paperSize()
050    log appPrintInfo's topMargin()
051    log appPrintInfo's bottomMargin()
052    log appPrintInfo's leftMargin()
053    log appPrintInfo's rightMargin()
054    log appPrintInfo's imageablePageBounds()
055    set ocidPaperOrientation to appPrintInfo's orientation()
056    log ocidPaperOrientation
057    if ocidPaperOrientation = (refMe's NSPaperOrientationPortrait) then
058      log "ポートレート形"
059    else if ocidPaperOrientation = (refMe's NSPaperOrientationLandscape) then
060      log "ランドスケープ形"
061    end if
062    log appPrintInfo's paperName() as text
063    log appPrintInfo's localizedPaperName() as text
064    log appPrintInfo's imageablePageBounds()
065    
066    log (ocidPrinter's imageRectForPaper:(itemPaperName))
067  end repeat
068end repeat
069
070
071################################
072#用紙名取得
073to doGetPaperNameArray(argPrinterName)
074  set strCommandText to ("/usr/bin/lpoptions -p \"" & argPrinterName & "\" -l") as text
075  log "\r" & strCommandText & "\r"
076  set strExec to ("/bin/zsh -c '" & strCommandText & " | grep PageSize' ") as text
077  set strResponse to (do shell script strExec) as text
078  #
079  set ocidLpoptiionString to refMe's NSMutableString's alloc()'s init()
080  ocidLpoptiionString's setString:(strResponse)
081  set ocidLpoptiionString to (ocidLpoptiionString's stringByReplacingOccurrencesOfString:("*") withString:(""))
082  set ocidLpoptiionString to (ocidLpoptiionString's stringByReplacingOccurrencesOfString:("PageSize/Media Size: ") withString:(""))
083  set ocidLpoptiionString to (ocidLpoptiionString's stringByReplacingOccurrencesOfString:(" Custom.WIDTHxHEIGHT") withString:(""))
084  #
085  set ocidPaperNameArray to ocidLpoptiionString's componentsSeparatedByString:(" ")
086  log ocidPaperNameArray as list
087  return ocidPaperNameArray
088end doGetPaperNameArray
AppleScriptで生成しました

|

[bash]PostScript用PSプリンタ設定(少し手直し)


サンプルコード

サンプルソース(参考)
行番号ソース
001#!/bin/bash
002#com.cocolog-nifty.quicktimer.icefloe
003#################################################
004###実行しているユーザー名
005CONSOLE_USER=$(/bin/echo "show State:/Users/ConsoleUser" | /usr/sbin/scutil | /usr/bin/awk '/Name :/ { print $3 }')
006/bin/echo "コンソールユーザー(scutil): $CONSOLE_USER"
007###実行しているユーザー名
008HOME_USER=$(/bin/echo "$HOME" | /usr/bin/awk -F'/' '{print $NF}')
009/bin/echo "実行ユーザー(HOME): $HOME_USER"
010###logname
011LOGIN_NAME=$(/usr/bin/logname)
012/bin/echo "ログイン名(logname): $LOGIN_NAME"
013###UID
014USER_NAME=$(/usr/bin/id -un)
015/bin/echo "ユーザー名(id): $USER_NAME"
016###STAT
017STAT_USR=$(/usr/bin/stat -f%Su /dev/console)
018/bin/echo "STAT_USR(console): $STAT_USR"
019########################################
020STR_URL="https://raw.githubusercontent.com/force4u/Acrobat/main/AppleScript/%E5%85%B1%E9%80%9A/AcrobatPPDs/AcrobatPPDs.zip"
021/bin/echo "処理開始"
022##展開先
023/bin/mkdir -p "/Users/${STAT_USR}/Library/Printers/PPDs/Contents/Resources"
024##ダウンロード先
025STR_TMPDIRPATH=$(/usr/bin/mktemp -d)
026/bin/chmod 777 "$STR_TMPDIRPATH"
027/bin/echo "ダウンロード開始:" "$STR_TMPDIRPATH"
028##
029
030if ! /usr/bin/curl -s --head "$STR_URL" >/dev/null
031then
032  /bin/echo "エラー:URLの生存確認で失敗しました"
033  exit 1
034fi
035###リダイレクト先のURLを取得
036
037if ! STR_REDIRECT_URL=$(/usr/bin/curl -s -L -I -o /dev/null -w '%{url_effective}' "$STR_URL")
038then
039  /bin/echo "エラー:リダイレクトの取得に失敗しました"
040  exit 1
041fi
042###ファイル名を取得
043STR_FILE_NAME=$(/usr/bin/basename "$STR_REDIRECT_URL")
044/bin/echo "ファイル名:$PKG_FILE_NAME"
045###ダウンロード
046
047if ! /usr/bin/curl -L --retry 3 --retry-connrefused --retry-delay 3 -o "$STR_TMPDIRPATH/$STR_FILE_NAME" "$STR_URL"
048then
049  /bin/echo "エラー:ダウンロードに失敗しました"
050  exit 1
051fi
052###展開
053if ! /usr/bin/unzip -q "$STR_TMPDIRPATH/$STR_FILE_NAME" -d "$STR_TMPDIRPATH"
054then
055 /bin/echo "エラー:解凍に失敗しました"
056exit 1
057fi
058###
059/bin/mkdir -p "/Users/${STAT_USR}/Library/Printers/PPDs/Contents/Resources/Acrobat"
060###移動
061if ! /usr/bin/ditto "$STR_TMPDIRPATH/AcrobatPPDs" "/Users/${STAT_USR}/Library/Printers/PPDs/Contents/Resources/Acrobat"
062then
063  /bin/echo "エラー:移動に失敗しました"
064  exit 1
065fi
066#
067/bin/chmod  -Rf 644 "/Users/${STAT_USR}/Library/Printers/PPDs/Contents/Resources/Acrobat"
068/bin/chmod  755 "/Users/${STAT_USR}/Library/Printers/PPDs/Contents/Resources/Acrobat"
069###################
070###設定項目
071STR_CHK_NAME="PsPrinterAcrobat9J"
072STR_PPD_PATH="/Users/${STAT_USR}/Library/Printers/PPDs/Contents/Resources/Acrobat/ADPDF9J.PPD"
073#登録済みのプリント台数を求めて
074STR_PLIST_FILEPAHT="/Library/Preferences/org.cups.printers.plist"
075ROOT_ARRAY=$(/usr/libexec/PlistBuddy -c "Print:" "$STR_PLIST_FILEPAHT")
076PRINTER_COUNT=$(/bin/echo "$ROOT_ARRAY" | grep -c 'printer-name')
077if [ "$PRINTER_COUNT" = 0 ]; then
078  /bin/echo "プリンターは登録されていません"
079else
080  ##登録済みのプリンタがある場合はチェックする
081  /bin/echo "登録済みプリンタは$PRINTER_COUNT台ありました"
082  for ((i = 0; i < PRINTER_COUNT; i++)); do
083    STR_PRINTER_NAME=$(/usr/libexec/PlistBuddy -c "Print:$i:printer-name:" "$STR_PLIST_FILEPAHT")
084    /bin/echo "プリンター $i の名前: $STR_PRINTER_NAME"
085  done
086  #登録済みでないか?チェックする
087  for ((i = 0; i < PRINTER_COUNT; i++)); do
088    STR_PRINTER_NAME=$(/usr/libexec/PlistBuddy -c "Print:$i:printer-name:" "$STR_PLIST_FILEPAHT")
089    if [ "$STR_CHK_NAME" = "$STR_PRINTER_NAME" ]; then
090      /bin/echo "エラー:プリンタ$STR_PRINTER_NAMEはすでに登録済みです"
091      #再登録=再作成の場合はここで一度削除する
092      #停止
093      /usr/sbin/cupsdisable "$STR_PRINTER_NAME"
094      #ジョブ削除
095      /usr/bin/cancel -a "$STR_PRINTER_NAME"
096      #プリンタ削除
097      /usr/sbin/lpadmin -x "$STR_PRINTER_NAME"
098    fi
099  done
100fi
101
102#チェックを通過した場合は新規に登録する
103if [ -f "$STR_PPD_PATH" ]; then
104  #プリンタ登録
105  /usr/sbin/lpadmin -p "$STR_CHK_NAME" -E -v "lpd://localhost/" -P "$STR_PPD_PATH" -D "$STR_CHK_NAME" -L "PS書き出し用の設定です" -o printer-is-shared=false
106  if [ $? -ne 0 ]; then
107    /bin/echo "エラー:プリンターの登録でエラーになりました"
108    exit 1
109  fi
110  #仮想プリンタなので停止させる場合
111  /usr/sbin/cupsdisable "$STR_PRINTER_NAME"
112else
113  /bin/echo "エラー:PPDファイルが存在しません"
114  exit 1
115fi
116################################################
117###設定項目
118STR_CHK_NAME="PsPrinteTRUEFLOW_J"
119STR_PPD_PATH="/Users/${STAT_USR}/Library/Printers/PPDs/Contents/Resources/Acrobat/DS TRUEFLOW_J V1.4"
120#登録済みのプリント台数を求めて
121STR_PLIST_FILEPAHT="/Library/Preferences/org.cups.printers.plist"
122ROOT_ARRAY=$(/usr/libexec/PlistBuddy -c "Print:" "$STR_PLIST_FILEPAHT")
123PRINTER_COUNT=$(/bin/echo "$ROOT_ARRAY" | grep -c 'printer-name')
124if [ "$PRINTER_COUNT" = 0 ]; then
125  /bin/echo "プリンターは登録されていません"
126else
127  ##登録済みのプリンタがある場合はチェックする
128  /bin/echo "登録済みプリンタは$PRINTER_COUNT台ありました"
129  for ((i = 0; i < PRINTER_COUNT; i++)); do
130    STR_PRINTER_NAME=$(/usr/libexec/PlistBuddy -c "Print:$i:printer-name:" "$STR_PLIST_FILEPAHT")
131    /bin/echo "プリンター $i の名前: $STR_PRINTER_NAME"
132  done
133  #登録済みでないか?チェックする
134  for ((i = 0; i < PRINTER_COUNT; i++)); do
135    STR_PRINTER_NAME=$(/usr/libexec/PlistBuddy -c "Print:$i:printer-name:" "$STR_PLIST_FILEPAHT")
136    if [ "$STR_CHK_NAME" = "$STR_PRINTER_NAME" ]; then
137      /bin/echo "エラー:プリンタ$STR_PRINTER_NAMEはすでに登録済みです"
138      #再登録=再作成の場合はここで一度削除する
139      #停止
140      /usr/sbin/cupsdisable "$STR_PRINTER_NAME"
141      #ジョブ削除
142      /usr/bin/cancel -a "$STR_PRINTER_NAME"
143      #プリンタ削除
144      /usr/sbin/lpadmin -x "$STR_PRINTER_NAME"
145      #再作成の場合はこのexitは取る
146      # exit 1
147    fi
148  done
149fi
150
151#チェックを通過した場合は新規に登録する
152if [ -f "$STR_PPD_PATH" ]; then
153  #プリンタ登録
154
155  if !  /usr/sbin/lpadmin -p "$STR_CHK_NAME" -E -v "lpd://localhost/" -P "$STR_PPD_PATH" -D "$STR_CHK_NAME" -L "PS書き出し用の設定です" -o printer-is-shared=false
156then
157    /bin/echo "エラー:プリンターの登録でエラーになりました"
158    exit 1
159  fi
160  #仮想プリンタなので停止させる場合
161  /usr/sbin/cupsdisable "$STR_PRINTER_NAME"
162else
163  /bin/echo "エラー:PPDファイルが存在しません"
164  exit 1
165fi
166################################################
167#プリンタープール削除
168/usr/sbin/lpadmin -x "A:PsPrinters"
169#プリンタープール再作成
170/usr/sbin/lpadmin -p "PsPrinterAcrobat9J" -c "A:PsPrinters"
171/usr/sbin/lpadmin -p "PsPrinteTRUEFLOW_J" -c "A:PsPrinters"
172/usr/sbin/lpadmin -p "A:PsPrinters"  -L "Psプリンタのプール(class)"
173/usr/sbin/lpadmin -p "A:PsPrinters" -o printer-is-shared=false
174/usr/sbin/lpadmin -p "A:PsPrinters" -u allow:all
175/usr/sbin/lpadmin -p "A:PsPrinters" -E
176/usr/sbin/cupsdisable "A:PsPrinters" 
177
178
179
180################################################
181#終了処理
182/usr/sbin/lpadmin  -d "PsPrinterAcrobat9J"
183/usr/sbin/cupsctl  --no-share-printers
184/usr/sbin/cupsctl  WebInterface=YES
185"/System/Library/SystemConfiguration/PrinterNotifications.bundle/Contents/MacOS/makequeues" -h
186"/System/Library/SystemConfiguration/PrinterNotifications.bundle/Contents/MacOS/makequeues" -k lpd
187"/System/Library/SystemConfiguration/PrinterNotifications.bundle/Contents/MacOS/makequeues" -k ipp
188"/System/Library/Image Capture/Tools/use_updated_image_capture_software"
189/usr/bin/killall -HUP com.apple.PrintKit.PrinterTool
190/usr/bin/killall -HUP PrintUITool
191/usr/bin/killall -HUP printtool
192/usr/bin/killall -HUP cfprefsd
193#
194/usr/bin/open -b com.apple.Safari http://localhost:631/printers/
195
196##プリントセンターを開く
197/usr/bin/open -b com.apple.printcenter
198
199exit 0
AppleScriptで生成しました

|

[Printer]PostScript用PSプリンタ設定(少し手直し)


AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004# 20241118 macOS15でエラーになりにくいように少し手直し
005# com.cocolog-nifty.quicktimer.icefloe
006----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
007use AppleScript version "2.8"
008use framework "Foundation"
009use framework "AppKit"
010use framework "PrintKit"
011use framework "UniformTypeIdentifiers"
012use scripting additions
013
014property refMe : a reference to current application
015
016set appFileManager to refMe's NSFileManager's defaultManager()
017
018
019
020#############################
021# 共有ディレクトリのPPDを廃止
022# makequeuesでエラーになるため
023#############################
024#廃止予定ディレクトリパス
025set strTmpDirPath to "/Users/Shared/Library/Printers" as text
026set ocidTmpDirPathStr to refMe's NSString's stringWithString:(strTmpDirPath)
027set ocidTmpDirPath to ocidTmpDirPathStr's stringByStandardizingPath()
028set ocidTmpDirPathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(ocidTmpDirPath) isDirectory:(true)
029#フォルダ生成
030set appFileManager to refMe's NSFileManager's defaultManager()
031set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
032ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
033set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidTmpDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error| :(reference)
034#注意喚起テキスト生成
035set strTmpFileName to ("このディレクトリは廃止になります.txt") as text
036set strTmpFilePathURL to ocidTmpDirPathURL's URLByAppendingPathComponent:(strTmpFileName) isDirectory:(false)
037set ocidTmpContentsString to refMe's NSString's stringWithString:("このディレクトリは廃止になります\n任意で削除してください")
038set listDone to ocidTmpContentsString's writeToURL:(strTmpFilePathURL) atomically:(true) encoding:(refMe's NSUTF8StringEncoding) |error| :(reference)
039
040#############################
041###AcrobatPPDの有無を確認
042#############################
043#ユーザードメインのPPD保存先
044set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSUserDomainMask))
045set ocidLibraryDirPathURL to ocidURLsArray's firstObject()
046set ocidExtractDirPathURL to ocidLibraryDirPathURL's URLByAppendingPathComponent:("Printers/PPDs/Contents/Resources") isDirectory:(true)
047#
048ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
049set listDone to appFileManager's createDirectoryAtURL:(ocidExtractDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error| :(reference)
050#
051set ocidSavePPDDirPathURL to ocidLibraryDirPathURL's URLByAppendingPathComponent:"Printers/PPDs/Contents/Resources/Acrobat" isDirectory:(true)
052set ocidPPDFilePathURL to ocidSavePPDDirPathURL's URLByAppendingPathComponent:"ADPDF9J.PPD" isDirectory:(false)
053############
054set boolFileExists to (appFileManager's fileExistsAtPath:(ocidPPDFilePathURL's |path|()) isDirectory:false)
055
056if boolFileExists is true then
057  log "PPDはインストール済み"
058else if boolFileExists is false then
059  ############ない場合はダウンロード
060  set strZipFileURL to "https://force4u.cocolog-nifty.com/skywalker/files/acrobatppds.zip"
061  set ocidZipFilePath to (refMe's NSString's stringWithString:strZipFileURL)
062  set ocidZipFilePathURL to refMe's NSURL's alloc()'s initWithString:ocidZipFilePath
063  set ocidOption to (refMe's NSDataReadingMappedIfSafe)
064  set listResponse to refMe's NSData's dataWithContentsOfURL:(ocidZipFilePathURL) options:(ocidOption) |error| :(reference)
065  if (item 2 of listResponse) = (missing value) then
066    log "NSData 正常処理"
067    set ocidZipData to (item 1 of listResponse)
068  else if (item 2 of listResponse) ≠ (missing value) then
069    set strErrorNO to (item 2 of listResponse)'s code() as text
070    set strErrorMes to (item 2 of listResponse)'s localizedDescription() as text
071    refMe's NSLog("■:" & strErrorNO & strErrorMes)
072    return "エラーしました" & strErrorNO & strErrorMes
073  end if
074  #保存
075  set ocidTempDirURL to appFileManager's temporaryDirectory()
076  set ocidUUID to refMe's NSUUID's alloc()'s init()
077  set ocidUUIDString to ocidUUID's UUIDString
078  set ocidSaveZipDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:true
079  #
080  ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
081  set listDone to appFileManager's createDirectoryAtURL:(ocidSaveZipDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error| :(reference)
082  #パス
083  set ocidSaveZipFilePathURL to ocidSaveZipDirPathURL's URLByAppendingPathComponent:"acrobatppds.zip" isDirectory:false
084  set ocidOption to (refMe's NSDataWritingAtomic)
085  set listDone to ocidZipData's writeToURL:(ocidSaveZipFilePathURL) options:(ocidOption) |error| :(reference)
086  if (item 1 of listDone) is true then
087    log "正常処理"
088  else if (item 2 of listDone) ≠ (missing value) then
089    set strErrorNO to (item 2 of listDone)'s code() as text
090    set strErrorMes to (item 2 of listDone)'s localizedDescription() as text
091    refMe's NSLog("■:" & strErrorNO & strErrorMes)
092    return "エラーしました" & strErrorNO & strErrorMes
093  end if
094  
095  ########################
096  #### 解凍
097  ########################
098  set strZipFilePathURL to (ocidSaveZipFilePathURL's |path|()) as text
099  set strSaveDirPathURL to (ocidExtractDirPathURL's |path|()) as text
100  
101  ################
102  #コマンド実行
103  set strCommandText to ("/usr/bin/ditto -xk  \"" & strZipFilePathURL & "\"   \"" & strSaveDirPathURL & "\"") as text
104  log strCommandText
105  set strExecCommand to ("/bin/zsh -c '" & strCommandText & "'") as text
106  try
107    do shell script strExecCommand
108  on error
109    return "ditto でエラーしました"
110  end try
111  
112end if
113
114#############################
115###Acrobatプリンタの有無を確認
116#############################
117
118set strQueName to ("PsPrinterAcrobat9J") as text
119set strModelName to ("PostScript書出用設定") as text
120set strDescriptionName to ("Adobe PDF J 3018.101") as text
121set ocidPPDFilePathURL to ocidSavePPDDirPathURL's URLByAppendingPathComponent:("ADPDF9J.PPD") isDirectory:(false)
122set strPPDFilePath to (ocidPPDFilePathURL's |path|()) as text
123
124set ocidPrinterNameArray to refMe's NSPrinter's printerNames()
125set booChkPsPrinter to false as boolean
126repeat with itemPrinterNameArray in ocidPrinterNameArray
127  set ocidPsPrinter to (refMe's NSPrinter's printerWithName:itemPrinterNameArray)
128  set strPrinterType to ocidPsPrinter's type() as text
129  if strPrinterType is strDescriptionName then
130    set booChkPsPrinter to true as boolean
131  end if
132end repeat
133if booChkPsPrinter is true then
134  log "Acrobatプリンタ設定済み"
135  ################
136  ##リセット=削除
137  set strCommandText to ("/usr/sbin/lpadmin -x \"" & strQueName & "\"") as text
138  log strCommandText
139  set strExec to ("/bin/zsh -c \"" & strCommandText & "\"") as text
140  try
141    do shell script strExec
142  end try
143end if
144
145################
146#プリンタ登録
147set strCommandText to ("/usr/sbin/lpadmin -p \"" & strQueName & "\" -E -v \"lpd://localhost/\" -P \"" & strPPDFilePath & "\" -D \"" & strQueName & "\" -L \"" & strModelName & "\" -o printer-is-shared=false") as text
148log strCommandText
149set strExecCommand to ("/bin/zsh -c '" & strCommandText & "'") as text
150try
151  do shell script strExecCommand
152on error
153  return "lpadmin -p でエラーしました"
154end try
155
156
157################
158#プリンタ登録
159set strCommandText to ("/usr/sbin/cupsdisable  \"" & strQueName & "\"") as text
160log strCommandText
161set strExecCommand to ("/bin/zsh -c '" & strCommandText & "'") as text
162try
163  do shell script strExecCommand
164on error
165  return "lpadmin -p でエラーしました"
166end try
167
168#############################
169###PsPrinteTRUEFLOW_Jプリンタ
170#############################
171
172set strQueName to ("PsPrinteTRUEFLOW_J") as text
173set strModelName to ("PostScript書出用設定") as text
174set strDescriptionName to ("DS TRUEFLOW_J V1.4") as text
175set ocidPPDFilePathURL to ocidSavePPDDirPathURL's URLByAppendingPathComponent:("DS TRUEFLOW_J V1.4") isDirectory:(false)
176set strPPDFilePath to (ocidPPDFilePathURL's |path|()) as text
177
178##リセット=削除
179set strCommandText to ("/usr/sbin/lpadmin -x \"" & strQueName & "\"") as text
180log strCommandText
181
182set strExec to ("/bin/zsh -c \"" & strCommandText & "\"") as text
183try
184  do shell script strExec
185end try
186
187
188#プリンタ登録
189set strCommandText to ("/bin/zsh -c '/usr/sbin/lpadmin -p \"" & strQueName & "\" -E -v \"lpd://localhost/\" -P \"" & strPPDFilePath & "\" -D \"" & strQueName & "\" -L \"" & strModelName & "\" -o printer-is-shared=false'") as text
190log strCommandText
191try
192  do shell script strCommandText
193on error
194  return "lpadmin -xでエラーになりました"
195end try
196#停止させる
197set strCommandText to ("/bin/zsh -c '/usr/sbin/cupsdisable  \"" & strQueName & "\"'") as text
198log strCommandText
199try
200  do shell script strCommandText
201on error
202  return "cupsdisableでエラーになりました"
203end try
204
205#############################
206###A:PsPrintersプリンタ削除
207#############################
208try
209  do shell script "/usr/sbin/lpadmin -x \"A:PsPrinters\""
210end try
211
212
213#############################
214###プリンタプールに追加
215#############################
216try
217  do shell script "/usr/sbin/lpadmin -p \"PsPrinterAcrobat9J\" -c \"A:PsPrinters\""
218end try
219try
220  do shell script "/usr/sbin/lpadmin -p \"PsPrinteTRUEFLOW_J\" -c \"A:PsPrinters\""
221end try
222#############################
223###プリンタプールの作成
224#############################
225try
226  do shell script "/usr/sbin/lpadmin  -p \"A:PsPrinters\" -L \"Psプリンタのプール(class)\""
227  do shell script "/usr/sbin/lpadmin  -p \"A:PsPrinters\" -o printer-is-shared=false"
228  do shell script "/usr/sbin/lpadmin  -p \"A:PsPrinters\" -u allow:all"
229  do shell script "/usr/sbin/lpadmin  -p \"A:PsPrinters\" -E"
230end try
231try
232  do shell script "/usr/sbin/cupsdisable \"A:PsPrinters\""
233end try
234
235#############################
236###デフォルトプリンタを指定する
237#############################
238
239do shell script "/usr/sbin/lpadmin  -d \"PsPrinterAcrobat9J\""
240
241#############################
242### 初期設定 PLIST 書き換え
243#############################
244set ocidFalse to (refMe's NSNumber's numberWithBool:false)
245####設定ファイルのパス
246set ocidLibrariesPathURLArray to (appFileManager's URLsForDirectory:(refMe's NSAllLibrariesDirectory) inDomains:(refMe's NSUserDomainMask))
247set ocidLibrariesPathURL to item 1 of ocidLibrariesPathURLArray
248set ocidFilePathURL to ocidLibrariesPathURL's URLByAppendingPathComponent:"Preferences/org.cups.PrintingPrefs.plist" isDirectory:false
249#####PLISTの内容を読み込んで
250set ocidPlistDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
251set listReadPlistData to refMe's NSMutableDictionary's dictionaryWithContentsOfURL:ocidFilePathURL  |error| :(reference)
252
253set ocidPlistDict to item 1 of listReadPlistData
254ocidPlistDict's setObject:ocidFalse forKey:"UseLastPrinter"
255set ocidLastUsedPrinter to ocidPlistDict's objectForKey:"LastUsedPrinters"
256if ocidLastUsedPrinter is not (missing value) then
257  ocidLastUsedPrinter's removeObjectAtIndex:0
258  set recordItemDict to {Network:"192.168.0.1", PrinterID:"" & strPrinterName & ""}
259  ocidLastUsedPrinter's addObject:recordItemDict
260  ###書き込み用にバイナリーデータに変換
261  set ocidNSbplist to refMe's NSPropertyListBinaryFormat_v1_0
262  set ocidPlistEditDataArray to refMe's NSPropertyListSerialization's dataWithPropertyList:ocidPlistDict format:ocidNSbplist options:0  |error| :(reference)
263  set ocidPlistEditData to item 1 of ocidPlistEditDataArray
264  set boolWritetoUrlArray to ocidPlistEditData's writeToURL:ocidFilePathURL options:0  |error| :(reference)
265end if
266#############################
267#cupsctl プリンタ共有停止
268set strCommandText to ("/bin/zsh -c '/usr/sbin/cupsctl  --no-share-printers'") as text
269log strCommandText
270try
271  do shell script strCommandText
272end try
273#############################
274#CUPS WEBインターフェイスを有効化
275set strCommandText to ("/bin/zsh -c '/usr/sbin/cupsctl  WebInterface=YES'") as text
276log strCommandText
277try
278  do shell script strCommandText
279end try
280#############################
281#makequeues USB リバインド
282set strCommandText to ("/bin/zsh -c '/System/Library/SystemConfiguration/PrinterNotifications.bundle/Contents/MacOS/makequeues -r'") as text
283log strCommandText
284try
285  do shell script strCommandText
286end try
287
288#makequeues PPD リバインド
289set strCommandText to ("/bin/zsh -c '/System/Library/SystemConfiguration/PrinterNotifications.bundle/Contents/MacOS/makequeues -h'") as text
290log strCommandText
291try
292  do shell script strCommandText
293end try
294#makequeues LPD リバインド
295set strCommandText to ("/bin/zsh -c '/System/Library/SystemConfiguration/PrinterNotifications.bundle/Contents/MacOS/makequeues -k lpd'") as text
296log strCommandText
297try
298  do shell script strCommandText
299end try
300#makequeues IPP リバインド
301set strCommandText to ("/bin/zsh -c '/System/Library/SystemConfiguration/PrinterNotifications.bundle/Contents/MacOS/makequeues -k ipp'") as text
302log strCommandText
303try
304  do shell script strCommandText
305end try
306#makequeues IPP リバインド
307set strCommandText to ("/bin/zsh -c '\"/System/Library/Image Capture/Tools/use_updated_image_capture_software\"'") as text
308log strCommandText
309try
310  do shell script strCommandText
311end try
312#############################
313#CUPSプロセスを再起動
314set strCommandText to ("/bin/zsh -c '/usr/bin/killall -HUP com.apple.PrintKit.PrinterTool'") as text
315log strCommandText
316try
317  do shell script strCommandText
318end try
319####
320set strCommandText to ("/bin/zsh -c '/usr/bin/killall -HUP PrintUITool'") as text
321log strCommandText
322try
323  do shell script strCommandText
324end try
325####
326set strCommandText to ("/bin/zsh -c '/usr/bin/killall -HUP printtool'") as text
327log strCommandText
328try
329  do shell script strCommandText
330end try
331#############################
332#CFPreferencesを再起動
333set strCommandText to ("/bin/zsh -c '/usr/bin/killall -HUP cfprefsd'") as text
334log strCommandText
335try
336  do shell script strCommandText
337end try
338
339
340#############################
341#プリンタパネルを開く
342tell application id "com.apple.systempreferences" to quit
343delay 1
344set appWorkspace to refMe's NSWorkspace's sharedWorkspace()
345set ocidOpenURL to refMe's NSURL's URLWithString:"x-apple.systempreferences:com.apple.Print-Scan-Settings.extension"
346appWorkspace's openURL:ocidOpenURL
347
348#############################
349#CUPSを開く
350tell application "Safari"
351  activate
352  make new document with properties {name:"localhost:631"}
353  tell window 1
354    open location "http://localhost:631/printers/"
355  end tell
356end tell
AppleScriptで生成しました

|

PPDの用紙情報をダイアログに戻して表示


AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004# com.cocolog-nifty.quicktimer.icefloe
005----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
006use AppleScript version "2.8"
007use framework "Foundation"
008use framework "AppKit"
009use framework "PrintKit"
010use scripting additions
011
012property refMe : a reference to current application
013set appFileManager to refMe's NSFileManager's defaultManager()
014
015
016############################
017#作業エリア gz解凍 zcatは使わない
018#起動時に削除される項目内
019set ocidTempDirURL to appFileManager's temporaryDirectory()
020set ocidUUID to refMe's NSUUID's alloc()'s init()
021set ocidUUIDString to ocidUUID's UUIDString
022set ocidSaveDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:(true)
023set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
024ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
025set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error| :(reference)
026#パス
027set strFileName to "Printer.ppd" as text
028set ocidPPDFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strFileName) isDirectory:false
029set strTempFilePath to (ocidPPDFilePathURL's |path|) as text
030
031############################
032#ダイアログ
033set strName to (name of current application) as text
034if strName is "osascript" then
035  tell application "Finder" to activate
036else
037  tell current application to activate
038end if
039#ローカルドメインのプリンタPPD
040set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSLocalDomainMask))
041set ocidLibraryDirPathURL to ocidURLsArray's firstObject()
042set ocidResourcesDirPathURL to ocidLibraryDirPathURL's URLByAppendingPathComponent:("Printers/PPDs/Contents/Resources") isDirectory:(true)
043set aliasDefaultLocation to (ocidResourcesDirPathURL's absoluteURL()) as alias
044set listUTI to {"public.item"}
045set strMes to ("PPDファイルを選んでください") as text
046set strPrompt to ("PPDファイルを選んでください\n拡張子無しの場合や\ngz圧縮されている場合があります") as text
047try
048  set aliasChooseFilePath to (choose file strMes with prompt strPrompt default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias
049on error
050  log "エラーしました"
051  return "エラーしました"
052end try
053############################
054#元になるPPD
055set strChooseFilePath to (POSIX path of aliasChooseFilePath) as text
056set ocidChooseFilePathStr to refMe's NSString's stringWithString:(strChooseFilePath)
057set ocidChooseFilePath to ocidChooseFilePathStr's stringByStandardizingPath()
058set ocidChooseFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(ocidChooseFilePath) isDirectory:(false)
059set strChooseExtensionName to (ocidChooseFilePathURL's pathExtension()) as text
060#gzなら解凍
061if strChooseExtensionName is "gz" then
062  ################
063  #コマンド実行
064  set strCommandText to ("/usr/bin/gunzip -c \"" & strChooseFilePath & "\" > \"" & strTempFilePath & "\"") as text
065  log strCommandText
066  set strExecCommand to ("/bin/zsh -c '" & strCommandText & "'") as text
067  try
068    do shell script strExecCommand
069  on error
070    return "gunzip でエラーしました"
071  end try
072  
073else
074  #gz以外ならそのまま利用
075  ################
076  #コマンド実行
077  set strCommandText to ("/usr/bin/ditto \"" & strChooseFilePath & "\" \"" & strTempFilePath & "\"") as text
078  log strCommandText
079  set strExecCommand to ("/bin/zsh -c '" & strCommandText & "'") as text
080  try
081    do shell script strExecCommand
082  on error
083    return "ditto でエラーしました"
084  end try
085  
086end if
087
088############################
089#PPDを読み込む NSDATA
090set ocidOption to (refMe's NSDataReadingMappedIfSafe)
091set listResponse to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidPPDFilePathURL) options:(ocidOption) |error| :(reference)
092if (item 2 of listResponse) = (missing value) then
093  log "正常処理"
094  set ocidReadData to (item 1 of listResponse)
095else if (item 2 of listResponse) ≠ (missing value) then
096  set strErrorNO to (item 2 of listResponse)'s code() as text
097  set strErrorMes to (item 2 of listResponse)'s localizedDescription() as text
098  refMe's NSLog("■:" & strErrorNO & strErrorMes)
099  return "エラーしました" & strErrorNO & strErrorMes
100end if
101
102############################
103#テキストにする NSString's
104set ocidReadStrings to refMe's NSString's alloc()'s initWithData:(ocidReadData) encoding:(refMe's NSUTF8StringEncoding)
105#ここまでのデータをクリアしておく
106set ocidReadData to (missing value)
107#改行をUNIXに強制
108set ocidReadStringsTMP to (ocidReadStrings's stringByReplacingOccurrencesOfString:("\n\r") withString:("\n"))
109set ocidReadStringsTMP to (ocidReadStringsTMP's stringByReplacingOccurrencesOfString:("\r") withString:("\n"))
110set ocidReadStrings to (ocidReadStringsTMP's stringByReplacingOccurrencesOfString:("\n\n") withString:("\n"))
111
112
113############################
114#リストArrayでの処理
115#改行でリストにする
116set ocidReadStringsArray to ocidReadStrings's componentsSeparatedByString:("\n")
117set ocidImageableAreaDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
118set ocidPaperDimensionDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
119
120#全行チェック
121repeat with itemLine in ocidReadStringsArray
122  if ((itemLine's hasPrefix:("*ImageableArea")) as boolean) then
123    set ocidImgAreaStr to (itemLine's stringByReplacingOccurrencesOfString:("*ImageableArea ") withString:(""))
124    set ocidImgAreaArray to (ocidImgAreaStr's componentsSeparatedByString:(": \""))
125    set ocidSetKey to ocidImgAreaArray's firstObject()
126    set ocidTempRectStr to ocidImgAreaArray's lastObject()
127    set ocidTempRectStr to (ocidTempRectStr's stringByReplacingOccurrencesOfString:(" \"") withString:(""))
128    set ocidImgAreaRectArray to (ocidTempRectStr's componentsSeparatedByString:(" "))
129    (ocidImageableAreaDict's setValue:(ocidImgAreaRectArray) forKey:(ocidSetKey))
130    
131  else if ((itemLine's hasPrefix:("*PaperDimension")) as boolean) then
132    set ocidPaperDimStr to (itemLine's stringByReplacingOccurrencesOfString:("*PaperDimension ") withString:(""))
133    set ocidPaperDimArray to (ocidPaperDimStr's componentsSeparatedByString:(": \""))
134    set ocidSetKey to ocidPaperDimArray's firstObject()
135    set ocidTempRectStr to ocidPaperDimArray's lastObject()
136    set ocidTempRectStr to (ocidTempRectStr's stringByReplacingOccurrencesOfString:("\"") withString:(""))
137    set ocidPaperDimensionRectArray to (ocidTempRectStr's componentsSeparatedByString:(" "))
138    (ocidPaperDimensionDict's setValue:(ocidPaperDimensionRectArray) forKey:(ocidSetKey))
139    
140  else if ((itemLine's hasPrefix:("*HWMargins")) as boolean) then
141    set ocidHWMarginsStr to (itemLine's stringByReplacingOccurrencesOfString:("*HWMargins: ") withString:(""))
142    set ocidHWMarginsArray to (ocidHWMarginsStr's componentsSeparatedByString:(" "))
143    set strHWMargins to ("HWMargins: ") as text
144    set strLeftMargins to doPtToMm(ocidHWMarginsArray's objectAtIndex:(0))
145    set strBottomMargins to doPtToMm(ocidHWMarginsArray's objectAtIndex:(1))
146    set strRightMargins to doPtToMm(ocidHWMarginsArray's objectAtIndex:(2))
147    set strTopMargins to doPtToMm(ocidHWMarginsArray's objectAtIndex:(3))
148    set strHWMargins to ("HWMargins(left bottom right top): " & strLeftMargins & "," & strBottomMargins & "," & strRightMargins & "," & strTopMargins) as text
149    
150  else if ((itemLine's hasPrefix:("*MaxMediaWidth")) as boolean) then
151    set ocidMaxMediaWidthStr to (itemLine's stringByReplacingOccurrencesOfString:("*MaxMediaWidth: ") withString:(""))
152    set ocidMaxMediaWidthStr to (ocidMaxMediaWidthStr's stringByReplacingOccurrencesOfString:("\"") withString:(""))
153    set strMaxMediaWidthStr to doPtToMm(ocidMaxMediaWidthStr)
154    set strMaxMediaWidthStr to ("MaxMediaWidth: " & strMaxMediaWidthStr) as text
155    
156  else if ((itemLine's hasPrefix:("*MaxMediaHeight")) as boolean) then
157    set ocidMaxMediaHeightStr to (itemLine's stringByReplacingOccurrencesOfString:("*MaxMediaHeight: ") withString:(""))
158    set ocidMaxMediaHeightStr to (ocidMaxMediaHeightStr's stringByReplacingOccurrencesOfString:("\"") withString:(""))
159    set strMaxMediaHeightStr to doPtToMm(ocidMaxMediaHeightStr)
160    set strMaxMediaHeightStr to ("MaxMediaHeight: " & strMaxMediaHeightStr) as text
161    set strMaxMediaSize to ("MaxMediaSize: " & strMaxMediaWidthStr & "x" & strMaxMediaHeightStr) as text
162  end if
163end repeat
164
165
166
167############################
168#
169set ocidAllKeysArray to ocidPaperDimensionDict's allKeys()
170set ocidSortedArray to ocidAllKeysArray's sortedArrayUsingSelector:("localizedStandardCompare:")
171set listAllKeysArray to ocidSortedArray as list
172#
173set strName to (name of current application) as text
174if strName is "osascript" then
175  tell application "Finder" to activate
176else
177  tell current application to activate
178end if
179###
180set strTitle to ("選んでください") as text
181set strPrompt to ("用紙名を選んでください") as text
182try
183  set listResponse to (choose from list listAllKeysArray with title strTitle with prompt strPrompt default items (item 1 of listAllKeysArray) OK button name "OK" cancel button name "キャンセル" without multiple selections allowed and empty selection allowed) as list
184on error
185  log "エラーしました"
186  return "エラーしました"
187end try
188if (item 1 of listResponse) is false then
189  return "キャンセルしましたA"
190else if (item 1 of listResponse) is "キャンセル" then
191  return "キャンセルしましたB"
192else
193  set strPaperName to (item 1 of listResponse) as text
194end if
195############################
196#
197set ocidPaperDimensionArray to (ocidPaperDimensionDict's valueForKey:(strPaperName))
198set strPaperW to doPtToMm(ocidPaperDimensionArray's objectAtIndex:(0))
199set strPaperH to doPtToMm(ocidPaperDimensionArray's objectAtIndex:(1))
200set strPaperDimension to ("PaperDimension(wh): " & strPaperW & "x" & strPaperH) as text
201
202set ocidImageableAreaArray to (ocidImageableAreaDict's valueForKey:(strPaperName))
203set strLLx to doPtToMm(ocidImageableAreaArray's objectAtIndex:(0))
204set strLLy to doPtToMm(ocidImageableAreaArray's objectAtIndex:(1))
205set strURx to doPtToMm(ocidImageableAreaArray's objectAtIndex:(2))
206set strURy to doPtToMm(ocidImageableAreaArray's objectAtIndex:(3))
207set strImageableArea to ("「lower left x 」「lower left y 」「upper right x」「upper right y」\nImageableArea: " & strLLx & "," & strLLy & "," & strURx & "," & strURy) as text
208
209#テキストを数値に変更して
210set numSetPaperWpt to (refMe's NSDecimalNumber's decimalNumberWithString:(strPaperW))'s floatValue()
211set numSetPaperHpt to (refMe's NSDecimalNumber's decimalNumberWithString:(strPaperH))'s floatValue()
212set numSetDimensionXpt to (refMe's NSDecimalNumber's decimalNumberWithString:(strLLx))'s floatValue()
213set numSetDimensionYpt to (refMe's NSDecimalNumber's decimalNumberWithString:(strLLy))'s floatValue()
214set numSetDimensionWpt to (refMe's NSDecimalNumber's decimalNumberWithString:(strURx))'s floatValue()
215set numSetDimensionHpt to (refMe's NSDecimalNumber's decimalNumberWithString:(strURy))'s floatValue()
216
217###小数点
218set appFormatter to refMe's NSNumberFormatter's alloc()'s init()
219appFormatter's setRoundingMode:(refMe's NSNumberFormatterRoundHalfUp)
220appFormatter's setNumberStyle:(refMe's NSNumberFormatterDecimalStyle)
221appFormatter's setMaximumFractionDigits:(2)
222set numSetMarginT to appFormatter's stringFromNumber:(numSetDimensionYpt)
223set numSetMarginB to appFormatter's stringFromNumber:(numSetPaperHpt - numSetDimensionHpt)
224set numSetMarginR to appFormatter's stringFromNumber:(numSetPaperWpt - numSetDimensionWpt)
225set numSetMarginL to appFormatter's stringFromNumber:(numSetDimensionXpt)
226
227set strPaperMargins to ("PaperMargins(left bottom right top): " & numSetMarginL & "," & numSetMarginB & "," & numSetMarginR & "," & numSetMarginT) as text
228
229
230############################
231#
232set strMesText to (strPaperName & "\n") as text
233set strMesText to (strMesText & strPaperDimension & "\n") as text
234set strMesText to (strMesText & strPaperMargins & "\n") as text
235set strMesText to (strMesText &  "------\n") as text
236set strMesText to (strMesText & strImageableArea & "\n") as text
237
238set strMesText to (strMesText & strHWMargins & "\n") as text
239set strMesText to (strMesText & strMaxMediaSize & "\n") as text
240
241log strMesText
242
243
244##############################
245#####ダイアログ
246##############################
247tell current application
248  set strName to name as text
249end tell
250####スクリプトメニューから実行したら
251if strName is "osascript" then
252  tell application "Finder"
253    activate
254  end tell
255else
256  tell current application
257    activate
258  end tell
259end if
260set aliasIconPath to (POSIX file "/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/PrintCore.framework/Versions/A/Resources/PrinterPool.icns") as alias
261try
262  set recordResult to (display dialog "PPD情報mm単位" with title "戻り値です" default answer strMesText buttons {"クリップボードにコピー", "キャンセル", "再実行"} default button "再実行" cancel button "キャンセル" giving up after 20 with icon aliasIconPath without hidden answer) as record
263on error
264  log "エラーしました"
265  return "エラーしました"
266end try
267if (gave up of recordResult) is true then
268  return "時間切れです"
269end if
270###自分自身を再実行
271if button returned of recordResult is "再実行" then
272  tell application "Finder"
273    set aliasPathToMe to (path to me) as alias
274  end tell
275  run script aliasPathToMe
276end if
277##############################
278#####値のコピー
279##############################
280if button returned of recordResult is "クリップボードにコピー" then
281  try
282    set strText to text returned of recordResult as text
283    ####ペーストボード宣言
284    set appPasteboard to refMe's NSPasteboard's generalPasteboard()
285    set ocidText to (refMe's NSString's stringWithString:(strText))
286    appPasteboard's clearContents()
287    appPasteboard's setString:(ocidText) forType:(refMe's NSPasteboardTypeString)
288  on error
289    tell application "Finder"
290      set the clipboard to strText as text
291    end tell
292  end try
293end if
294
295
296return
297
298to doPtToMm(argText)
299  #割り算
300  set ocidDecNo to refMe's NSDecimalNumber's alloc()'s initWithString:(argText)
301  set ocidDecPt to refMe's NSDecimalNumber's alloc()'s initWithString:("72")
302  set ocidNoDivPt to (ocidDecNo's decimalNumberByDividingBy:(ocidDecPt))
303  #掛け算
304  set ocidDecInch to refMe's NSDecimalNumber's alloc()'s initWithString:("25.4")
305  set ocidDecMM to (ocidNoDivPt's decimalNumberByMultiplyingBy:(ocidDecInch))
306  ###小数点
307  set appFormatter to refMe's NSNumberFormatter's alloc()'s init()
308  appFormatter's setRoundingMode:(refMe's NSNumberFormatterRoundHalfUp)
309  appFormatter's setNumberStyle:(refMe's NSNumberFormatterDecimalStyle)
310  appFormatter's setMaximumFractionDigits:(2)
311  set ocidMM to appFormatter's stringFromNumber:(ocidDecMM)
312  set strMM to ocidMM as text
313  return strMM
314end doPtToMm
315
316
317
318
319
320
AppleScriptで生成しました

|

[lpoptions]デフォルトプリンタ変更


AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004# com.cocolog-nifty.quicktimer.icefloe
005----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
006use AppleScript version "2.8"
007use framework "Foundation"
008use framework "AppKit"
009use framework "PrintKit"
010use framework "UniformTypeIdentifiers"
011use scripting additions
012
013property refMe : a reference to current application
014
015#############################
016set ocidPaperDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
017set appFileManager to refMe's NSFileManager's defaultManager()
018#プリンタを取得
019set ocidPrinterArray to refMe's NSPrinter's printerNames()
020set listPrinterArray to ocidPrinterArray as list
021
022#############################
023#ダイアログを前面に出す
024set strName to (name of current application) as text
025if strName is "osascript" then
026  tell application "Finder" to activate
027else
028  tell current application to activate
029end if
030###
031set strTitle to ("選んでください") as text
032set strPrompt to ("プリンタ名を選んでください") as text
033try
034  set listResponse to (choose from list listPrinterArray with title strTitle with prompt strPrompt default items (item 1 of listPrinterArray) OK button name "OK" cancel button name "キャンセル" without multiple selections allowed and empty selection allowed) as list
035on error
036  log "エラーしました"
037  return "エラーしました"
038end try
039if (item 1 of listResponse) is false then
040  return "キャンセルしましたA"
041else if (item 1 of listResponse) is "キャンセル" then
042  return "キャンセルしましたB"
043else
044  set strPrinterName to (item 1 of listResponse) as text
045end if
046
047
048#############################
049#lpoptions
050set strCommandText to ("/usr/bin/lpoptions -d \"" & strPrinterName & "\"") as text
051log strCommandText
052set strExecCommand to ("/bin/zsh -c '" & strCommandText & "'") as text
053try
054  do shell script strCommandText
055end try
056
057#############################
058#lpadmin
059set strCommandText to ("/usr/sbin/lpadmin -d \"" & strPrinterName & "\"") as text
060log strCommandText
061set strExecCommand to ("/bin/zsh -c '" & strCommandText & "'") as text
062try
063  do shell script strCommandText
064end try
065
066
067#############################
068#cupsctl プリンタ共有停止
069set strCommandText to ("/bin/zsh -c '/usr/sbin/cupsctl  --no-share-printers'") as text
070log strCommandText
071try
072  do shell script strCommandText
073end try
074#############################
075#CUPS WEBインターフェイスを有効化
076set strCommandText to ("/bin/zsh -c '/usr/sbin/cupsctl  WebInterface=YES'") as text
077log strCommandText
078try
079  do shell script strCommandText
080end try
081#############################
082#CUPSプロセスを再起動
083set strCommandText to ("/bin/zsh -c '/usr/bin/killall -HUP com.apple.PrintKit.PrinterTool'") as text
084log strCommandText
085try
086  do shell script strCommandText
087end try
088####
089set strCommandText to ("/bin/zsh -c '/usr/bin/killall -HUP PrintUITool'") as text
090log strCommandText
091try
092  # do shell script strCommandText
093end try
094####
095set strCommandText to ("/bin/zsh -c '/usr/bin/killall -HUP printtool'") as text
096log strCommandText
097try
098  do shell script strCommandText
099end try
100#############################
101#CFPreferencesを再起動
102set strCommandText to ("/bin/zsh -c '/usr/bin/killall -HUP cfprefsd'") as text
103log strCommandText
104try
105  do shell script strCommandText
106end try
107
108
109
110set strBundleID to "com.apple.systempreferences" as text
111###URLにする
112set ocidURLComponents to refMe's NSURLComponents's alloc()'s init()
113###スキーム
114ocidURLComponents's setScheme:("x-apple.systempreferences")
115###パネルIDをパスにセット
116ocidURLComponents's setPath:("com.apple.Print-Scan-Settings.extension")
117###アンカーをクエリーとして追加
118ocidURLComponents's setQuery:("print")
119set ocidOpenAppURL to ocidURLComponents's |URL|
120set strOpenAppURL to ocidOpenAppURL's absoluteString() as text
121###ワークスペースで開く
122set appShardWorkspace to refMe's NSWorkspace's sharedWorkspace()
123set boolDone to appShardWorkspace's openURL:(ocidOpenAppURL)
124log boolDone
125if boolDone is false then
126  tell application id "com.apple.systempreferences"
127    activate
128    set miniaturized of the settings window to false
129  end tell
130  tell application id "com.apple.finder"
131    open location "x-apple.systempreferences:com.apple.Print-Scan-Settings.extension?print"
132  end tell
133  tell application id "com.apple.systempreferences"
134    reveal anchor "print" of pane id "com.apple.Print-Scan-Settings.extension"
135  end tell
136  tell application id "com.apple.systempreferences" to activate
137end if
138
139
140tell application id "com.apple.printcenter" to launch
141
142tell application id "com.apple.printcenter" to activate
143
144return
AppleScriptで生成しました

|

[cupsfilter]cupsfilterを使って印刷機能でpostscriptファイルに書き出す


AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004(*
005Usage: cupsfilter [ options ] [ -- ] filename
006オプション:
007  --list-filters          使用するフィルタの一覧を表示します。
008  -D                      完了時に入力ファイルを削除します。
009  -P filename.ppd         PPDファイルを設定します。
010  -U username             ユーザ名を指定します。
011  -c cups-files.conf      使用するcups-files.confファイルを設定します。
012  -d printer              指定されたプリンタを使用します。
013  -e                      PPDファイルに含まれるすべてのフィルタを使用します。
014  -i mime/type            入力のMIMEタイプを設定します(設定しない場合はauto-typed)。
015  -j job-id[,N]           指定されたジョブからファイルNをフィルタします(デフォルトはファイル1)。
016  -m mime/type            出力のMIMEタイプを設定します(設定しない場合はapplication/pdf)。
017  -n copies               部数を設定します。
018  -o name=value           オプションを設定します。
019  -p filename.ppd         PPDファイルを設定します。
020  -t title                タイトルを設定します。
021  -u                      完了時にPPDファイルを削除します。
022*)
023#com.cocolog-nifty.quicktimer.icefloe
024----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
025##自分環境がos12なので2.8にしているだけです
026use AppleScript version "2.8"
027use framework "Foundation"
028use framework "AppKit"
029use framework "PrintKit"
030use scripting additions
031
032property refMe : a reference to current application
033set appFileManager to refMe's NSFileManager's defaultManager()
034
035#############################
036#ポストスクリプト出力先 ダウンロード
037set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDownloadsDirectory) inDomains:(refMe's NSUserDomainMask))
038set ocidDownloadsDirPathURL to ocidURLsArray's firstObject()
039set ocidSaveDirPathURL to ocidDownloadsDirPathURL's URLByAppendingPathComponent:("PostScriptPrint") isDirectory:(true)
040set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
041ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
042set listDone to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error| :(reference)
043
044#############################
045#ダイアログ
046#プリンタを取得
047set ocidPrinterArray to refMe's NSPrinter's printerNames()
048set listPrinterArray to ocidPrinterArray as list
049#
050set strName to (name of current application) as text
051if strName is "osascript" then
052  tell application "Finder" to activate
053else
054  tell current application to activate
055end if
056set strTitle to ("選んでください") as text
057set strPrompt to ("プリンタ名を選んでください") as text
058try
059  set listResponse to (choose from list listPrinterArray with title strTitle with prompt strPrompt default items (item 1 of listPrinterArray) OK button name "OK" cancel button name "キャンセル" without multiple selections allowed and empty selection allowed) as list
060on error
061  log "エラーしました"
062  return "エラーしました"
063end try
064if (item 1 of listResponse) is false then
065  return "キャンセルしましたA"
066else if (item 1 of listResponse) is "キャンセル" then
067  return "キャンセルしましたB"
068else
069  set strPrinterName to (item 1 of listResponse) as text
070end if
071##PPDパス
072set strPPDfilePath to ("/private/etc/cups/ppd/" & strPrinterName & ".ppd") as text
073
074#############################
075#ファイル
076set strName to (name of current application) as text
077if strName is "osascript" then
078  tell application "Finder" to activate
079else
080  tell current application to activate
081end if
082#
083set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
084set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
085set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
086#
087set listUTI to {"com.adobe.pdf", "public.image"}
088set strMes to ("ファイルを選んでください") as text
089set strPrompt to ("ファイルを選んでください") as text
090try
091  set aliasFilePath to (choose file strMes with prompt strPrompt default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias
092on error
093  log "エラーしました"
094  return "エラーしました"
095end try
096
097set strFilePath to (POSIX path of aliasFilePath) as text
098set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
099set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
100set strFilePath to (ocidFilePath) as text
101set ocidFileName to ocidFilePath's lastPathComponent()
102#############################
103#出力先
104set ocidSaveBaseFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(ocidFileName) isDirectory:(false)
105set ocidSaveFilePathURL to ocidSaveBaseFilePathURL's URLByAppendingPathExtension:("ps")
106set ocidSaveFilePath to ocidSaveFilePathURL's |path|
107set strSaveFilePath to ocidSaveFilePath as text
108set boolDirExists to appFileManager's fileExistsAtPath:(ocidSaveFilePath) isDirectory:(true)
109if boolDirExists = true then
110  
111  
112end if
113set ocidSaveTextFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:("_このフォルダは削除しても大丈夫です.txt") isDirectory:(false)
114set ocidTextStr to refMe's NSString's stringWithString:("このフォルダは削除しても大丈夫です")
115set listDone to ocidTextStr's writeToURL:(ocidSaveTextFilePathURL) atomically:(true) encoding:(refMe's NSUTF8StringEncoding) |error| :(reference)
116#############################
117#コマンド
118(* オプション
119-o fit-to-page
120-o orientation-requested=5  
121-o scaling=50
122-o media=A3
123*)
124set strCommandText to ("/usr/sbin/cupsfilter  -m application/postscript -n 1  -P \"" & strPPDfilePath & "\" \"" & strFilePath & "\" > \"" & strSaveFilePath & "\"  ") as text
125set strExecCommand to ("/bin/zsh -c '" & strCommandText & "'") as text
126log "\r" & strCommandText & "\r"
127try
128  do shell script strExecCommand
129end try
130
131#############################
132#
133set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
134set boolDone to appSharedWorkspace's openURL:(ocidSaveDirPathURL)
135
AppleScriptで生成しました

|

より以前の記事一覧

その他のカテゴリー

Accessibility Acrobat Acrobat 2020 Acrobat 2024 Acrobat AddOn Acrobat Annotation Acrobat AppleScript Acrobat ARMDC Acrobat AV2 Acrobat BookMark Acrobat Classic Acrobat DC Acrobat Dialog Acrobat Distiller Acrobat Form Acrobat GentechAI Acrobat JS Acrobat JS Word Search Acrobat Maintenance Acrobat Manifest Acrobat Menu Acrobat Merge Acrobat Open Acrobat PDFPage Acrobat Plugin Acrobat Preferences Acrobat Preflight Acrobat Print Acrobat Python Acrobat Reader Acrobat Reader Localized Acrobat Reference Acrobat Registered Products Acrobat SCA Acrobat SCA Updater Acrobat Sequ Acrobat Sign Acrobat Stamps Acrobat URL List Mac Acrobat URL List Windows Acrobat Watermark Acrobat Windows Acrobat Windows Reader Admin Admin Account Admin Apachectl Admin ConfigCode Admin configCode Admin Device Management Admin LaunchServices Admin Locationd Admin loginitem Admin Maintenance Admin Mobileconfig Admin NetWork Admin Permission Admin Pkg Admin Power Management Admin Printer Admin Printer Basic Admin Printer Custompapers Admin SetUp Admin SMB Admin softwareupdate Admin Support Admin System Information Admin TCC Admin Tools Admin Umask Admin Users Admin Volumes Admin XProtect Adobe Adobe AUSST Adobe Bridge Adobe Documents Adobe FDKO Adobe Fonts Adobe Reference Adobe RemoteUpdateManager Adobe Sap Code AppKit Apple AppleScript AppleScript Duplicate AppleScript entire contents AppleScript List AppleScript ObjC AppleScript Osax AppleScript PDF AppleScript Pictures AppleScript record AppleScript Video Applications AppStore Archive Archive Keka Attributes Automator BackUp Barcode Barcode Decode Barcode QR Bash Basic Basic Path Bluetooth BOX Browser Calendar CD/DVD Choose Chrome Chromedriver CIImage CityCode CloudStorage Color Color NSColor Color NSColorList com.apple.LaunchServices.OpenWith Console Contacts CotEditor CURL current application Date&Time delimiters Desktop Desktop Position Device Diff Disk do shell script Dock Dock Launchpad DropBox Droplet eMail Encode % Encode Decode Encode HTML Entity Encode UTF8 Error EXIFData exiftool ffmpeg File File Name Finder Finder Window Firefox Folder FolderAction Font List FontCollections Fonts Fonts Asset_Font Fonts ATS Fonts Emoji Fonts Maintenance Fonts Morisawa Fonts Python Fonts Variable Foxit GIF github Guide HTML Icon Icon Assets.car Illustrator Image Events ImageOptim Input Dictionary iPhone iWork Javascript Jedit Ω Json Label Language Link locationd lsappinfo m3u8 Mail Map Math Media Media AVAsset Media AVconvert Media AVFoundation Media AVURLAsset Media Movie Media Music Memo Messages Microsoft Microsoft Edge Microsoft Excel Microsoft Fonts Microsoft Office Microsoft Office Link Microsoft OneDrive Microsoft Teams Mouse Music Node Notes NSArray NSArray Sort NSAttributedString NSBezierPath NSBitmapImageRep NSBundle NSCFBoolean NSCharacterSet NSData NSDecimalNumber NSDictionary NSError NSEvent NSFileAttributes NSFileManager NSFileManager enumeratorAtURL NSFont NSFontManager NSGraphicsContext NSGraphicsContext Crop NSImage NSIndex NSKeyedArchiver NSKeyedUnarchiver NSLocale NSMetadataItem NSMutableArray NSMutableDictionary NSMutableString NSNotFound NSNumber NSOpenPanel NSPasteboard NSpoint NSPredicate NSRange NSRect NSRegularExpression NSRunningApplication NSScreen NSSet NSSize NSString NSString stringByApplyingTransform NSStringCompareOptions NSTask NSTimeZone NSUbiquitous NSURL NSURL File NSURLBookmark NSURLComponents NSURLResourceKey NSURLSession NSUserDefaults NSUUID NSView NSWorkspace Numbers OAuth PDF PDF Image2PDF PDF MakePDF PDF nUP PDF Pymupdf PDF Pypdf PDFContext PDFDisplayBox PDFImageRep PDFKit PDFKit Annotation PDFKit AnnotationWidget PDFKit DocumentPermissions PDFKit OCR PDFKit Outline PDFKit Start PDFPage PDFPage Rotation PDFView perl Photoshop PlistBuddy pluginkit plutil postalcode PostScript PowerShell prefPane Preview Python Python eyed3 Python pip QuickLook QuickTime ReadMe Regular Expression Reminders ReName Repeat RTF Safari SaveFile ScreenCapture ScreenSaver Script Editor Script Menu SF Symbols character id SF Symbols Entity Shortcuts Shortcuts Events sips Skype Slack Sound Spotlight sqlite StandardAdditions StationSearch Subtitles LRC Subtitles SRT Subtitles VTT Swift swiftDialog System Events System Settings TemporaryItems Terminal Text Text CSV Text MD Text TSV TextEdit Tools Translate Trash Twitter Typography UI Unit Conversion UTType valueForKeyPath Video VisionKit Visual Studio Code VMware Fusion Wacom Weather webarchive webp Wifi Windows XML XML EPUB XML HTML XML LSSharedFileList XML LSSharedFileList sfl2 XML LSSharedFileList sfl3 XML objectsForXQuery XML OPML XML Plist XML Plist System Events XML RSS XML savedSearch XML SVG XML TTML XML webloc XML xmllint XML XMP YouTube Zero Padding zoom