Admin Printer

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で生成しました

|

PPDに記載されている用紙サイズをカスタム用紙設定する(修正)


AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003(*
004プリンタの用紙サイズの取得してカスタム用紙設定する
005キャノン、フジとリコーのプリンタしか確認していないので
006他社のプリンタでは動作しないかもしれない
007PPDの記述方法に依存があるため
008
009接頭語をメーカー名からプリンタ名に変更
010
011Airプリントの機種は基本非対応
012com.cocolog-nifty.quicktimer.icefloe
013*)
014----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
015use AppleScript version "2.8"
016use framework "Foundation"
017use framework "AppKit"
018use framework "PrintKit"
019use scripting additions
020
021property refMe : a reference to current application
022
023############################
024#バックアップ 先
025#ユーザーの書類フォルダのにバックアップします
026set strDateno to doGetDateNo("yyyyMMdd-hhmmss") as text
027set strBackupFileName to ("com.apple.print.custompapers." & strDateno & ".plist") as text
028#保存先
029set appFileManager to refMe's NSFileManager's defaultManager()
030set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDocumentDirectory) inDomains:(refMe's NSUserDomainMask))
031set ocidDocumentDirPathURL to ocidURLsArray's firstObject()
032# ユーザーの書類/Apple/Printer/Custompapers がバックアップ先
033set ocidBackUpDirPathURL to ocidDocumentDirPathURL's URLByAppendingPathComponent:("Apple/Printer/Custompapers") isDirectory:(true)
034#フォルダ生成
035set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
036ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
037set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidBackUpDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error| :(reference)
038#パス
039set ocidBackUpFilePathURL to ocidBackUpDirPathURL's URLByAppendingPathComponent:(strBackupFileName) isDirectory:(false)
040
041############################
042#元ファイル
043set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSUserDomainMask))
044set ocidLibraryDirPathURL to ocidURLsArray's firstObject()
045set ocidPrefFilePathURL to ocidLibraryDirPathURL's URLByAppendingPathComponent:("Preferences/com.apple.print.custompapers.plist") isDirectory:(false)
046#ファイルの有無を確認
047set boolFileExists to (appFileManager's fileExistsAtPath:(ocidPrefFilePathURL's |path|()) isDirectory:false)
048if boolFileExists is true then
049  #ファイルがあるなら
050  ############################
051  #バックアップ
052  set listDone to (appFileManager's copyItemAtURL:(ocidPrefFilePathURL) toURL:(ocidBackUpFilePathURL) |error| :(reference))
053  ############################
054  #Plist読み込み NSData's
055  set ocidOption to (refMe's NSDataReadingMappedIfSafe)
056  set listReadData to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidPrefFilePathURL) options:(ocidOption) |error| :(reference)
057  set ocidPlistData to (item 1 of listReadData)
058  #DICTにする
059  set ocidXmlPlist to (refMe's NSPropertyListBinaryFormat_v1_0)
060  set appPlistSerial to refMe's NSPropertyListSerialization
061  set ocidOption to refMe's NSPropertyListMutableContainersAndLeaves
062  set listPlistDict to appPlistSerial's propertyListWithData:(ocidPlistData) options:(ocidOption) format:(ocidXmlPlist) |error| :(reference)
063  set ocidPlistDict to (item 1 of listPlistDict)
064else
065  #ファイルが無いなら
066  #空のDICTを用意する
067  set ocidPlistDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
068end if
069
070############################
071#作業エリア gz解凍 zcatは使わない
072#起動時に削除される項目内
073set ocidTempDirURL to appFileManager's temporaryDirectory()
074set ocidUUID to refMe's NSUUID's alloc()'s init()
075set ocidUUIDString to ocidUUID's UUIDString
076set ocidSaveDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:(true)
077set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
078ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
079set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error| :(reference)
080#パス
081set strFileName to "Printer.ppd" as text
082set ocidPPDFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strFileName) isDirectory:false
083set strTempFilePath to (ocidPPDFilePathURL's |path|) as text
084
085############################
086#ダイアログ
087set strName to (name of current application) as text
088if strName is "osascript" then
089  tell application "Finder" to activate
090else
091  tell current application to activate
092end if
093#ローカルドメインのプリンタPPD
094set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSLocalDomainMask))
095set ocidLibraryDirPathURL to ocidURLsArray's firstObject()
096set ocidResourcesDirPathURL to ocidLibraryDirPathURL's URLByAppendingPathComponent:("Printers/PPDs/Contents/Resources") isDirectory:(true)
097set aliasDefaultLocation to (ocidResourcesDirPathURL's absoluteURL()) as alias
098set listUTI to {"public.item"}
099set strMes to ("PPDファイルを選んでください") as text
100set strPrompt to ("PPDファイルを選んでください\n拡張子無しの場合や\ngz圧縮されている場合があります") as text
101try
102  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
103on error
104  log "エラーしました"
105  return "エラーしました"
106end try
107############################
108#元になるPPD
109set strChooseFilePath to (POSIX path of aliasChooseFilePath) as text
110set ocidChooseFilePathStr to refMe's NSString's stringWithString:(strChooseFilePath)
111set ocidChooseFilePath to ocidChooseFilePathStr's stringByStandardizingPath()
112set ocidChooseFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(ocidChooseFilePath) isDirectory:(false)
113set strChooseExtensionName to (ocidChooseFilePathURL's pathExtension()) as text
114#gzなら解凍
115if strChooseExtensionName is "gz" then
116  set strCommandText to ("/bin/zsh -c '/usr/bin/gunzip -c  \"" & strChooseFilePath & "\" > \"" & strTempFilePath & "\"'") as text
117  log strCommandText
118  try
119    do shell script strCommandText
120  end try
121else
122  #gz以外ならそのまま利用
123  set strCommandText to ("/bin/zsh -c '/usr/bin/ditto \"" & strChooseFilePath & "\"  \"" & strTempFilePath & "\"'") as text
124  log strCommandText
125  try
126    do shell script strCommandText
127  end try
128end if
129
130############################
131#PPDを読み込む NSDATA
132set ocidOption to (refMe's NSDataReadingMappedIfSafe)
133set listResponse to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidPPDFilePathURL) options:(ocidOption) |error| :(reference)
134if (item 2 of listResponse) = (missing value) then
135  log "正常処理"
136  set ocidReadData to (item 1 of listResponse)
137else if (item 2 of listResponse) ≠ (missing value) then
138  set strErrorNO to (item 2 of listResponse)'s code() as text
139  set strErrorMes to (item 2 of listResponse)'s localizedDescription() as text
140  refMe's NSLog("■:" & strErrorNO & strErrorMes)
141  return "エラーしました" & strErrorNO & strErrorMes
142end if
143
144############################
145#テキストにする NSString's
146set ocidReadStrings to refMe's NSString's alloc()'s initWithData:(ocidReadData) encoding:(refMe's NSUTF8StringEncoding)
147#ここまでのデータをクリアしておく
148set ocidReadData to (missing value)
149#改行をUNIXに強制
150set ocidReadStringsTMP to (ocidReadStrings's stringByReplacingOccurrencesOfString:("\n\r") withString:("\n"))
151set ocidReadStringsTMP to (ocidReadStringsTMP's stringByReplacingOccurrencesOfString:("\r") withString:("\n"))
152set ocidReadStrings to (ocidReadStringsTMP's stringByReplacingOccurrencesOfString:("\n\n") withString:("\n"))
153
154############################
155#リストArrayでの処理
156#改行でリストにする
157set ocidReadStringsArray to ocidReadStrings's componentsSeparatedByString:("\n")
158#ここまでのデータをクリアしておく
159set ocidReadStrings to (missing value)
160#必要な行のテキストを格納する
161set ocidImageableAreaStr to refMe's NSMutableString's alloc()'s initWithCapacity:(0)
162set ocidPaperDimensionStr to refMe's NSMutableString's alloc()'s initWithCapacity:(0)
163#
164set ocidHWMarginsStr to refMe's NSMutableString's alloc()'s initWithCapacity:(0)
165set ocidNickNameStr to refMe's NSMutableString's alloc()'s initWithCapacity:(0)
166set ocidShortNickNameStr to refMe's NSMutableString's alloc()'s initWithCapacity:(0)
167set ocidModelNameStr to refMe's NSMutableString's alloc()'s initWithCapacity:(0)
168set ocidManufacturerStr to refMe's NSMutableString's alloc()'s initWithCapacity:(0)
169set ocidProductStr to refMe's NSMutableString's alloc()'s initWithCapacity:(0)
170
171#全行チェック
172repeat with itemLine in ocidReadStringsArray
173  if ((itemLine's hasPrefix:("*ImageableArea")) as boolean) then
174    (ocidImageableAreaStr's appendString:(itemLine))
175    (ocidImageableAreaStr's appendString:("\n"))
176  else if ((itemLine's hasPrefix:("*PaperDimension")) as boolean) then
177    (ocidPaperDimensionStr's appendString:(itemLine))
178    (ocidPaperDimensionStr's appendString:("\n"))
179  else if ((itemLine's hasPrefix:("*HWMargins")) as boolean) then
180    (ocidHWMarginsStr's appendString:(itemLine))
181  else if ((itemLine's hasPrefix:("*NickName:")) as boolean) then
182    (ocidNickNameStr's appendString:(itemLine))
183  else if ((itemLine's hasPrefix:("*ShortNickName:")) as boolean) then
184    (ocidShortNickNameStr's appendString:(itemLine))
185  else if ((itemLine's hasPrefix:("*ModelName:")) as boolean) then
186    (ocidModelNameStr's appendString:(itemLine))
187  else if ((itemLine's hasPrefix:("*Manufacturer:")) as boolean) then
188    set itemLine to (itemLine's stringByReplacingOccurrencesOfString:("\"") withString:(""))
189    (ocidManufacturerStr's appendString:(itemLine))
190  else if ((itemLine's hasPrefix:("*Product:")) as boolean) then
191    (ocidProductStr's appendString:(itemLine))
192  end if
193end repeat
194#ここまでのデータをクリアしておく
195set ocidReadStringsArray to (missing value)
196################################
197#収集した行データの処理 Product
198set ocidProductStr to (ocidProductStr's stringByReplacingOccurrencesOfString:("*Product: ") withString:(""))
199set ocidProductStr to (ocidProductStr's stringByReplacingOccurrencesOfString:("\"") withString:(""))
200set ocidProductStr to (ocidProductStr's stringByReplacingOccurrencesOfString:("(") withString:(""))
201set ocidProductStr to (ocidProductStr's stringByReplacingOccurrencesOfString:(")") withString:(""))
202set ocidProductStr to (ocidProductStr's stringByReplacingOccurrencesOfString:(" ") withString:(""))
203set strProductStr to ocidProductStr as text
204
205################################
206#収集した行データの処理 HWMargins
207set ocidHWMarginsStr to (ocidHWMarginsStr's stringByReplacingOccurrencesOfString:("*HWMargins: ") withString:(""))
208
209################################
210#収集した行データの処理 NickName
211set ocidNickNameStr to (ocidNickNameStr's stringByReplacingOccurrencesOfString:("*NickName: ") withString:(""))
212
213################################
214#収集した行データの処理 ShortNickName
215set ocidShortNickNameStr to (ocidShortNickNameStr's stringByReplacingOccurrencesOfString:("*ShortNickName: ") withString:(""))
216
217################################
218#収集した行データの処理 ModelName
219set ocidModelNameStr to (ocidModelNameStr's stringByReplacingOccurrencesOfString:("*ModelName: ") withString:(""))
220
221################################
222#収集した行データの処理 Manufacturer
223set strManufacturerStr to (ocidManufacturerStr's stringByReplacingOccurrencesOfString:("*Manufacturer: ") withString:("")) as text
224
225################################
226#収集した行データの処理 ocidImageableAreaStr
227set ocidImageableAreaDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
228set ocidImageableAreaArray to ocidImageableAreaStr's componentsSeparatedByString:("\n")
229#最後の改行分を削除
230ocidImageableAreaArray's removeLastObject()
231#Arrayの内容を順番に処理
232repeat with itemImgArea in ocidImageableAreaArray
233  set itemImgArea to (itemImgArea's stringByReplacingOccurrencesOfString:("*ImageableArea ") withString:(""))
234  set itemImgAreaArray to (itemImgArea's componentsSeparatedByString:(": \""))
235  set ocidSetKey to itemImgAreaArray's firstObject()
236  set ocidTempRectStr to itemImgAreaArray's lastObject()
237  set ocidTempRectStr to (ocidTempRectStr's stringByReplacingOccurrencesOfString:(" \"") withString:(""))
238  set ocidImgAreaRectArray to (ocidTempRectStr's componentsSeparatedByString:(" "))
239  (ocidImageableAreaDict's setValue:(ocidImgAreaRectArray) forKey:(ocidSetKey))
240end repeat
241#ここまでのデータをクリアしておく
242set ocidImageableAreaStr to (missing value)
243
244################################
245#収集した行データの処理 PaperDimension
246set ocidPaperDimensionDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
247set ocidPaperDimensionArray to ocidPaperDimensionStr's componentsSeparatedByString:("\n")
248#最後の改行分を削除
249ocidPaperDimensionArray's removeLastObject()
250#Arrayの内容を順番に処理
251repeat with itemPaperDim in ocidPaperDimensionArray
252  set itemPaperDim to (itemPaperDim's stringByReplacingOccurrencesOfString:("*PaperDimension ") withString:(""))
253  set itemPaperDimArray to (itemPaperDim's componentsSeparatedByString:(": \""))
254  set ocidSetKey to itemPaperDimArray's firstObject()
255  set ocidTempRectStr to itemPaperDimArray's lastObject()
256  set ocidTempRectStr to (ocidTempRectStr's stringByReplacingOccurrencesOfString:("\"") withString:(""))
257  set ocidPaperDimensionRectArray to (ocidTempRectStr's componentsSeparatedByString:(" "))
258  (ocidPaperDimensionDict's setValue:(ocidPaperDimensionRectArray) forKey:(ocidSetKey))
259end repeat
260#ここまでのデータをクリアしておく
261set ocidPaperDimensionStr to (missing value)
262
263################################
264#必要な値を生成していく
265#log ocidImageableAreaDict's allKeys()'s |count|() as integer
266#キーを取り出して
267set ocidDimensionDictAllKeys to ocidPaperDimensionDict's allKeys()
268#順番に処理する
269repeat with itemKey in ocidDimensionDictAllKeys
270  #紙名はメーカー名+紙の名前
271  set strSetPaperName to (strProductStr & "-" & itemKey) as text
272  #データを取り出す この段階ではテキスト形式
273  set boolCustom to true as boolean
274  set itemPaperDimensionArray to (ocidPaperDimensionDict's objectForKey:(itemKey))
275  set strSetPaperWpt to itemPaperDimensionArray's firstObject()
276  set strSetPaperHpt to itemPaperDimensionArray's lastObject()
277  set itemImageableAreaArray to (ocidImageableAreaDict's objectForKey:(itemKey))
278  set strSetDimensionXpt to itemImageableAreaArray's firstObject()
279  set strSetDimensionYpt to (itemImageableAreaArray's objectAtIndex:(1))
280  set strSetDimensionWpt to (itemImageableAreaArray's objectAtIndex:(2))
281  set strSetDimensionHpt to itemImageableAreaArray's lastObject()
282  #テキストを数値に変更して
283  set numSetPaperWpt to (refMe's NSDecimalNumber's decimalNumberWithString:(strSetPaperWpt))'s floatValue()
284  set numSetPaperHpt to (refMe's NSDecimalNumber's decimalNumberWithString:(strSetPaperHpt))'s floatValue()
285  set numSetDimensionXpt to (refMe's NSDecimalNumber's decimalNumberWithString:(strSetDimensionXpt))'s floatValue()
286  set numSetDimensionYpt to (refMe's NSDecimalNumber's decimalNumberWithString:(strSetDimensionYpt))'s floatValue()
287  set numSetDimensionWpt to (refMe's NSDecimalNumber's decimalNumberWithString:(strSetDimensionWpt))'s floatValue()
288  set numSetDimensionHpt to (refMe's NSDecimalNumber's decimalNumberWithString:(strSetDimensionHpt))'s floatValue()
289  #余白 margin計算
290  #天地上向で 左下 と 右上のxy
291  set numSetMarginT to numSetDimensionYpt
292  set numSetMarginB to (numSetPaperHpt - numSetDimensionHpt)
293  set numSetMarginR to (numSetPaperWpt - numSetDimensionWpt)
294  set numSetMarginL to numSetDimensionXpt
295  #紙単位でセットするDICT
296  set ocidSetDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
297  #各値をDICTにセットしていく
298  (ocidSetDict's setValue:(strSetPaperName) forKey:("id"))
299  (ocidSetDict's setValue:(strSetPaperName) forKey:("name"))
300  (ocidSetDict's setValue:(boolCustom) forKey:("custom"))
301  (ocidSetDict's setValue:("") forKey:("printer"))
302  #
303  (ocidSetDict's setValue:(numSetMarginT) forKey:("top"))
304  (ocidSetDict's setValue:(numSetMarginB) forKey:("bottom"))
305  (ocidSetDict's setValue:(numSetMarginL) forKey:("left"))
306  (ocidSetDict's setValue:(numSetMarginR) forKey:("right"))
307  #
308  (ocidSetDict's setValue:(numSetPaperWpt) forKey:("width"))
309  (ocidSetDict's setValue:(numSetPaperHpt) forKey:("height"))
310  #値をセットしたDICTをPLISTのDICTにセットする
311  (ocidPlistDict's setObject:(ocidSetDict) forKey:(strSetPaperName))
312end repeat
313
314#ここまでのデータをクリアしておく
315set ocidImageableAreaDict to (missing value)
316set ocidImageableAreaArray to (missing value)
317set ocidPaperDimensionDict to (missing value)
318set ocidPaperDimensionArray to (missing value)
319set ocidPaperNameDict to (missing value)
320set ocidPaperNameArray to (missing value)
321################################
322#保存
323#DICTをPLISTに変換
324set ocidFormat to (refMe's NSPropertyListBinaryFormat_v1_0)
325set listResponse to refMe's NSPropertyListSerialization's dataWithPropertyList:(ocidPlistDict) format:(ocidFormat) options:0  |error| :(reference)
326set ocidPlistData to (item 1 of listResponse)
327#保存 
328set ocidOption to (refMe's NSDataWritingAtomic)
329set listDone to ocidPlistData's writeToURL:(ocidPrefFilePathURL) options:(ocidOption) |error| :(reference)
330if (item 1 of listDone) is true then
331  log "正常終了"
332else if (item 1 of listDone) is false then
333  return "保存に失敗しました"
334end if
335
336
337
338########################
339#CUPS WEBUIを利用可能に
340try
341  set theComandText to ("/usr/sbin/cupsctl  WebInterface=YES") as text
342  do shell script theComandText
343end try
344########################
345#保存先がPreferencesの場合
346##USBリバインド
347do shell script "/System/Library/SystemConfiguration/PrinterNotifications.bundle/Contents/MacOS/makequeues -r"
348##Update printer module cache
349try
350  do shell script "/System/Library/SystemConfiguration/PrinterNotifications.bundle/Contents/MacOS/makequeues -u"
351end try
352##Update PPD based queues
353do shell script "/System/Library/SystemConfiguration/PrinterNotifications.bundle/Contents/MacOS/makequeues -h"
354##LPDリバインド
355do shell script "/System/Library/SystemConfiguration/PrinterNotifications.bundle/Contents/MacOS/makequeues -k lpd"
356##IPPリバインド
357do shell script "/System/Library/SystemConfiguration/PrinterNotifications.bundle/Contents/MacOS/makequeues -k ipp"
358
359#############################
360#CFPreferencesを再起動
361set strCommandText to ("/bin/zsh -c '/usr/bin/killall -HUP cfprefsd'") as text
362log strCommandText
363try
364  do shell script strCommandText
365end try
366
367#############################
368#CUPSプロセスを再起動
369set strCommandText to ("/bin/zsh -c '/usr/bin/killall -HUP com.apple.PrintKit.PrinterTool'") as text
370log strCommandText
371try
372  do shell script strCommandText
373end try
374####
375set strCommandText to ("/bin/zsh -c '/usr/bin/killall -HUP PrintUITool'") as text
376log strCommandText
377try
378  do shell script strCommandText
379end try
380####
381set strCommandText to ("/bin/zsh -c '/usr/bin/killall -HUP printtool'") as text
382log strCommandText
383try
384  do shell script strCommandText
385end try
386####
387set strCommandText to ("/bin/zsh -c '/usr/bin/killall -HUP distnoted'") as text
388log strCommandText
389try
390  do shell script strCommandText
391end try
392####
393set strCommandText to ("/bin/zsh -c '/usr/bin/killall -HUP sharedfilelistd'") as text
394log strCommandText
395try
396  do shell script strCommandText
397end try
398
399
400
401#############################
402#プリントセンター開く
403tell application id "com.apple.printcenter" to launch
404delay 1
405tell application id "com.apple.printcenter" to activate
406
407
408#############################
409#プリンタパネルを開く
410tell application id "com.apple.systempreferences" to quit
411delay 1
412set appWorkspace to refMe's NSWorkspace's sharedWorkspace()
413set ocidOpenURL to refMe's NSURL's URLWithString:"x-apple.systempreferences:com.apple.Print-Scan-Settings.extension"
414appWorkspace's openURL:ocidOpenURL
415
416
417return
418
419########################
420#日付取得サブ
421to doGetDateNo(strDateFormat)
422  ####日付情報の取得
423  set ocidDate to current application's NSDate's |date|()
424  ###日付のフォーマットを定義
425  set ocidNSDateFormatter to current application's NSDateFormatter's alloc()'s init()
426  ocidNSDateFormatter's setLocale:(current application's NSLocale's localeWithLocaleIdentifier:"ja_JP_POSIX")
427  ocidNSDateFormatter's setDateFormat:strDateFormat
428  set ocidDateAndTime to ocidNSDateFormatter's stringFromDate:ocidDate
429  set strDateAndTime to ocidDateAndTime as text
430  return strDateAndTime
431end doGetDateNo
432
433
AppleScriptで生成しました

|

[makequeues] makequeuesを使ってプリンターを設定する(少し治し)サンプル AcrobatPsPrinter設定


AppleScript サンプルコード

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

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

|

[CUPS]スプールされたジョブデータの取り出し macOS15対応 修正


AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004(*
005/usr/sbin/lpmove
006/usr/sbin/lpinfo
007/usr/sbin/lpc
008/usr/sbin/lpadmin
009/usr/bin/lpstat
010/usr/bin/lprm
011/usr/bin/lpr
012/usr/bin/lpq
013/usr/bin/lpoptions
014/usr/bin/lp
015
016macOS15 Sequoia専用
017CUPS 2.3.4対応
018CUPSコマンドジョブの取り出しに対応
019*)
020# 要管理者権限
021# ジョブの削除とリロードの選択肢を追加
022#com.cocolog-nifty.quicktimer.icefloe
023----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
024use AppleScript version "2.8"
025use framework "Foundation"
026use framework "AppKit"
027use scripting additions
028
029property refMe : a reference to current application
030
031
032###WEBUIを有効にする
033set strCommandText to ("/bin/zsh -c '/usr/sbin/cupsctl WebInterface=yes'") as string
034log strCommandText
035try
036  set strPrintQStr to (do shell script strCommandText) as string
037on error
038  return "cupsctlでエラーしました"
039end try
040
041#####UIDショートユーザー名
042set ocidUserName to refMe's NSUserName()
043set strShortUserName to ocidUserName as string
044###ジョブ(キュー)の一覧を取得する
045set strCommandText to ("/bin/zsh -c '/usr/bin/lpq  -alE -U " & strShortUserName & "'") as string
046log strCommandText
047try
048  set strPrintQStr to (do shell script strCommandText) as string
049on error
050  return "lpqでエラーしました"
051end try
052if strPrintQStr is "エントリーがありません" then
053  display alert "エントリーがありません" message "スプールJOBデータ無し"
054  return "スプールデータ無し"
055end if
056log strPrintQStr
057####コマンドの戻り値からリストを作成
058set ocidOrgStrings to refMe's NSString's stringWithString:(strPrintQStr)
059set ocidPrintQStr to (ocidOrgStrings's stringByReplacingOccurrencesOfString:("\r\r") withString:("\r"))
060set ocidPrintQStr to (ocidPrintQStr's stringByReplacingOccurrencesOfString:("]\r") withString:("]"))
061set ocidPrintQStr to (ocidPrintQStr's stringByReplacingOccurrencesOfString:("\r\r") withString:("\r"))
062#リストにして
063set ocidTextNSArray to ocidPrintQStr's componentsSeparatedByString:("\r")
064set ocidPrintQArray to refMe's NSMutableArray's alloc()'s initWithCapacity:0
065ocidPrintQArray's addObjectsFromArray:ocidTextNSArray
066ocidPrintQArray's removeObjectAtIndex:0
067set listPrintQArray to ocidPrintQArray as list
068#
069set strSetRest to ("ResetJob     全ジョブ削除") as text
070copy strSetRest to end of listPrintQArray
071set strSetRest to ("ReloadJob     リスト更新 ") as text
072copy strSetRest to end of listPrintQArray
073
074try
075  set listResponse to (choose from list listPrintQArray with title "選んでください" with prompt "取り出すJOBを選んでください\rResetJobで全ジョブ削除\rReloadJobでジョブリストを更新します\r【留意事項】管理者権限が必要です" default items (item 1 of listPrintQArray) OK button name "OK" cancel button name "キャンセル" without multiple selections allowed and empty selection allowed)
076on error
077  log "エラーしました"
078  return "エラーしました"
079end try
080if listResponse is false then
081  return "キャンセルしました"
082end if
083#ダイアログの戻り値
084set strResponse to (item 1 of listResponse) as text
085#キャンセル ジョブ全削除
086if strResponse contains "ResetJob" then
087  set strCommandText to ("/usr/bin/cancel -a -x")
088  set ocidAppName to refMe's NSString's stringWithString:strCommandText
089  set ocidTermTask to refMe's NSTask's alloc()'s init()
090  ocidTermTask's setLaunchPath:"/bin/zsh"
091  ocidTermTask's setArguments:({"-c", ocidAppName})
092  set listDoneReturn to ocidTermTask's launchAndReturnError:(reference)
093  ##自分自信を再実行
094  tell application "Finder"
095    set aliasPathToMe to (path to me) as alias
096  end tell
097  run script aliasPathToMe with parameters "再実行"
098  return
099  #再度実行を選んだら
100else if strResponse contains "ReloadJob" then
101  ##自分自信を再実行
102  tell application "Finder"
103    set aliasPathToMe to (path to me) as alias
104  end tell
105  run script aliasPathToMe with parameters "再実行"
106  return
107  
108end if
109#戻り値からジョブ番号を取得する
110set ocidResponse to refMe's NSMutableString's alloc()'s initWithCapacity:0
111ocidResponse's setString:(strResponse)
112##他に方法ありそうな気もするけど…いったんスペースでArrayにして
113set ocidResponseArray to ocidResponse's componentsSeparatedByString:("ジョブ")
114set ocidLastArray to ocidResponseArray's lastObject()
115set ocidJobArray to ocidLastArray's componentsSeparatedByString:(" ")
116set strJobNo to ocidJobArray's firstObject() as text
117##スプールフォルダをアクセスできるようにして
118try
119  set strCommandText to ("/bin/zsh -c '/usr/bin/sudo /bin/chmod 777 /private/var/spool/cups'") as text
120  log strCommandText
121  do shell script strCommandText
122on error
123  return "スプールにアクセスできませんした /bin/chmod 777"
124end try
125###ファイル名整形 ジョブ番号にする
126set strZeroAppend to "d00000" & strJobNo as text
127set strFileNo to "d" & (text -5 through -1 of strZeroAppend) & "-001" as text
128set strJobPath to ("/private/var/spool/cups/" & strFileNo & "") as text
129(*
130set strFilePath to POSIX path of strJobPath
131set ocidFilePathStr to (refMe's NSString's stringWithString:strFilePath)
132set ocidFilePath to ocidFilePathStr's stringByStandardizingPath
133set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false)
134set listResults to ocidFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLTypeIdentifierKey) |error| :(reference)
135set strUTI to item 1 of listResults as text
136*)
137##ジョブファイルをアクセス権つける
138set strCommandText to ("/bin/zsh -c '/usr/bin/sudo /bin/chmod 640 \"" & strJobPath & "\"'") as text
139log strCommandText
140try
141  do shell script strCommandText
142on error
143  return "アクセス権戻しchmod 640でエラー"
144end try
145##PSファイルなのか? PDFデータなのか?を確認
146set strCommandText to "/bin/zsh -c '/usr/bin/sudo /usr/bin/file -b --mime-type \"" & strJobPath & "\"'"
147log strCommandText
148try
149  set strMimeType to (do shell script strCommandText) as text
150on error
151  return "mime-type取得でエラー"
152end try
153log strMimeType
154##mimeの戻り値で拡張子を設定
155if strMimeType contains "postscript" then
156  set strSaveFilePath to "~/Desktop/" & strFileNo & ".ps" as text
157else if strMimeType contains "pdf" then
158  set strSaveFilePath to "~/Desktop/" & strFileNo & ".pdf" as text
159else if strMimeType contains "text" then
160  set strSaveFilePath to "~/Desktop/" & strFileNo & ".txt" as text
161end if
162##パスにして
163set ocidSaveFilePathStr to refMe's NSString's stringWithString:(strSaveFilePath)
164set ocidSaveFilePath to ocidSaveFilePathStr's stringByStandardizingPath()
165set strSaveFilePath to ocidSaveFilePath as text
166
167##ジョブファイルのアクセス権収集
168# グループがLPグループなのでフルアクセス権をつける
169set strCommandText to ("/bin/zsh -c '/usr/bin/sudo /bin/chmod 644 \"" & strJobPath & "\"'") as text
170log strCommandText
171try
172  do shell script strCommandText
173on error
174  return "chmod strJobPathでエラー"
175end try
176##デスクトップにコピー
177set strCommandText to ("/bin/zsh -c '/usr/bin/ditto  \"" & strJobPath & "\"   \"" & strSaveFilePath & "\"'") as text
178log strCommandText
179try
180  do shell script strCommandText
181on error
182  return "dittoでエラー"
183end try
184
185
186
187
188#スプールフォルダのアクセス権を戻す
189set strCommandText to ("/bin/zsh -c '/usr/bin/sudo /bin/chmod 750 /private/var/spool/cups'") as text
190log strCommandText
191try
192  do shell script strCommandText
193on error
194  return "chmod cupsでエラー"
195end try
196
197##自分自信を再実行
198tell application "Finder"
199  set aliasPathToMe to (path to me) as alias
200end tell
201run script aliasPathToMe with parameters "再実行"
AppleScriptで生成しました

|

PPDからカスタム用紙設定を生成して現在のカスタム用紙設定に追加する


AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003(*
004プリンタの用紙サイズの取得してカスタム用紙設定する
005キャノン、フジとリコーのプリンタしか確認していないので
006他社のプリンタでは動作しないかもしれない
007PPDの記述方法に依存があるため
008com.cocolog-nifty.quicktimer.icefloe
009*)
010----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
011use AppleScript version "2.8"
012use framework "Foundation"
013use framework "AppKit"
014use framework "PrintKit"
015use scripting additions
016
017property refMe : a reference to current application
018
019############################
020#バックアップ 先
021set strDateno to doGetDateNo("yyyyMMdd-hhmmss") as text
022set strBackupFileName to ("com.apple.print.custompapers." & strDateno & ".plist") as text
023#保存先
024set appFileManager to refMe's NSFileManager's defaultManager()
025set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDocumentDirectory) inDomains:(refMe's NSUserDomainMask))
026set ocidDocumentDirPathURL to ocidURLsArray's firstObject()
027set ocidBackUpDirPathURL to ocidDocumentDirPathURL's URLByAppendingPathComponent:("Apple/Printer/Custompapers") isDirectory:(true)
028#
029set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
030ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
031set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidBackUpDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error| :(reference)
032#
033set ocidBackUpFilePathURL to ocidBackUpDirPathURL's URLByAppendingPathComponent:(strBackupFileName) isDirectory:(false)
034
035############################
036#元ファイル
037set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSUserDomainMask))
038set ocidLibraryDirPathURL to ocidURLsArray's firstObject()
039set ocidPrefFilePathURL to ocidLibraryDirPathURL's URLByAppendingPathComponent:("Preferences/com.apple.print.custompapers.plist") isDirectory:(false)
040
041############################
042#バックアップ
043set listDone to (appFileManager's copyItemAtURL:(ocidPrefFilePathURL) toURL:(ocidBackUpFilePathURL) |error| :(reference))
044
045############################
046#Plist読み込み NSData's
047set ocidOption to (refMe's NSDataReadingMappedIfSafe)
048set listReadData to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidPrefFilePathURL) options:(ocidOption) |error| :(reference)
049set ocidPlistData to (item 1 of listReadData)
050#DICTにする
051set ocidXmlPlist to (refMe's NSPropertyListBinaryFormat_v1_0)
052set appPlistSerial to refMe's NSPropertyListSerialization
053set ocidOption to refMe's NSPropertyListMutableContainersAndLeaves
054set listPlistDict to appPlistSerial's propertyListWithData:(ocidPlistData) options:(ocidOption) format:(ocidXmlPlist) |error| :(reference)
055set ocidPlistDict to (item 1 of listPlistDict)
056
057
058############################
059#作業エリア
060set ocidTempDirURL to appFileManager's temporaryDirectory()
061set ocidUUID to refMe's NSUUID's alloc()'s init()
062set ocidUUIDString to ocidUUID's UUIDString
063set ocidSaveDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:(true)
064set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
065ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
066set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error| :(reference)
067#パス
068set strFileName to "Printer.ppd" as text
069set ocidPPDFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strFileName) isDirectory:false
070set strTempFilePath to (ocidPPDFilePathURL's |path|) as text
071
072############################
073#ダイアログ
074set strName to (name of current application) as text
075if strName is "osascript" then
076  tell application "Finder" to activate
077else
078  tell current application to activate
079end if
080set appFileManager to refMe's NSFileManager's defaultManager()
081set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSLocalDomainMask))
082set ocidLibraryDirPathURL to ocidURLsArray's firstObject()
083set ocidResourcesDirPathURL to ocidLibraryDirPathURL's URLByAppendingPathComponent:("Printers/PPDs/Contents/Resources") isDirectory:(true)
084set aliasDefaultLocation to (ocidResourcesDirPathURL's absoluteURL()) as alias
085set listUTI to {"public.item"}
086set strMes to ("PPDファイルを選んでください") as text
087set strPrompt to ("PPDファイルを選んでください\n拡張子無しの場合や\ngz圧縮されている場合があります") as text
088try
089  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
090on error
091  log "エラーしました"
092  return "エラーしました"
093end try
094############################
095#元になるPPD
096set strChooseFilePath to (POSIX path of aliasChooseFilePath) as text
097set ocidChooseFilePathStr to refMe's NSString's stringWithString:(strChooseFilePath)
098set ocidChooseFilePath to ocidChooseFilePathStr's stringByStandardizingPath()
099set ocidChooseFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(ocidChooseFilePath) isDirectory:(false)
100set strChooseExtensionName to (ocidChooseFilePathURL's pathExtension()) as text
101if strChooseExtensionName is "gz" then
102  set strCommandText to ("/bin/zsh -c '/usr/bin/gunzip -c  \"" & strChooseFilePath & "\" > \"" & strTempFilePath & "\"'") as text
103  log strCommandText
104  try
105    do shell script strCommandText
106  end try
107else
108  set strCommandText to ("/bin/zsh -c '/usr/bin/ditto \"" & strChooseFilePath & "\"  \"" & strTempFilePath & "\"'") as text
109  log strCommandText
110  try
111    do shell script strCommandText
112  end try
113end if
114
115############################
116#PPDを読み込む NSDATA
117set ocidOption to (refMe's NSDataReadingMappedIfSafe)
118set listResponse to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidPPDFilePathURL) options:(ocidOption) |error| :(reference)
119if (item 2 of listResponse) = (missing value) then
120  log "正常処理"
121  set ocidReadData to (item 1 of listResponse)
122else if (item 2 of listResponse) ≠ (missing value) then
123  set strErrorNO to (item 2 of listResponse)'s code() as text
124  set strErrorMes to (item 2 of listResponse)'s localizedDescription() as text
125  refMe's NSLog("■:" & strErrorNO & strErrorMes)
126  return "エラーしました" & strErrorNO & strErrorMes
127end if
128
129############################
130#テキストにする NSString's
131set ocidReadStrings to refMe's NSString's alloc()'s initWithData:(ocidReadData) encoding:(refMe's NSUTF8StringEncoding)
132#ここまでのデータをクリアしておく
133set ocidReadData to (missing value)
134#改行をUNIXに強制
135set ocidReadStringsTMP to (ocidReadStrings's stringByReplacingOccurrencesOfString:("\n\r") withString:("\n"))
136set ocidReadStringsTMP to (ocidReadStringsTMP's stringByReplacingOccurrencesOfString:("\r") withString:("\n"))
137set ocidReadStrings to (ocidReadStringsTMP's stringByReplacingOccurrencesOfString:("\n\n") withString:("\n"))
138
139############################
140#リストArrayでの処理
141#改行でリストにする
142set ocidReadStringsArray to ocidReadStrings's componentsSeparatedByString:("\n")
143#ここまでのデータをクリアしておく
144set ocidReadStrings to (missing value)
145#必要な行のテキストを格納する
146set ocidImageableAreaStr to refMe's NSMutableString's alloc()'s initWithCapacity:(0)
147set ocidPaperDimensionStr to refMe's NSMutableString's alloc()'s initWithCapacity:(0)
148#
149set ocidHWMarginsStr to refMe's NSMutableString's alloc()'s initWithCapacity:(0)
150set ocidNickNameStr to refMe's NSMutableString's alloc()'s initWithCapacity:(0)
151set ocidShortNickNameStr to refMe's NSMutableString's alloc()'s initWithCapacity:(0)
152set ocidModelNameStr to refMe's NSMutableString's alloc()'s initWithCapacity:(0)
153set ocidManufacturerStr to refMe's NSMutableString's alloc()'s initWithCapacity:(0)
154#全行チェック
155repeat with itemLine in ocidReadStringsArray
156  if ((itemLine's hasPrefix:("*ImageableArea")) as boolean) then
157    (ocidImageableAreaStr's appendString:(itemLine))
158    (ocidImageableAreaStr's appendString:("\n"))
159  else if ((itemLine's hasPrefix:("*PaperDimension")) as boolean) then
160    (ocidPaperDimensionStr's appendString:(itemLine))
161    (ocidPaperDimensionStr's appendString:("\n"))
162  else if ((itemLine's hasPrefix:("*HWMargins")) as boolean) then
163    (ocidHWMarginsStr's appendString:(itemLine))
164  else if ((itemLine's hasPrefix:("*NickName:")) as boolean) then
165    (ocidNickNameStr's appendString:(itemLine))
166  else if ((itemLine's hasPrefix:("*ShortNickName:")) as boolean) then
167    (ocidShortNickNameStr's appendString:(itemLine))
168  else if ((itemLine's hasPrefix:("*ModelName:")) as boolean) then
169    (ocidModelNameStr's appendString:(itemLine))
170  else if ((itemLine's hasPrefix:("*Manufacturer:")) as boolean) then
171    set itemLine to (itemLine's stringByReplacingOccurrencesOfString:("\"") withString:(""))
172    (ocidManufacturerStr's appendString:(itemLine))
173  end if
174end repeat
175#ここまでのデータをクリアしておく
176set ocidReadStringsArray to (missing value)
177
178################################
179#収集した行データの処理 HWMargins
180set ocidHWMarginsStr to (ocidHWMarginsStr's stringByReplacingOccurrencesOfString:("*HWMargins: ") withString:(""))
181################################
182#収集した行データの処理 NickName
183set ocidNickNameStr to (ocidNickNameStr's stringByReplacingOccurrencesOfString:("*NickName: ") withString:(""))
184################################
185#収集した行データの処理 ShortNickName
186set ocidShortNickNameStr to (ocidShortNickNameStr's stringByReplacingOccurrencesOfString:("*ShortNickName: ") withString:(""))
187################################
188#収集した行データの処理 ModelName
189set ocidModelNameStr to (ocidModelNameStr's stringByReplacingOccurrencesOfString:("*ModelName: ") withString:(""))
190################################
191#収集した行データの処理 Manufacturer
192set strManufacturerStr to (ocidManufacturerStr's stringByReplacingOccurrencesOfString:("*Manufacturer: ") withString:("")) as text
193
194################################
195#収集した行データの処理 ocidImageableAreaStr
196set ocidImageableAreaDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
197set ocidImageableAreaArray to ocidImageableAreaStr's componentsSeparatedByString:("\n")
198#最後の改行分を削除
199ocidImageableAreaArray's removeLastObject()
200#Arrayの内容を順番に処理
201repeat with itemImgArea in ocidImageableAreaArray
202  set itemImgArea to (itemImgArea's stringByReplacingOccurrencesOfString:("*ImageableArea ") withString:(""))
203  set itemImgAreaArray to (itemImgArea's componentsSeparatedByString:(": \""))
204  set ocidSetKey to itemImgAreaArray's firstObject()
205  set ocidTempRectStr to itemImgAreaArray's lastObject()
206  set ocidTempRectStr to (ocidTempRectStr's stringByReplacingOccurrencesOfString:(" \"") withString:(""))
207  set ocidImgAreaRectArray to (ocidTempRectStr's componentsSeparatedByString:(" "))
208  (ocidImageableAreaDict's setValue:(ocidImgAreaRectArray) forKey:(ocidSetKey))
209end repeat
210#ここまでのデータをクリアしておく
211set ocidImageableAreaStr to (missing value)
212
213################################
214#収集した行データの処理 PaperDimension
215set ocidPaperDimensionDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
216set ocidPaperDimensionArray to ocidPaperDimensionStr's componentsSeparatedByString:("\n")
217#最後の改行分を削除
218ocidPaperDimensionArray's removeLastObject()
219#Arrayの内容を順番に処理
220repeat with itemPaperDim in ocidPaperDimensionArray
221  set itemPaperDim to (itemPaperDim's stringByReplacingOccurrencesOfString:("*PaperDimension ") withString:(""))
222  set itemPaperDimArray to (itemPaperDim's componentsSeparatedByString:(": \""))
223  set ocidSetKey to itemPaperDimArray's firstObject()
224  set ocidTempRectStr to itemPaperDimArray's lastObject()
225  set ocidTempRectStr to (ocidTempRectStr's stringByReplacingOccurrencesOfString:("\"") withString:(""))
226  set ocidPaperDimensionRectArray to (ocidTempRectStr's componentsSeparatedByString:(" "))
227  (ocidPaperDimensionDict's setValue:(ocidPaperDimensionRectArray) forKey:(ocidSetKey))
228end repeat
229#ここまでのデータをクリアしておく
230set ocidPaperDimensionStr to (missing value)
231
232################################
233#必要な値を生成していく
234#log ocidImageableAreaDict's allKeys()'s |count|() as integer
235#キーを取り出して
236set ocidDimensionDictAllKeys to ocidPaperDimensionDict's allKeys()
237#順番に処理する
238repeat with itemKey in ocidDimensionDictAllKeys
239  #紙名はメーカー名+紙の名前
240  set strSetPaperName to (strManufacturerStr & "-" & itemKey) as text
241  #データを取り出す この段階ではテキスト形式
242  set boolCustom to true as boolean
243  set itemPaperDimensionArray to (ocidPaperDimensionDict's objectForKey:(itemKey))
244  set strSetPaperWpt to itemPaperDimensionArray's firstObject()
245  set strSetPaperHpt to itemPaperDimensionArray's lastObject()
246  set itemImageableAreaArray to (ocidImageableAreaDict's objectForKey:(itemKey))
247  set strSetDimensionXpt to itemImageableAreaArray's firstObject()
248  set strSetDimensionYpt to (itemImageableAreaArray's objectAtIndex:(1))
249  set strSetDimensionWpt to (itemImageableAreaArray's objectAtIndex:(2))
250  set strSetDimensionHpt to itemImageableAreaArray's lastObject()
251  #テキストを数値に変更して
252  set numSetPaperWpt to (refMe's NSDecimalNumber's decimalNumberWithString:(strSetPaperWpt))'s floatValue()
253  set numSetPaperHpt to (refMe's NSDecimalNumber's decimalNumberWithString:(strSetPaperHpt))'s floatValue()
254  set numSetDimensionXpt to (refMe's NSDecimalNumber's decimalNumberWithString:(strSetDimensionXpt))'s floatValue()
255  set numSetDimensionYpt to (refMe's NSDecimalNumber's decimalNumberWithString:(strSetDimensionYpt))'s floatValue()
256  set numSetDimensionWpt to (refMe's NSDecimalNumber's decimalNumberWithString:(strSetDimensionWpt))'s floatValue()
257  set numSetDimensionHpt to (refMe's NSDecimalNumber's decimalNumberWithString:(strSetDimensionHpt))'s floatValue()
258  #余白 margin計算
259  set numSetMarginT to numSetDimensionYpt
260  set numSetMarginB to (numSetPaperHpt - numSetDimensionHpt)
261  set numSetMarginR to (numSetPaperWpt - numSetDimensionWpt)
262  set numSetMarginL to numSetDimensionXpt
263  #紙単位でセットするDICT
264  set ocidSetDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
265  #各値をDICTにセットしていく
266  (ocidSetDict's setValue:(strSetPaperName) forKey:("id"))
267  (ocidSetDict's setValue:(strSetPaperName) forKey:("name"))
268  (ocidSetDict's setValue:(boolCustom) forKey:("custom"))
269  (ocidSetDict's setValue:("") forKey:("printer"))
270  #
271  (ocidSetDict's setValue:(numSetMarginT) forKey:("top"))
272  (ocidSetDict's setValue:(numSetMarginB) forKey:("bottom"))
273  (ocidSetDict's setValue:(numSetMarginL) forKey:("left"))
274  (ocidSetDict's setValue:(numSetMarginR) forKey:("right"))
275  #
276  (ocidSetDict's setValue:(numSetPaperWpt) forKey:("width"))
277  (ocidSetDict's setValue:(numSetPaperHpt) forKey:("height"))
278  #値をセットしたDICTをPLISTのDICTにセットする
279  (ocidPlistDict's setObject:(ocidSetDict) forKey:(strSetPaperName))
280end repeat
281
282#ここまでのデータをクリアしておく
283set ocidImageableAreaDict to (missing value)
284set ocidImageableAreaArray to (missing value)
285set ocidPaperDimensionDict to (missing value)
286set ocidPaperDimensionArray to (missing value)
287set ocidPaperNameDict to (missing value)
288set ocidPaperNameArray to (missing value)
289################################
290#保存
291#DICTをPLISTに変換
292set ocidFormat to (refMe's NSPropertyListBinaryFormat_v1_0)
293set listResponse to refMe's NSPropertyListSerialization's dataWithPropertyList:(ocidPlistDict) format:(ocidFormat) options:0  |error| :(reference)
294set ocidPlistData to (item 1 of listResponse)
295#保存 
296set ocidOption to (refMe's NSDataWritingAtomic)
297set listDone to ocidPlistData's writeToURL:(ocidPrefFilePathURL) options:(ocidOption) |error| :(reference)
298if (item 1 of listDone) is true then
299  log "正常終了"
300else if (item 1 of listDone) is false then
301  return "保存に失敗しました"
302end if
303
304########################
305#保存先がPreferencesの場合
306##USBリバインド
307do shell script "/System/Library/SystemConfiguration/PrinterNotifications.bundle/Contents/MacOS/makequeues -r"
308##Update printer module cache
309try
310  do shell script "/System/Library/SystemConfiguration/PrinterNotifications.bundle/Contents/MacOS/makequeues -u"
311end try
312##Update PPD based queues
313do shell script "/System/Library/SystemConfiguration/PrinterNotifications.bundle/Contents/MacOS/makequeues -h"
314##LPDリバインド
315do shell script "/System/Library/SystemConfiguration/PrinterNotifications.bundle/Contents/MacOS/makequeues -k lpd"
316##IPPリバインド
317do shell script "/System/Library/SystemConfiguration/PrinterNotifications.bundle/Contents/MacOS/makequeues -k ipp"
318#プロセス再起動でリロード
319try
320  set strCommandText to "/usr/bin/killall cfprefsd" as text
321  do shell script strCommandText
322end try
323try
324  set strCommandText to "/usr/bin/killall -9 printtool" as text
325  do shell script strCommandText
326end try
327try
328  set strCommandText to "/usr/bin/killall -9 PrintUITool" as text
329  do shell script strCommandText
330end try
331
332
333return
334
335########################
336#日付取得サブ
337to doGetDateNo(strDateFormat)
338  ####日付情報の取得
339  set ocidDate to current application's NSDate's |date|()
340  ###日付のフォーマットを定義
341  set ocidNSDateFormatter to current application's NSDateFormatter's alloc()'s init()
342  ocidNSDateFormatter's setLocale:(current application's NSLocale's localeWithLocaleIdentifier:"ja_JP_POSIX")
343  ocidNSDateFormatter's setDateFormat:strDateFormat
344  set ocidDateAndTime to ocidNSDateFormatter's stringFromDate:ocidDate
345  set strDateAndTime to ocidDateAndTime as text
346  return strDateAndTime
347end doGetDateNo
348
349
AppleScriptで生成しました

|

PPDからカスタム用紙設定plistを生成する


AppleScript サンプルコード