Acrobat Distiller

Adobe PDF用のjoboptionsの用紙サイズ変更


AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004#
005#
006#com.cocolog-nifty.quicktimer.icefloe
007----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
008use AppleScript version "2.8"
009use framework "Foundation"
010use framework "AppKit"
011use scripting additions
012property refMe : a reference to current application
013
014#解像度今回は使わない
015set listResolution to {"72", "144", "288", "300", "360", "600", "1200", "2400", "3600", "4000"} as list
016#用紙名とサイズのレコード
017set recordPaperSizePt to {|Letter|:{612, 792}, |Legal|:{612, 1008}, |Executive|:{522, 756}, |Ledger|:{1224, 792}, |Tabloid|:{792, 1224}, |Screen|:{468, 373}, |A5|:{420, 595.22}, |A4|:{595.22, 842}, |A3|:{842, 1191}, |A2|:{1191, 1684}, |A1|:{1684, 2384}, |A0|:{2384, 3370}, |A4Extra|:{667, 914}, |A3Extra|:{913, 1262}, |JISB5|:{516, 729}, |JISB4|:{729, 1032}, |JISB3|:{1032, 1460}, |JISB2|:{1460, 2064}, |JISB1|:{2064, 2920}, |JISB0|:{2920, 4127}, |Letter-H|:{612, 792}, |Legal-H|:{612, 1008}, |Executive-H|:{522, 756}, |Ledger-H|:{1224, 792}, |Tabloid-H|:{792, 1224}, |Screen-H|:{468, 373}, |A5-H|:{420, 595.22}, |A4-H|:{595.22, 842}, |A3-H|:{842, 1191}, |A2-H|:{1191, 1684}, |A1-H|:{1684, 2384}, |A0-H|:{2384, 3370}, |A4Extra-H|:{667, 914}, |A3Extra-H|:{913, 1262}, |JISB5-H|:{516, 729}, |JISB4-H|:{729, 1032}, |JISB3-H|:{1032, 1460}, |JISB2-H|:{1460, 2064}, |JISB1-H|:{2064, 2920}, |JISB0-H|:{2920, 4127}} as record
018
019#DICT
020set ocidPaperSizePtDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
021ocidPaperSizePtDict's setDictionary:(recordPaperSizePt)
022set ocidAllKeys to ocidPaperSizePtDict's allKeys()
023set ocidSortedArray to ocidAllKeys's sortedArrayUsingSelector:("localizedStandardCompare:")
024set listAllKeys to ocidSortedArray as list
025#ダイアログ
026set strName to (name of current application) as text
027if strName is "osascript" then
028  tell application "Finder" to activate
029else
030  tell current application to activate
031end if
032set strTitle to ("選んでください") as text
033set strPrompt to ("用紙サイズ選択") as text
034try
035  set listResponse to (choose from list listAllKeys with title strTitle with prompt strPrompt default items (item 1 of listAllKeys) OK button name "OK" cancel button name "キャンセル" without multiple selections allowed and empty selection allowed) as list
036on error
037  log "エラーしました"
038  return "エラーしました"
039end try
040if (item 1 of listResponse) is false then
041  return "キャンセルしましたA"
042else if (item 1 of listResponse) is "キャンセル" then
043  return "キャンセルしましたB"
044else
045  set strPapaerName to (item 1 of listResponse) as text
046end if
047##
048set ocidSizeArray to ocidPaperSizePtDict's valueForKey:(strPapaerName)
049
050#############################
051#ダイアログ
052set strName to (name of current application) as text
053if strName is "osascript" then
054  tell application "Finder" to activate
055else
056  tell current application to activate
057end if
058set appFileManager to refMe's NSFileManager's defaultManager()
059set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
060set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
061set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
062#UTIリスト
063set listUTI to {"public.item"}
064set strMes to ("ファイルを選んでください") as text
065set strPrompt to ("ファイルを選んでください") as text
066try
067  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
068on error
069  log "Cエラーしました"
070  return "Cエラーしました"
071end try
072#パス
073set strFilePath to (POSIX path of aliasFilePath) as text
074set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
075set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
076set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:(false))
077#保存用
078set ocidBaseFilePathURL to ocidFilePathURL's URLByDeletingPathExtension()
079set strFileName to (ocidBaseFilePathURL's lastPathComponent()) as text
080set strSetFileName to ("(" & strPapaerName & ").joboptions") as text
081set ocidSaveFilePathURL to ocidBaseFilePathURL's URLByAppendingPathExtension:(strSetFileName)
082#NSDATA
083set ocidOption to (refMe's NSDataReadingMappedIfSafe)
084set listResponse to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidFilePathURL) options:(ocidOption) |error| :(reference)
085if (item 2 of listResponse) = (missing value) then
086  log "正常処理"
087  set ocidReadData to (item 1 of listResponse)
088else if (item 2 of listResponse) ≠ (missing value) then
089  set strErrorNO to (item 2 of listResponse)'s code() as text
090  set strErrorMes to (item 2 of listResponse)'s localizedDescription() as text
091  refMe's NSLog("■:" & strErrorNO & strErrorMes)
092  return "エラーしました" & strErrorNO & strErrorMes
093end if
094#NSString
095set ocidReadString to refMe's NSString's alloc()'s initWithData:(ocidReadData) encoding:(refMe's NSUTF8StringEncoding)
096#NSArray
097set ocidChrSet to refMe's NSCharacterSet's newlineCharacterSet()
098set ocidStringArray to ocidReadString's componentsSeparatedByCharactersInSet:(ocidChrSet)
099#アイテム数
100set numCntArray to ocidStringArray's |count|()
101#ページサイズは最後の方なので項目は最後から
102repeat with itemNo from (numCntArray - 1) to 0 by -1
103  #リストから取り出す
104  set ocidItemString to (ocidStringArray's objectAtIndex:(itemNo))
105  #ページサイズ行がきたら
106  set boolContain to (ocidItemString's containsString:("/PageSize"))
107  if (boolContain as boolean) is true then
108    #サイズw
109    set numW to ocidSizeArray's firstObject()
110    #サイズh
111    set numH to ocidSizeArray's lastObject()
112    #新しい値にして
113    set strSetSize to ("/PageSize [" & numW & " " & numH & "]") as text
114    #Stringにして
115    set ocidSetObject to (refMe's NSString's stringWithString:(strSetSize))
116    #Arrayの項目を入れ替え
117    (ocidStringArray's replaceObjectAtIndex:(itemNo) withObject:(ocidSetObject))
118    exit repeat
119  end if
120end repeat
121#Arrayをテキストにして
122set ocidJoinText to ocidStringArray's componentsJoinedByString:("\n")
123#テキストを保存
124set ocidOption to (refMe's NSUTF8StringEncoding)
125set listDone to ocidJoinText's writeToURL:(ocidSaveFilePathURL) atomically:(true) encoding:(ocidOption) |error| :(reference)
126#保存結果
127if (item 1 of listDone) is true then
128  log "正常処理"
129else if (item 2 of listDone) ≠ (missing value) then
130  set strErrorNO to (item 2 of listDone)'s code() as text
131  set strErrorMes to (item 2 of listDone)'s localizedDescription() as text
132  refMe's NSLog("■:" & strErrorNO & strErrorMes)
133  return "エラーしました" & strErrorNO & strErrorMes
134end if
135
AppleScriptで生成しました

|

[Distiller]ページサイズを指定したjoboptionを作成する


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
(*
ページサイズを指定して
joboptionをコピーします
com.cocolog-nifty.quicktimer.icefloe
*)
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use framework "UniformTypeIdentifiers"

use scripting additions

property refMe : a reference to current application

set ocidPaperDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0

#プリンタを取得
set ocidPrinterArray to refMe's NSPrinter's printerNames()
set listPrinterArray to ocidPrinterArray as list
###ダイアログを前面に出す
set strName to (name of current application) as text
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
###
set strTitle to ("選んでください") as text
set strPrompt to ("プリンタ名を選んでください") as text
try
  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
on error
log "エラーしました"
return "エラーしました"
end try
if (item 1 of listResponse) is false then
return "キャンセルしましたA"
else if (item 1 of listResponse) is "キャンセル" then
return "キャンセルしましたB"
else
  set strPPDsName to ((item 1 of listResponse) & ".ppd") as text
end if

(*
set ocidPrinter to (refMe's NSPrinter's printerWithName:(strPrinterName))
この方法はmacOS14の不具合
#プリンタの名前
set strPrinterName to ocidPrinter's |name| as text
log "name:" & ocidPrinter's |name| as text
log "type:" & ocidPrinter's type as text
set ocidDescription to ocidPrinter's deviceDescription()
log "deviceDescription:" & (ocidDescription's valueForKey:("deviceDescriptionNSDeviceIsPrinter")) as text
######
*)

##########################################
##
set strPPDsDirPath to "/private/etc/cups/ppd" as text
set ocidPPDsDirPathStr to refMe's NSString's stringWithString:(strPPDsDirPath)
set ocidPPDsDirPath to ocidPPDsDirPathStr's stringByStandardizingPath()
set ocidPPDsDirPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidPPDsDirPath) isDirectory:false)
#ファイル収集のオプション(非表示無視)
set ocidOption to (refMe's NSDirectoryEnumerationSkipsHiddenFiles)
#収集するキー(パスと名前)
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidKeysArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
ocidKeysArray's addObject:(refMe's NSURLPathKey)
ocidKeysArray's addObject:(refMe's NSURLNameKey)
set lisrResponse to (appFileManager's contentsOfDirectoryAtURL:(ocidPPDsDirPathURL) includingPropertiesForKeys:(ocidKeysArray) options:(ocidOption) |error|:(reference))
if (item 2 of lisrResponse) = (missing value) then
  set ocidPPDsFilePathURLArray to (item 1 of lisrResponse)
else if (item 2 of lisrResponse) ≠ (missing value) then
log (item 2 of lisrResponse)'s localizedDescription() as text
end if
##ファイル名とパスのレコードを作成
set ocidName2URLDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
repeat with itemFilePathURL in ocidPPDsFilePathURLArray
  set ocidFileName to itemFilePathURL's lastPathComponent()
(ocidName2URLDict's setObject:(itemFilePathURL) forKey:(ocidFileName))
end repeat
set ocidPPDsFilePathURL to ocidName2URLDict's objectForKey:(strPPDsName)

##########################################
##PPD読み込み
set listResponse to refMe's NSString's alloc()'s initWithContentsOfURL:(ocidPPDsFilePathURL) encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)
if (item 2 of lisrResponse) = (missing value) then
  set ocidReadString to (item 1 of listResponse)
else if (item 2 of lisrResponse) ≠ (missing value) then
log (item 2 of lisrResponse)'s localizedDescription() as text
end if

##########################################
##PPD解析
set ocidCharSet to refMe's NSCharacterSet's newlineCharacterSet()
set ocidPPDsLineArray to ocidReadString's componentsSeparatedByCharactersInSet:(ocidCharSet)
##格納用のレコード
set ocidPaperDimensionDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
##全行対象
repeat with itemArray in ocidPPDsLineArray
  set boolImageableArea to (itemArray's containsString:("*PaperDimension")) as boolean
  if boolImageableArea is true then
    set ocidLineString to (itemArray's stringByReplacingOccurrencesOfString:("*PaperDimension ") withString:(""))
    set ocidCharSet to (refMe's NSMutableCharacterSet's characterSetWithCharactersInString:(":"))
    set ocidLineArray to (ocidLineString's componentsSeparatedByCharactersInSet:(ocidCharSet))
    set ocidPaperName to (ocidLineArray's objectAtIndex:(0))
    set ocidDimensionStr to (ocidLineArray's objectAtIndex:(1))
    set ocidDimension to (ocidDimensionStr's stringByReplacingOccurrencesOfString:(" \"") withString:(""))
    set ocidDimensionStr to (ocidDimension's stringByReplacingOccurrencesOfString:("\"") withString:(""))
    set ocidCharSet to (refMe's NSMutableCharacterSet's characterSetWithCharactersInString:(" "))
    set ocidDimensionArray to (ocidDimensionStr's componentsSeparatedByCharactersInSet:(ocidCharSet))
    set ocidPaperW to (ocidDimensionArray's objectAtIndex:(0))'s floatValue
    set ocidPaperH to (ocidDimensionArray's objectAtIndex:(1))'s floatValue
    ##サイズにして格納しておく(ここでは不要なんだけど後で何か使うかなと)
    set ocidPageSize to refMe's NSSize's NSMakeSize(ocidPaperW, ocidPaperH)
(ocidPaperDimensionDict's setObject:(ocidPageSize) forKey:(ocidPaperName))
  end if
end repeat

################
##用紙名だけのリスト
set ocidAllKeys to ocidPaperDimensionDict's allKeys()
##ソート
set ocidPaperNameArray to ocidAllKeys's sortedArrayUsingSelector:("localizedStandardCompare:")
set listAllKeys to ocidPaperNameArray as list

##########################################
##ダイアログ
set strName to (name of current application) as text
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
###
set strTitle to ("選んでください") as text
set strPrompt to ("用紙名を選んでください\n用紙サイズを戻します") as text
try
  set listResponse to (choose from list listAllKeys with title strTitle with prompt strPrompt default items (item 1 of listAllKeys) OK button name "OK" cancel button name "キャンセル" without multiple selections allowed and empty selection allowed) as list
on error
log "エラーしました"
return "エラーしました"
end try
if (item 1 of listResponse) is false then
return "キャンセルしましたA"
else if (item 1 of listResponse) is "キャンセル" then
return "キャンセルしましたB"
else
  set strPaperName to (item 1 of listResponse) as text
end if
##数値で取得
set ocidSizeList to ocidPaperDimensionDict's objectForKey:(strPaperName)
set ocidDecW to (ocidSizeList's width)'s floatValue
set ocidDecH to (ocidSizeList's height)'s floatValue
##小数点以下2桁
set ocidFormatter to refMe's NSNumberFormatter's alloc()'s init()
ocidFormatter's setRoundingMode:(refMe's NSNumberFormatterRoundFloor)
ocidFormatter's setNumberStyle:(refMe's NSNumberFormatterNoStyle)
ocidFormatter's setMaximumFractionDigits:(2)
set ocidFloat4W to ocidFormatter's stringFromNumber:(ocidDecW)
set ocidFloat4H to ocidFormatter's stringFromNumber:(ocidDecH)
##テキストにしておく
set strW to ocidFloat4W as text
set strH to ocidFloat4H as text

##########################################
##Joboptionの収集
##ファイルパスの格納用のリスト
set ocidFilePathURLArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
#ファイル収集のオプション(非表示無視)
set ocidOption to (refMe's NSDirectoryEnumerationSkipsHiddenFiles)
#収集するキー(パスと名前)
set ocidKeysArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
ocidKeysArray's addObject:(refMe's NSURLPathKey)
ocidKeysArray's addObject:(refMe's NSURLNameKey)
######
#収集するパス
set listDirPath to {"Adobe/Adobe PDF/Settings", "Adobe/Adobe PDF/Extras"}
#ローカルドメインの収集
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSApplicationSupportDirectory) inDomains:(refMe's NSLocalDomainMask))
set ocidLocalAppSupDirPathURL to ocidURLsArray's firstObject()
#収集して
repeat with itemDirPath in listDirPath
  set ocidChkDirPathURL to (ocidLocalAppSupDirPathURL's URLByAppendingPathComponent:(itemDirPath) isDirectory:(true))
  set lisrResponse to (appFileManager's contentsOfDirectoryAtURL:(ocidChkDirPathURL) includingPropertiesForKeys:(ocidKeysArray) options:(ocidOption) |error|:(reference))
  if (item 2 of lisrResponse) = (missing value) then
    set ocidGetFilePathURLArray to (item 1 of lisrResponse)
  else if (item 2 of lisrResponse) ≠ (missing value) then
log (item 2 of lisrResponse)'s localizedDescription() as text
  end if
  ##リストに追加
(ocidFilePathURLArray's addObjectsFromArray:(ocidGetFilePathURLArray))
end repeat
######
#ユーザードメインの収集
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSApplicationSupportDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidLocalAppSupDirPathURL to ocidURLsArray's firstObject()
#収集して
repeat with itemDirPath in listDirPath
  set ocidChkDirPathURL to (ocidLocalAppSupDirPathURL's URLByAppendingPathComponent:(itemDirPath) isDirectory:(true))
  set lisrResponse to (appFileManager's contentsOfDirectoryAtURL:(ocidChkDirPathURL) includingPropertiesForKeys:(ocidKeysArray) options:(ocidOption) |error|:(reference))
  if (item 2 of lisrResponse) = (missing value) then
    set ocidGetFilePathURLArray to (item 1 of lisrResponse)
  else if (item 2 of lisrResponse) ≠ (missing value) then
log (item 2 of lisrResponse)'s localizedDescription() as text
  end if
  ##リストに追加
(ocidFilePathURLArray's addObjectsFromArray:(ocidGetFilePathURLArray))
end repeat
######
##ファイル名とパスのレコードを作成
set ocidName2URLDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
repeat with itemFilePathURL in ocidFilePathURLArray
  set ocidFileName to itemFilePathURL's lastPathComponent()
(ocidName2URLDict's setObject:(itemFilePathURL) forKey:(ocidFileName))
end repeat
######
##ファイル名だけのリスト
set ocidAllKeys to ocidName2URLDict's allKeys()
##ソート
set ocidFileNameArray to ocidAllKeys's sortedArrayUsingSelector:("localizedStandardCompare:")
set listFileNameArray to ocidFileNameArray as list

##########################################
##ダイアログ
set strName to (name of current application) as text
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
###
set strTitle to ("選んでください") as text
set strPrompt to ("JOBOPTIONを選んでください\n用紙サイズを設定します") as text
try
  set listResponse to (choose from list listFileNameArray with title strTitle with prompt strPrompt default items (item 1 of listFileNameArray) OK button name "OK" cancel button name "キャンセル" without multiple selections allowed and empty selection allowed) as list
on error
log "エラーしました"
return "エラーしました"
end try
if (item 1 of listResponse) is false then
return "キャンセルしましたA"
else if (item 1 of listResponse) is "キャンセル" then
return "キャンセルしましたB"
else
  set strJobOptionName to (item 1 of listResponse) as text
end if
##########################################
##joboptionsのURL
set ocidOptionFilePathURL to ocidName2URLDict's objectForKey:(strJobOptionName)
##joboptions読み込み
set listResponse to refMe's NSString's alloc()'s initWithContentsOfURL:(ocidOptionFilePathURL) encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)
if (item 2 of lisrResponse) = (missing value) then
  set ocidReadJoboption to (item 1 of listResponse)
else if (item 2 of lisrResponse) ≠ (missing value) then
log (item 2 of lisrResponse)'s localizedDescription() as text
end if
#セットする値
set strSetValue to ("/PageSize [" & strW & " " & strH & "]") as text

##########################################
##改行UNIXを強制
set ocidTmpJoboption to (ocidReadJoboption's stringByReplacingOccurrencesOfString:("\n\r") withString:("\n"))
set ocidTmpJoboption to (ocidTmpJoboption's stringByReplacingOccurrencesOfString:("\r") withString:("\n"))
set ocidReadJoboption to (ocidTmpJoboption's stringByReplacingOccurrencesOfString:("\n\n") withString:("\n"))
##改行でリストに
set ocidCharSet to refMe's NSCharacterSet's newlineCharacterSet()
set ocidJobOptionLineArray to ocidReadJoboption's componentsSeparatedByCharactersInSet:(ocidCharSet)
set ocidSaveOptionArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
##全行調べて ページサイズを置換
repeat with itemJobOptionLineArray in ocidJobOptionLineArray
  set boolContain to (itemJobOptionLineArray's containsString:("/PageSize "))
  if boolContain is true then
(ocidSaveOptionArray's addObject:(strSetValue))
  else
(ocidSaveOptionArray's addObject:(itemJobOptionLineArray))
  end if
end repeat
##リストをテキストに戻して
set ocidSaveString to ocidSaveOptionArray's componentsJoinedByString:("\n")

##########################################
##ファイル名
set strSaveFileName to (strPaperName & "_" & strPPDsName & "_" & strJobOptionName) as text
set ocidSaveFileName to refMe's NSString's stringWithString:(strSaveFileName)
set ocidSaveFileName to (ocidSaveFileName's stringByReplacingOccurrencesOfString:("/") withString:("_"))
##保存先
set ocidSaveDirPathURL to (ocidLocalAppSupDirPathURL's URLByAppendingPathComponent:("Adobe/Adobe PDF/Settings") isDirectory:(true))
set ocidSaveFilePathURL to (ocidSaveDirPathURL's URLByAppendingPathComponent:(ocidSaveFileName) isDirectory:(false))
##保存
set listDone to ocidSaveString's writeToURL:(ocidSaveFilePathURL) atomically:(true) encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)
if (item 1 of listDone) is true then
return "正常終了"
else if (item 1 of listDone) is false then
log (item 2 of listDone)'s localizedDescription() as text
return "保存に失敗しました"
end if



return








|

[Distiller]postscriptファイルをPDFに変換する


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
# テキスト系式のapplescriptだとコンパイル時に起動するのでダメ
# コンパイル済みのscpt系式で保存してください
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use framework "UniformTypeIdentifiers"

use scripting additions
property refMe : a reference to current application

##ファイルパスの格納用のリスト
set ocidFilePathURLArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
#ファイル収集のオプション(非表示無視)
set ocidOption to (refMe's NSDirectoryEnumerationSkipsHiddenFiles)
#収集するキー(パスと名前)
set ocidKeysArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
ocidKeysArray's addObject:(refMe's NSURLPathKey)
ocidKeysArray's addObject:(refMe's NSURLNameKey)
######
#収集するパス
set listDirPath to {"Adobe/Adobe PDF/Settings", "Adobe/Adobe PDF/Extras"}
#ローカルドメインの収集
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSApplicationSupportDirectory) inDomains:(refMe's NSLocalDomainMask))
set ocidLocalAppSupDirPathURL to ocidURLsArray's firstObject()
#収集して
repeat with itemDirPath in listDirPath
  set ocidChkDirPathURL to (ocidLocalAppSupDirPathURL's URLByAppendingPathComponent:(itemDirPath) isDirectory:(true))
  set lisrResponse to (appFileManager's contentsOfDirectoryAtURL:(ocidChkDirPathURL) includingPropertiesForKeys:(ocidKeysArray) options:(ocidOption) |error|:(reference))
  if (item 2 of lisrResponse) = (missing value) then
    set ocidGetFilePathURLArray to (item 1 of lisrResponse)
  else if (item 2 of lisrResponse) ≠ (missing value) then
log (item 2 of lisrResponse)'s localizedDescription() as text
  end if
  ##リストに追加
(ocidFilePathURLArray's addObjectsFromArray:(ocidGetFilePathURLArray))
end repeat
######
#ユーザードメインの収集
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSApplicationSupportDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidLocalAppSupDirPathURL to ocidURLsArray's firstObject()
#収集して
repeat with itemDirPath in listDirPath
  set ocidChkDirPathURL to (ocidLocalAppSupDirPathURL's URLByAppendingPathComponent:(itemDirPath) isDirectory:(true))
  set lisrResponse to (appFileManager's contentsOfDirectoryAtURL:(ocidChkDirPathURL) includingPropertiesForKeys:(ocidKeysArray) options:(ocidOption) |error|:(reference))
  if (item 2 of lisrResponse) = (missing value) then
    set ocidGetFilePathURLArray to (item 1 of lisrResponse)
  else if (item 2 of lisrResponse) ≠ (missing value) then
log (item 2 of lisrResponse)'s localizedDescription() as text
  end if
  ##リストに追加
(ocidFilePathURLArray's addObjectsFromArray:(ocidGetFilePathURLArray))
end repeat
######
##ファイル名とパスのレコードを作成
set ocidName2URLDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
repeat with itemFilePathURL in ocidFilePathURLArray
  set ocidFileName to itemFilePathURL's lastPathComponent()
(ocidName2URLDict's setObject:(itemFilePathURL) forKey:(ocidFileName))
end repeat
######
##ファイル名だけのリスト
set ocidAllKeys to ocidName2URLDict's allKeys()
##ソート
set ocidFileNameArray to ocidAllKeys's sortedArrayUsingSelector:("localizedStandardCompare:")
set listFileNameArray to ocidFileNameArray as list
#最小ファイルサイズが何番目か?
set numIndex to ocidFileNameArray's indexOfObject:("Smallest File Size.joboptions")
set numIndex to (numIndex + 1) as integer
##################
#ダイアログ
set strName to (name of current application) as text
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
###
set strTitle to ("選んでください") as text
set strPrompt to ("ジョブオプションを選んでください") as text
try
  set listResponse to (choose from list listFileNameArray with title strTitle with prompt strPrompt default items (item numIndex of listFileNameArray) OK button name "OK" cancel button name "キャンセル" without multiple selections allowed and empty selection allowed) as list
on error
log "エラーしました"
return "エラーしました"
end try
if (item 1 of listResponse) is false then
return "キャンセルしましたA"
else if (item 1 of listResponse) is "キャンセル" then
return "キャンセルしましたB"
else
  set strResponse to (item 1 of listResponse) as text
end if
##
set ocidChooseFilePathURL to ocidName2URLDict's objectForKey:(strResponse)
set strChooseFilePath to ocidChooseFilePathURL's |path| as text
set strAdobePDFSettingsPath to strChooseFilePath as text

###ダイアログ
set strName to (name of current application) as text
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias

set listUTI to {"com.adobe.postscript"}
set strMes to ("ファイルを選んでください") as text
set strPrompt to ("ファイルを選んでください") as text
try
  ### ファイル選択時
  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
on error
log "エラーしました"
return "エラーしました"
end try

set strPsFilePath to (POSIX path of aliasFilePath) as text
set ocidFilePathStr to refMe's NSString's stringWithString:(strPsFilePath)
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
set ocidContainerDirPathURL to ocidFilePathURL's URLByDeletingLastPathComponent()
set strDestinationPath to ocidContainerDirPathURL's |path| as text


tell application "Acrobat Distiller" to launch
##起動待ち最大10秒
repeat 20 times
  tell application id "com.adobe.distiller"
    set boolFrontmost to frontmost as boolean
  end tell
  if boolFrontmost is false then
    tell application id "com.adobe.distiller"
activate
    end tell
delay 0.5
  else if boolFrontmost is true then
    exit repeat
  end if
end repeat

tell application "Acrobat Distiller"
Distill sourcePath strPsFilePath destinationPath strDestinationPath adobePDFSettingsPath strAdobePDFSettingsPath
end tell

tell application "Acrobat Distiller"
quit
end tell

|

[Distiller]EPSをPDFに変換する


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
# テキスト系式のapplescriptだとコンパイル時に起動するのでダメ
# コンパイル済みのscpt系式で保存してください
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use framework "UniformTypeIdentifiers"

use scripting additions
property refMe : a reference to current application


tell application id "com.adobe.distiller" to quit

##ファイルパスの格納用のリスト
set ocidFilePathURLArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
#ファイル収集のオプション(非表示無視)
set ocidOption to (refMe's NSDirectoryEnumerationSkipsHiddenFiles)
#収集するキー(パスと名前)
set ocidKeysArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
ocidKeysArray's addObject:(refMe's NSURLPathKey)
ocidKeysArray's addObject:(refMe's NSURLNameKey)
######
#収集するパス
set listDirPath to {"Adobe/Adobe PDF/Settings", "Adobe/Adobe PDF/Extras"}
#ローカルドメインの収集
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSApplicationSupportDirectory) inDomains:(refMe's NSLocalDomainMask))
set ocidLocalAppSupDirPathURL to ocidURLsArray's firstObject()
#収集して
repeat with itemDirPath in listDirPath
  set ocidChkDirPathURL to (ocidLocalAppSupDirPathURL's URLByAppendingPathComponent:(itemDirPath) isDirectory:(true))
  set lisrResponse to (appFileManager's contentsOfDirectoryAtURL:(ocidChkDirPathURL) includingPropertiesForKeys:(ocidKeysArray) options:(ocidOption) |error|:(reference))
  if (item 2 of lisrResponse) = (missing value) then
    set ocidGetFilePathURLArray to (item 1 of lisrResponse)
  else if (item 2 of lisrResponse) ≠ (missing value) then
log (item 2 of lisrResponse)'s localizedDescription() as text
  end if
  ##リストに追加
(ocidFilePathURLArray's addObjectsFromArray:(ocidGetFilePathURLArray))
end repeat
######
#ユーザードメインの収集
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSApplicationSupportDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidLocalAppSupDirPathURL to ocidURLsArray's firstObject()
#収集して
repeat with itemDirPath in listDirPath
  set ocidChkDirPathURL to (ocidLocalAppSupDirPathURL's URLByAppendingPathComponent:(itemDirPath) isDirectory:(true))
  set lisrResponse to (appFileManager's contentsOfDirectoryAtURL:(ocidChkDirPathURL) includingPropertiesForKeys:(ocidKeysArray) options:(ocidOption) |error|:(reference))
  if (item 2 of lisrResponse) = (missing value) then
    set ocidGetFilePathURLArray to (item 1 of lisrResponse)
  else if (item 2 of lisrResponse) ≠ (missing value) then
log (item 2 of lisrResponse)'s localizedDescription() as text
  end if
  ##リストに追加
(ocidFilePathURLArray's addObjectsFromArray:(ocidGetFilePathURLArray))
end repeat
######
##ファイル名とパスのレコードを作成
set ocidName2URLDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
repeat with itemFilePathURL in ocidFilePathURLArray
  set ocidFileName to itemFilePathURL's lastPathComponent()
(ocidName2URLDict's setObject:(itemFilePathURL) forKey:(ocidFileName))
end repeat
######
##ファイル名だけのリスト
set ocidAllKeys to ocidName2URLDict's allKeys()
##ソート
set ocidFileNameArray to ocidAllKeys's sortedArrayUsingSelector:("localizedStandardCompare:")
set listFileNameArray to ocidFileNameArray as list
#最小ファイルサイズが何番目か?
set numIndex to ocidFileNameArray's indexOfObject:("Smallest File Size.joboptions")
set numIndex to (numIndex + 1) as integer
##################
#ダイアログ
set strName to (name of current application) as text
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
###
set strTitle to ("選んでください") as text
set strPrompt to ("ジョブオプションを選んでください") as text
try
  set listResponse to (choose from list listFileNameArray with title strTitle with prompt strPrompt default items (item numIndex of listFileNameArray) OK button name "OK" cancel button name "キャンセル" without multiple selections allowed and empty selection allowed) as list
on error
log "エラーしました"
return "エラーしました"
end try
if (item 1 of listResponse) is false then
return "キャンセルしましたA"
else if (item 1 of listResponse) is "キャンセル" then
return "キャンセルしましたB"
else
  set strResponse to (item 1 of listResponse) as text
end if
##
set ocidChooseFilePathURL to ocidName2URLDict's objectForKey:(strResponse)
set strChooseFilePath to ocidChooseFilePathURL's |path| as text
set strAdobePDFSettingsPath to strChooseFilePath as text

###ダイアログ
set strName to (name of current application) as text
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias

set listUTI to {"com.adobe.encapsulated-postscript"}
set strMes to ("ファイルを選んでください") as text
set strPrompt to ("ファイルを選んでください") as text
try
  ### ファイル選択時
  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
on error
log "エラーしました"
return "エラーしました"
end try

set strPsFilePath to (POSIX path of aliasFilePath) as text
set ocidFilePathStr to refMe's NSString's stringWithString:(strPsFilePath)
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
set ocidContainerDirPathURL to ocidFilePathURL's URLByDeletingLastPathComponent()
set strDestinationPath to ocidContainerDirPathURL's |path| as text


tell application "Acrobat Distiller" to launch
##起動待ち最大10秒
repeat 20 times
  tell application id "com.adobe.distiller"
    set boolFrontmost to frontmost as boolean
  end tell
  if boolFrontmost is false then
    tell application id "com.adobe.distiller"
activate
    end tell
delay 0.5
  else if boolFrontmost is true then
    exit repeat
  end if
end repeat

tell application "Acrobat Distiller"
Distill sourcePath strPsFilePath destinationPath strDestinationPath adobePDFSettingsPath strAdobePDFSettingsPath
end tell

return
tell application "Acrobat Distiller"
quit
end tell

|

[Distiller]キャッシュをゴミ箱に入れる


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#【重要】 Adobeのアプリケーションを【重要】
#一旦全て終了させてから実行してください
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application

set appFileManager to refMe's NSFileManager's defaultManager()

###################################
########まずは処理するアプリケーションを終了させる
###################################
try
  tell application id "com.adobe.distiller" to quit
end try
set ocidRunningApplication to refMe's NSRunningApplication
set ocidAppArray to (ocidRunningApplication's runningApplicationsWithBundleIdentifier:("com.adobe.distiller"))
###複数起動時も順番に終了
repeat with itemAppArray in ocidAppArray
  ###終了
itemAppArray's terminate()
end repeat
##1秒まって終了を確認
delay 1
##終了できない場合は強制終了
repeat with itemAppArray in ocidAppArray
  set boolTerminate to itemAppArray's terminated
  if boolTerminate = false then
itemAppArray's forceTerminate()
  end if
end repeat
##使いたくないがしかたがない
try
do shell script "/usr/bin/killall Distiller"
end try
###################################
########
###################################
log doMoveToTrash("~/Library/Application Scripts/com.adobe.distiller")
log doMoveToTrash("~/Library/Caches/Acrobat")
log doMoveToTrash("~/Library/Caches/Adobe")
log doMoveToTrash("~/Library/Caches/com.adobe.Acrobat.Pro")
log doMoveToTrash("~/Library/Caches/com.adobe.distiller")
log doMoveToTrash("~/Library/Caches/com.adobe.Reader")
log doMoveToTrash("~/Library/WebKit/com.adobe.crashreporter")
log doMoveToTrash("~/Library/WebKit/com.adobe.distiller")
log doMoveToTrash("~/Library/Logs/Adobe")
log doMoveToTrash("~/Library/HTTPStorages/com.adobe.distiller")
log doMoveToTrash("~/Library/HTTPStorages/com.adobe.Acrobat.Pro")
log doMoveToTrash("~/Library/HTTPStorages/com.adobe.Reader")
##
log doMoveToTrash("~/Library/Application Support/Adobe/AcroCef/DC/Acrobat/Cache")
log doMoveToTrash("~/Library/Application Support/Adobe/AcroCef/2020/Acrobat/Cache")
log doMoveToTrash("~/Library/Application Support/Adobe/Acrobat/Distiller DC/FontCache")
log doMoveToTrash("~/Library/Application Support/Adobe/Acrobat/SaveAsAdobePDF DC/FontCache")
log doMoveToTrash("~/Library/Application Support/Adobe/Acrobat/Preflight Acrobat Continuous/FontCache")
log doMoveToTrash("~/Library/Application Support/Adobe/Acrobat/Distiller DC/Messages.log")
log doMoveToTrash("~/Library/Application Support/Adobe/Acrobat/DC/BHCache")
log doMoveToTrash("~/Library/Application Support/Adobe/Acrobat/DC/AdobeCMapFnt22.lst")
log doMoveToTrash("~/Library/Application Support/Adobe/Acrobat/DC/AdobeCMapFnt24.lst")
log doMoveToTrash("~/Library/Application Support/Adobe/Acrobat/DC/AdobeSysFnt22.lst")
log doMoveToTrash("~/Library/Application Support/Adobe/Acrobat/DC/AdobeSysFnt24.lst")
log doMoveToTrash("~/Library/Application Support/Adobe/Acrobat/DC/JSCache")
log doMoveToTrash("~/Library/Application Support/Adobe/Acrobat/DC/ThumbCache")
log doMoveToTrash("~/Library/Application Support/Adobe/Acrobat/DC/ToolsSearchCacheAcro")
log doMoveToTrash("~/Library/Application Support/Adobe/Acrobat/DC/UserCache64.bin")
log doMoveToTrash("~/Library/Application Support/Adobe/Acrobat/DC/ProtectedView¥AdobeSysFnt22.lst")


###################################
########キャッシュNSTemporaryDirectory
###################################
### T
set ocidTempDir to (refMe's NSTemporaryDirectory())
set ocidTemporaryTPathURL to refMe's NSURL's fileURLWithPath:(ocidTempDir)
set ocidPropertiesArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
ocidPropertiesArray's addObject:(refMe's NSURLIsRegularFileKey)
ocidPropertiesArray's addObject:(refMe's NSURLPathKey)
ocidPropertiesArray's addObject:(refMe's NSURLNameKey)
set listResponse to appFileManager's contentsOfDirectoryAtURL:(ocidTemporaryTPathURL) includingPropertiesForKeys:(ocidPropertiesArray) options:(refMe's NSDirectoryEnumerationSkipsSubdirectoryDescendants) |error|:(reference)
log item 2 of listResponse

repeat with itemURL in (item 1 of listResponse)
  set listResourceValue to (itemURL's getResourceValue:(reference) forKey:(refMe's NSURLNameKey) |error|:(missing value))
  set ocidFileName to (item 2 of listResourceValue)
  if (ocidFileName's hasPrefix:("Acr")) = true then
log itemURL's lastPathComponent() as text
    
  end if
end repeat

log doMoveToTrash(ocidTemporaryTPathURL's URLByAppendingPathComponent:"AdobeIDataSync")
###
set ocidTempURL to ocidTemporaryTPathURL's URLByDeletingLastPathComponent()
### C
set ocidTemporaryCPathURL to ocidTempURL's URLByAppendingPathComponent:"C"

log doMoveToTrash(ocidTemporaryCPathURL's URLByAppendingPathComponent:"com.adobe.Acrobat.Pro")
log doMoveToTrash(ocidTemporaryCPathURL's URLByAppendingPathComponent:"com.adobe.Reader")
log doMoveToTrash(ocidTemporaryCPathURL's URLByAppendingPathComponent:"com.adobe.distiller")

###################################
########処理 ゴミ箱に入れる
###################################

to doMoveToTrash(argFilePath)
  ###ファイルマネジャー初期化
  set appFileManager to refMe's NSFileManager's defaultManager()
  #########################################
  ###渡された値のClassを調べてとりあえずNSURLにする
  set refClass to class of argFilePath
  if refClass is list then
return "エラー:リストは処理しません"
  else if refClass is text then
log "テキストパスです"
    set ocidArgFilePathStr to (refMe's NSString's stringWithString:argFilePath)
    set ocidArgFilePath to ocidArgFilePathStr's stringByStandardizingPath
    set ocidArgFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:ocidArgFilePath)
  else if refClass is alias then
log "エイリアスパスです"
    set strArgFilePath to (POSIX path of argFilePath) as text
    set ocidArgFilePathStr to (refMe's NSString's stringWithString:strArgFilePath)
    set ocidArgFilePath to ocidArgFilePathStr's stringByStandardizingPath
    set ocidArgFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:ocidArgFilePath)
  else
    set refClass to (className() of argFilePath) as text
    if refClass contains "NSPathStore2" then
log "NSPathStore2です"
      set ocidArgFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:argFilePath)
    else if refClass contains "NSCFString" then
log "NSCFStringです"
      set ocidArgFilePath to argFilePath's stringByStandardizingPath
      set ocidArgFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:ocidArgFilePath)
    else if refClass contains "NSURL" then
      set ocidArgFilePathURL to argFilePath
log "NSURLです"
    end if
  end if
  #########################################
  ###
  -->false
  set ocidFalse to (refMe's NSNumber's numberWithBool:false)'s boolValue
  -->true
  set ocidTrue to (refMe's NSNumber's numberWithBool:true)'s boolValue
  #########################################
  ###NSURLがエイリアス実在するか?
  set ocidArgFilePath to ocidArgFilePathURL's |path|()
  set boolFileAlias to appFileManager's fileExistsAtPath:(ocidArgFilePath)
  ###パス先が実在しないなら処理はここまで
  if boolFileAlias = false then
log ocidArgFilePath as text
log "処理中止 パス先が実在しない"
return false
  end if
  #########################################
  ###NSURLがディレクトリなのか?ファイルなのか?
  set listBoolDir to ocidArgFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLIsDirectoryKey) |error|:(reference)
  # log (item 1 of listBoolDir)
  # log (item 2 of listBoolDir)
  # log (item 3 of listBoolDir)
  if (item 2 of listBoolDir) = ocidTrue then
    #########################################
log "ディレクトリです"
log ocidArgFilePathURL's |path| as text
    ##内包リスト
    set listResult to appFileManager's contentsOfDirectoryAtURL:ocidArgFilePathURL includingPropertiesForKeys:{refMe's NSURLPathKey} options:0 |error|:(reference)
    ###結果
    set ocidContentsPathURLArray to item 1 of listResult
    ###リストの数だけ繰り返し
    repeat with itemContentsPathURL in ocidContentsPathURLArray
      ###ゴミ箱に入れる
      set listResult to (appFileManager's trashItemAtURL:itemContentsPathURL resultingItemURL:(missing value) |error|:(reference))
    end repeat
  else
    #########################################
log "ファイルです"
    set listBoolDir to ocidArgFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLIsAliasFileKey) |error|:(reference)
    if (item 2 of listBoolDir) = ocidTrue then
log "エイリアスは処理しません"
return false
    end if
    set listBoolDir to ocidArgFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLIsSymbolicLinkKey) |error|:(reference)
    if (item 2 of listBoolDir) = ocidTrue then
log "シンボリックリンクは処理しません"
return false
    end if
    set listBoolDir to ocidArgFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLIsSystemImmutableKey) |error|:(reference)
    if (item 2 of listBoolDir) = ocidTrue then
log "システムファイルは処理しません"
return false
    end if
    ###ファイルをゴミ箱に入れる
    set listResult to (appFileManager's trashItemAtURL:ocidArgFilePathURL resultingItemURL:(missing value) |error|:(reference))
  end if
return true
end doMoveToTrash


|

[Distiller]強制終了


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use framework "UniformTypeIdentifiers"

use scripting additions
property refMe : a reference to current application

try
  tell application id "com.adobe.distiller" to quit
end try
set ocidRunningApplication to refMe's NSRunningApplication
set ocidAppArray to (ocidRunningApplication's runningApplicationsWithBundleIdentifier:("com.adobe.distiller"))
###複数起動時も順番に終了
repeat with itemAppArray in ocidAppArray
  ###終了
itemAppArray's terminate()
end repeat
##1秒まって終了を確認
delay 1
##終了できない場合は強制終了
repeat with itemAppArray in ocidAppArray
  set boolTerminate to itemAppArray's terminated
  if boolTerminate = false then
itemAppArray's forceTerminate()
  end if
end repeat
##使いたくないがしかたがない
try
do shell script "/usr/bin/killall Distiller"
end try
return

|

[Distiller]起動をまつ


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
# テキスト系式のapplescriptだとコンパイル時に起動するのでダメ
# コンパイル済みのscpt系式で保存してください
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.5"
use framework "Foundation"
use framework "AppKit"
use scripting additions

tell application id "com.adobe.distiller" to launch

##起動待ち最大10秒
repeat 20 times
  tell application id "com.adobe.distiller"
    set boolFrontmost to frontmost as boolean
  end tell
  if boolFrontmost is false then
    tell application id "com.adobe.distiller"
activate
    end tell
delay 0.5
  else if boolFrontmost is true then
    exit repeat
  end if
end repeat



|

[Distiller]Psファイルをオプション選んでPDFに変換


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use framework "Foundation"
use framework "AppKit"
use scripting additions
property refMe : a reference to current application

##ファイルパスの格納用のリスト
set ocidFilePathURLArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
#ファイル収集のオプション(非表示無視)
set ocidOption to (refMe's NSDirectoryEnumerationSkipsHiddenFiles)
#収集するキー(パスと名前)
set ocidKeysArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
ocidKeysArray's addObject:(refMe's NSURLPathKey)
ocidKeysArray's addObject:(refMe's NSURLNameKey)
######
#収集するパス
set listDirPath to {"Adobe/Adobe PDF/Settings", "Adobe/Adobe PDF/Extras"}
#ローカルドメインの収集
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSApplicationSupportDirectory) inDomains:(refMe's NSLocalDomainMask))
set ocidLocalAppSupDirPathURL to ocidURLsArray's firstObject()
#収集して
repeat with itemDirPath in listDirPath
  set ocidChkDirPathURL to (ocidLocalAppSupDirPathURL's URLByAppendingPathComponent:(itemDirPath) isDirectory:(true))
  set lisrResponse to (appFileManager's contentsOfDirectoryAtURL:(ocidChkDirPathURL) includingPropertiesForKeys:(ocidKeysArray) options:(ocidOption) |error|:(reference))
  if (item 2 of lisrResponse) = (missing value) then
    set ocidGetFilePathURLArray to (item 1 of lisrResponse)
  else if (item 2 of lisrResponse) ≠ (missing value) then
log (item 2 of lisrResponse)'s localizedDescription() as text
  end if
  ##リストに追加
(ocidFilePathURLArray's addObjectsFromArray:(ocidGetFilePathURLArray))
end repeat
######
#ユーザードメインの収集
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSApplicationSupportDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidLocalAppSupDirPathURL to ocidURLsArray's firstObject()
#収集して
repeat with itemDirPath in listDirPath
  set ocidChkDirPathURL to (ocidLocalAppSupDirPathURL's URLByAppendingPathComponent:(itemDirPath) isDirectory:(true))
  set lisrResponse to (appFileManager's contentsOfDirectoryAtURL:(ocidChkDirPathURL) includingPropertiesForKeys:(ocidKeysArray) options:(ocidOption) |error|:(reference))
  if (item 2 of lisrResponse) = (missing value) then
    set ocidGetFilePathURLArray to (item 1 of lisrResponse)
  else if (item 2 of lisrResponse) ≠ (missing value) then
log (item 2 of lisrResponse)'s localizedDescription() as text
  end if
  ##リストに追加
(ocidFilePathURLArray's addObjectsFromArray:(ocidGetFilePathURLArray))
end repeat
######
##ファイル名とパスのレコードを作成
set ocidName2URLDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
repeat with itemFilePathURL in ocidFilePathURLArray
  set ocidFileName to itemFilePathURL's lastPathComponent()
(ocidName2URLDict's setObject:(itemFilePathURL) forKey:(ocidFileName))
end repeat
######
##ファイル名だけのリスト
set ocidAllKeys to ocidName2URLDict's allKeys()
##ソート
set ocidFileNameArray to ocidAllKeys's sortedArrayUsingSelector:("localizedStandardCompare:")
set listFileNameArray to ocidFileNameArray as list
#最小ファイルサイズが何番目か?
set numIndex to ocidFileNameArray's indexOfObject:("Smallest File Size.joboptions")
set numIndex to (numIndex + 1) as integer
##################
#ダイアログ
set strName to (name of current application) as text
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
###
set strTitle to ("選んでください") as text
set strPrompt to ("ジョブオプションを選んでください") as text
try
  set listResponse to (choose from list listFileNameArray with title strTitle with prompt strPrompt default items (item numIndex of listFileNameArray) OK button name "OK" cancel button name "キャンセル" without multiple selections allowed and empty selection allowed) as list
on error
log "エラーしました"
return "エラーしました"
end try
if (item 1 of listResponse) is false then
return "キャンセルしましたA"
else if (item 1 of listResponse) is "キャンセル" then
return "キャンセルしましたB"
else
  set strResponse to (item 1 of listResponse) as text
end if
##
set ocidChooseFilePathURL to ocidName2URLDict's objectForKey:(strResponse)
set strChooseFilePath to ocidChooseFilePathURL's |path| as text
set strAdobePDFSettingsPath to strChooseFilePath as text

###ダイアログ
set strName to (name of current application) as text
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias

set listUTI to {"com.adobe.postscript"}
set strMes to ("ファイルを選んでください") as text
set strPrompt to ("ファイルを選んでください") as text
try
  ### ファイル選択時
  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
on error
log "エラーしました"
return "エラーしました"
end try

set strPsFilePath to (POSIX path of aliasFilePath) as text
set ocidFilePathStr to refMe's NSString's stringWithString:(strPsFilePath)
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
set ocidContainerDirPathURL to ocidFilePathURL's URLByDeletingLastPathComponent()
set strDestinationPath to ocidContainerDirPathURL's |path| as text


tell application "Acrobat Distiller" to launch
##起動待ち最大10秒
repeat 20 times
  tell application id "com.adobe.distiller"
    set boolFrontmost to frontmost as boolean
  end tell
  if boolFrontmost is false then
    tell application id "com.adobe.distiller"
activate
    end tell
delay 0.5
  else if boolFrontmost is true then
    exit repeat
  end if
end repeat

tell application "Acrobat Distiller"
Distill sourcePath strPsFilePath destinationPath strDestinationPath adobePDFSettingsPath strAdobePDFSettingsPath
end tell

tell application "Acrobat Distiller"
quit
end tell

|

[macOS13.3]NUP(nIN1)集約PDF作成時の余白0

印刷画面から余白0の集約PDFを作成する場合

『たぶん』OS側の不具合だと思いますが
(PDF生成時は用紙設定時の余白を考慮しないって言われたらアレだけど…)
PDFをページ集約印刷する際の余白0
現時点では、一旦PostScriptで出力してPDF化しないと『余白』入ります。

前提条件:余白0に設定されている用紙設定が必要です。

PostScriptをPDF化するには
1:Acrobat Distillerを使う
2:Skim等のサードパーティ製アプリケーションを使う
3:cupsfilterを使う 
4:オンラインサービスを利用する※
などの方法があります。
※業務利用の場合オンラインサービスに業務内容の一部をアップロードする事自体
セキュリティ違反となる場合がありあす。利用に際しては、職場のセキュリティ担当者の許可が必要です。



余白0の用紙設定を使う
1:余白設定0のPPDを使ったプリンタを作成する
2:自分で余白0の用紙設定を作る

どちらか


PostScriptをPDF化
1:Acrobat Distillerを使う
アカウントは有料ですがインストールダケはできます
https://helpx.adobe.com/jp/acrobat/kb/acrobat-dc-downloads.html
2:Skim等のサードパーティ製アプリケーションを使う
https://quicktimer.cocolog-nifty.com/icefloe/2023/04/post-b7beb6.html
3:cupsfilterを使う 
https://quicktimer.cocolog-nifty.com/icefloe/2023/02/post-26866c.html


余白0の用紙設定を使う
1:余白設定0のPPD
[PPDs]AcrobatPPDsをダウンロードして利用可能にする
https://quicktimer.cocolog-nifty.com/icefloe/2023/04/post-089275.html
2:自分で余白0の用紙設定を作る
https://quicktimer.cocolog-nifty.com/icefloe/2023/04/post-8097d1.html


PostScriptファイルを生成する
プリンタ画面からPostScriptファイルを生成する
Screencapture1720x639

|

[Distiller]PSファイルをPDFに変換する その2

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7

use AppleScript version "2.8"
use framework "Foundation"
use scripting additions



###Acrobat Distillerフォルダを作る
tell application "Finder"
set aliasShared to path to shared documents from user domain
set boolFolderExists to (exists of (folder "Acrobat Distiller" of folder aliasShared)) as boolean
if boolFolderExists is false then
make new folder at aliasShared with properties {name:"Acrobat Distiller", owner privileges:"read write", group privileges:"read write", everyones privileges:"read write", comment:"このフォルダはAcrobat Distiller用のフォルダです", description:"スクリプトが生成したフォルダです", label index:3}
end if
set aliasDistillerDir to folder "Acrobat Distiller" of folder aliasShared as alias
set strDistillerDir to POSIX path of aliasDistillerDir as text
end tell
###inフォルダを作る
tell application "Finder"
set boolFolderExists to (exists of (folder "in" of folder aliasDistillerDir)) as boolean
if boolFolderExists is false then
make new folder at aliasDistillerDir with properties {name:"in", owner privileges:"read write", group privileges:"read write", everyones privileges:"read write", comment:"このフォルダはAcrobat Distiller用のフォルダです", description:"スクリプトが生成したフォルダです", label index:3}
end if
set aliasDistillerInDir to folder "in" of folder aliasDistillerDir as alias
set strDistillerInDir to POSIX path of aliasDistillerInDir as text
end tell
###outフォルダを作る
tell application "Finder"
set boolFolderExists to (exists of (folder "out" of folder aliasDistillerDir)) as boolean
if boolFolderExists is false then
make new folder at aliasDistillerDir with properties {name:"out", owner privileges:"read write", group privileges:"read write", everyones privileges:"read write", comment:"このフォルダはAcrobat Distiller用のフォルダです", description:"スクリプトが生成したフォルダです", label index:3}
end if
set aliasDistilleroutDir to folder "out" of folder aliasDistillerDir as alias
set strDistilleroutDir to POSIX path of aliasDistilleroutDir as text
end tell
###ファイルを選択
set aliasFile to (choose file with prompt "PSファイルを選んでください" default location aliasDistillerDir of type {"com.adobe.postscript"} without invisibles, showing package contents and multiple selections allowed) as alias

###Print.joboptionsの一覧を取得
set strCommandText to ("ls -d /Library/Application\\ Support/Adobe/Adobe\\ PDF/Settings/*")
set strJobOption to do shell script strCommandText
set AppleScript's text item delimiters to "\r"
set listJobOption to every text item of strJobOption


set strCommandText to ("ls -d $HOME/Library/Application\\ Support/Adobe/Adobe\\ PDF/Settings/*")
set strUserJobOption to do shell script strCommandText
set AppleScript's text item delimiters to "\r"
set listUserJobOption to every text item of strUserJobOption

set listJobOption to listJobOption & listUserJobOption



###Print.joboptionsを選択
try
set objResponse to (choose from list listJobOption with title "Print.joboptions" with prompt "ジョブオプションを選んでください" default items (item 1 of listJobOption) OK button name "OK" cancel button name "キャンセル" with multiple selections allowed without empty selection allowed)
on error
log "エラーしました"
return
end try
if objResponse is false then
return
end if
set theResponse to (objResponse) as text

###ディスティラでPDF
tell application "Acrobat Distiller"
properties
Distill sourcePath (POSIX path of aliasFile) destinationPath strDistilleroutDir adobePDFSettingsPath theResponse
end tell
###OUTフォルダを開く
tell application "Finder"
make new Finder window to (aliasDistilleroutDir)
end tell

|

より以前の記事一覧

その他のカテゴリー

Accessibility Acrobat Acrobat 2020 Acrobat AddOn Acrobat Annotation Acrobat ARMDC Acrobat AV2 Acrobat BookMark Acrobat Classic Acrobat DC Acrobat Dialog Acrobat Distiller Acrobat Form Acrobat JS Acrobat Manifest Acrobat Menu Acrobat Open Acrobat Plugin Acrobat Preferences Acrobat Preflight Acrobat python Acrobat Reader Acrobat SCA Acrobat SCA Updater Acrobat Sequ Acrobat Sign Acrobat Stamps Acrobat Watermark Acrobat Windows Acrobat Windows Reader Admin Admin Account Admin Apachectl Admin configCode Admin Device Management Admin LaunchServices Admin Locationd Admin loginitem Admin Maintenance Admin Mobileconfig Admin Permission Admin Pkg Admin Power Management Admin Printer Admin SetUp Admin SMB Admin Support Admin System Information Admin Tools Admin Users Admin Volumes Adobe Adobe FDKO Adobe RemoteUpdateManager AppKit Apple AppleScript AppleScript do shell script AppleScript List AppleScript ObjC AppleScript Osax AppleScript PDF AppleScript Pictures AppleScript record AppleScript Script Editor AppleScript Script Menu AppleScript Shortcuts AppleScript Shortcuts Events AppleScript System Events AppleScript System Events Plist AppleScript Video Applications AppStore Archive Attributes Automator BackUp Barcode Barcode QR Barcode QR Decode Bash Basic Basic Path Bluetooth BOX Browser Calendar CD/DVD Choose Chrome CIImage CityCode CloudStorage Color com.apple.LaunchServices.OpenWith Console Contacts CotEditor CURL current application Date&Time delimiters Desktop Device Diff Disk Dock DropBox Droplet eMail Encode % Encode Decode Encode UTF8 Error EXIFData ffmpeg File Finder Firefox Folder FolderAction Fonts GIF github Guide HTML HTML Entity Icon Illustrator Image Events Image2PDF ImageOptim iPhone iWork Javascript Jedit Json Label Leading Zero List locationd LRC lsappinfo LSSharedFileList m3u8 Mail MakePDF Map Math Media Media AVAsset Media AVconvert Media AVFoundation Media AVURLAsset Media Movie Media Music Memo Messages Microsoft Microsoft Edge Microsoft Excel Mouse Music NetWork Notes NSArray NSArray Sort NSBezierPath NSBitmapImageRep NSBundle NSCFBoolean NSCharacterSet NSColor NSColorList NSData NSDecimalNumber NSDictionary NSError NSEvent NSFileAttributes NSFileManager NSFileManager enumeratorAtURL NSFont NSFontManager NSGraphicsContext NSImage NSIndex NSKeyedArchiver NSKeyedUnarchiver NSLocale NSMutableArray NSMutableDictionary NSMutableString NSNotFound NSNumber NSOpenPanel NSPasteboard NSpoint NSPredicate NSPrintOperation NSRange NSRect NSRegularExpression NSRunningApplication NSScreen NSSize NSString NSString stringByApplyingTransform NSStringCompareOptions NSTask NSTimeZone NSURL NSURL File NSURLBookmark NSURLComponents NSURLResourceKey NSURLSession NSUserDefaults NSUUID NSView NSWorkspace Numbers OAuth OneDrive PDF PDFAnnotation PDFAnnotationWidget PDFContext PDFDisplayBox PDFDocumentPermissions PDFImageRep PDFKit PDFnUP PDFOutline perl Photoshop PlistBuddy pluginkit postalcode PostScript prefPane Preview Python QuickLook QuickTime ReadMe Regular Expression Reminders ReName Repeat RTF Safari SaveFile ScreenCapture ScreenSaver SF Symbols character id SF Symbols Entity sips Skype Slack Sound Spotlight sqlite SRT StandardAdditions Swift System Settings TCC 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 webarchive webp Wifi Windows XML XML EPUB XML OPML XML Plist XML RSS XML savedSearch XML SVG XML TTML XML webloc XML XMP YouTube zoom