Image2PDF

[PDF化]複数の画像ファイルをPDFにまとめる(解像度を72ppi化)

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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use framework "PDFKit"
use framework "Quartz"
use framework "QuartzCore"
use scripting additions

property refMe : a reference to current application
set appFileManager to refMe's NSFileManager's defaultManager()


#####設定項目 短辺の長さmm
set numShortSize to 210 as integer
###################################
###ポイント換算
set numMaxPtSize to numShortSize * 2.83465 as number
###小数点2桁に(ここは好みの問題)
set numMaxPtSize to ((round (numMaxPtSize * 100) rounding down) / 100) as number
###################################
#####ファイル選択ダイアログ
###################################
###ダイアログのデフォルト
set ocidUserDesktopPath to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set aliasDefaultLocation to ocidUserDesktopPath as alias
set listChooseFileUTI to {"public.image"}
set strPromptText to "画像ファイルを選んでください" as text
###ダイアログを前面に出す
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder"
    activate
    set listAliasFilePath to (choose file strPromptText with prompt strPromptText default location (aliasDefaultLocation) of type listChooseFileUTI with multiple selections allowed without invisibles and showing package contents) as list
  end tell
else
  tell current application
    activate
    set listAliasFilePath to (choose file strPromptText with prompt strPromptText default location (aliasDefaultLocation) of type listChooseFileUTI with multiple selections allowed without invisibles and showing package contents) as list
  end tell
end if
#############################################
##まずはリストをファイル名順にソート
#############################################
###初期化
set ocidFilePathArray to refMe's NSMutableArray's alloc()'s initWithCapacity:0
repeat with itemAliasFilePath in listAliasFilePath
  set strFilePath to POSIX path of itemAliasFilePath as text
  (ocidFilePathArray's addObject:strFilePath)
end repeat
###ファイルリストをソート
set ocidSortedArray to (ocidFilePathArray's sortedArrayUsingSelector:"compare:")
#############################################
#####保存先 ダイアログ
#############################################
###並び替えたリストの最初のパス
set strFirstFilePath to ocidSortedArray's objectAtIndex:0
set ocidFilePathStr to refMe's NSString's stringWithString:strFirstFilePath
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 aliasDefaultLocation to ocidContainerDirPathURL as alias
####ファイル名を取得
set ocidFileName to ocidContainerDirPathURL's lastPathComponent()
####ファイル名から拡張子を取っていわゆるベースファイル名を取得
set ocidPrefixName to ocidFileName's stringByDeletingPathExtension
###ファイル名
set strPrefixName to ocidPrefixName as text
###拡張子
set strFileExtension to "pdf"
###ダイアログに出すファイル名
set strDefaultName to (strPrefixName & ".image." & strFileExtension) as text
set strPromptText to "名前を決めてください"
set strPromptMes to "名前を決めてください"
###選んだファイルの同階層をデフォルトの場合
#set aliasDefaultLocation to ocidContainerDirPathURL as alias
###選んだファイルの一つ上の階層の場合
set ocidDefaultLocation to ocidContainerDirPathURL's URLByDeletingLastPathComponent()
set aliasDefaultLocation to ocidDefaultLocation as alias
####デスクトップの場合
##set aliasDefaultLocation to (path to desktop folder from user domain) as alias
####ファイル名ダイアログ
####実在しない『はず』なのでas «class furl»
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder"
    activate
    set aliasSaveFilePath to (choose file name strPromptMes default location aliasDefaultLocation default name strDefaultName with prompt strPromptText) as «class furl»
  end tell
else
  tell current application
    activate
    set aliasSaveFilePath to (choose file name strPromptMes default location aliasDefaultLocation default name strDefaultName with prompt strPromptText) as «class furl»
  end tell
end if
set strSaveFilePath to POSIX path of aliasSaveFilePath as text
set ocidSaveFilePathStr to refMe's NSString's stringWithString:strSaveFilePath
set ocidSaveFilePath to ocidSaveFilePathStr's stringByStandardizingPath()
set ocidContainerSaveDirPath to ocidSaveFilePath's stringByDeletingLastPathComponent()
set ocidSaveFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:ocidSaveFilePath isDirectory:false
###拡張子取得
set strFileExtensionName to ocidSaveFilePathURL's pathExtension() as text
###ダイアログで拡張子を取っちゃった時対策
if strFileExtensionName is not strFileExtension then
  set ocidSaveFilePathURL to ocidSaveFilePathURL's URLByAppendingPathExtension:strFileExtension
end if
#############################################
####本処理
#############################################
####PDFドキュメント初期化
set ocidActivDoc to refMe's PDFDocument's alloc()'s init()
###画像のファイル数 使わない画像の数でrepeatするときはこれ
set numCntAllFileNo to (ocidSortedArray count) as integer
###画像のカウンター初期化
set numFileCnt to 0 as integer
###ファイルリストを順番に処理
repeat with itemSortedArray in ocidSortedArray
  ###########ファイルから
  set strFilePath to itemSortedArray as text
  set ocidFilePathStr to (refMe's NSString's stringWithString:strFilePath)
  set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
  set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false)
  ###########画像読み込み
  set ocidImageData to (refMe's NSImage's alloc()'s initWithContentsOfURL:ocidFilePathURL)
  ####ピクセルサイズを取得
  set ocidImageRepArray to ocidImageData's representations()
  set ocidBitmapRep to (ocidImageRepArray's objectAtIndex:0)
  set numPixW to ocidBitmapRep's pixelsWide() as integer
  set numPixH to ocidBitmapRep's pixelsHigh() as integer
  #####サイズをピクセルサイズに設定=72ppi
  set ocidNewSize to refMe's NSSize's NSMakeSize(numPixW, numPixH)
  (ocidBitmapRep's setSize:ocidNewSize)
  ##########################################
  ####新しく↑で作ったサイズで新しいイメージを初期化して
  set ocidNewImageData to (refMe's NSImage's alloc()'s initWithSize:ocidNewSize)
  ####このイメージにサイズ変更したNSBitmapImageRepを入れる
  (ocidNewImageData's addRepresentation:ocidBitmapRep)
  ###PDFページに
  set ocidPdfPage to (refMe's PDFPage's alloc()'s initWithImage:ocidNewImageData)
  ###ページに挿入する
  (ocidActivDoc's insertPage:ocidPdfPage atIndex:numFileCnt)
  ####次ページ用にカウントアップ
  set numFileCnt to numFileCnt + 1 as integer
  set ocidNewImageData to ""
  set ocidImageData to ""
  set ocidPdfPage to ""
  set ocidDistImage to ""
end repeat

####ファイルを保存する
set boolResponse to ocidActivDoc's writeToURL:ocidSaveFilePathURL


####保存先を開く
set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
set boolSelectFileResults to appSharedWorkspace's selectFile:ocidSaveFilePath inFileViewerRootedAtPath:ocidContainerSaveDirPath

|

[PDF化]複数の画像ファイルをPDFにまとめる(解像度サイズ)

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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use framework "PDFKit"
use framework "Quartz"
use framework "QuartzCore"
use scripting additions

property refMe : a reference to current application
set appFileManager to refMe's NSFileManager's defaultManager()


#####設定項目 短辺の長さmm
set numShortSize to 210 as integer


###################################
###ポイント換算
set numMaxPtSize to numShortSize * 2.83465 as number
###小数点2桁に(ここは好みの問題)
set numMaxPtSize to ((round (numMaxPtSize * 100) rounding down) / 100) as number
###################################
#####ファイル選択ダイアログ
###################################
###ダイアログのデフォルト
set ocidUserDesktopPath to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set aliasDefaultLocation to ocidUserDesktopPath as alias
set listChooseFileUTI to {"public.image"}
set strPromptText to "画像ファイルを選んでください" as text
###ダイアログを前面に出す
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder"
    activate
    set listAliasFilePath to (choose file strPromptText with prompt strPromptText default location (aliasDefaultLocation) of type listChooseFileUTI with multiple selections allowed without invisibles and showing package contents) as list
  end tell
else
  tell current application
    activate
    set listAliasFilePath to (choose file strPromptText with prompt strPromptText default location (aliasDefaultLocation) of type listChooseFileUTI with multiple selections allowed without invisibles and showing package contents) as list
  end tell
end if
#############################################
##まずはリストをファイル名順にソート
#############################################
###初期化
set ocidFilePathArray to refMe's NSMutableArray's alloc()'s initWithCapacity:0
repeat with itemAliasFilePath in listAliasFilePath
  set strFilePath to POSIX path of itemAliasFilePath as text
  (ocidFilePathArray's addObject:strFilePath)
end repeat
###ファイルリストをソート
set ocidSortedArray to (ocidFilePathArray's sortedArrayUsingSelector:"compare:")
#############################################
#####保存先 ダイアログ
#############################################
###並び替えたリストの最初のパス
set strFirstFilePath to ocidSortedArray's objectAtIndex:0
set ocidFilePathStr to refMe's NSString's stringWithString:strFirstFilePath
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 aliasDefaultLocation to ocidContainerDirPathURL as alias
####ファイル名を取得
set ocidFileName to ocidContainerDirPathURL's lastPathComponent()
####ファイル名から拡張子を取っていわゆるベースファイル名を取得
set ocidPrefixName to ocidFileName's stringByDeletingPathExtension
###ファイル名
set strPrefixName to ocidPrefixName as text
###拡張子
set strFileExtension to "pdf"
###ダイアログに出すファイル名
set strDefaultName to (strPrefixName & ".image." & strFileExtension) as text
set strPromptText to "名前を決めてください"
set strPromptMes to "名前を決めてください"
###選んだファイルの同階層をデフォルトの場合
#set aliasDefaultLocation to ocidContainerDirPathURL as alias
###選んだファイルの一つ上の階層の場合
set ocidDefaultLocation to ocidContainerDirPathURL's URLByDeletingLastPathComponent()
set aliasDefaultLocation to ocidDefaultLocation as alias
####デスクトップの場合
##set aliasDefaultLocation to (path to desktop folder from user domain) as alias
####ファイル名ダイアログ
####実在しない『はず』なのでas «class furl»
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder"
    activate
    set aliasSaveFilePath to (choose file name strPromptMes default location aliasDefaultLocation default name strDefaultName with prompt strPromptText) as «class furl»
  end tell
else
  tell current application
    activate
    set aliasSaveFilePath to (choose file name strPromptMes default location aliasDefaultLocation default name strDefaultName with prompt strPromptText) as «class furl»
  end tell
end if
set strSaveFilePath to POSIX path of aliasSaveFilePath as text
set ocidSaveFilePathStr to refMe's NSString's stringWithString:strSaveFilePath
set ocidSaveFilePath to ocidSaveFilePathStr's stringByStandardizingPath()
set ocidContainerSaveDirPath to ocidSaveFilePath's stringByDeletingLastPathComponent()
set ocidSaveFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:ocidSaveFilePath isDirectory:false
###拡張子取得
set strFileExtensionName to ocidSaveFilePathURL's pathExtension() as text
###ダイアログで拡張子を取っちゃった時対策
if strFileExtensionName is not strFileExtension then
  set ocidSaveFilePathURL to ocidSaveFilePathURL's URLByAppendingPathExtension:strFileExtension
end if
#############################################
####本処理
#############################################
####PDFドキュメント初期化
set ocidActivDoc to refMe's PDFDocument's alloc()'s init()
###画像のファイル数 使わない画像の数でrepeatするときはこれ
set numCntAllFileNo to (ocidSortedArray count) as integer
###画像のカウンター初期化
set numFileCnt to 0 as integer
###ファイルリストを順番に処理
repeat with itemSortedArray in ocidSortedArray
  ###########ファイルから
  set strFilePath to itemSortedArray as text
  set ocidFilePathStr to (refMe's NSString's stringWithString:strFilePath)
  set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
  set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false)
  ###########画像読み込み
  set ocidImageData to (refMe's NSImage's alloc()'s initWithContentsOfURL:ocidFilePathURL)
  ###PDFページに
  set ocidPdfPage to (refMe's PDFPage's alloc()'s initWithImage:ocidImageData)
  ###ページに挿入する
  (ocidActivDoc's insertPage:ocidPdfPage atIndex:numFileCnt)
  ####次ページ用にカウントアップ
  set numFileCnt to numFileCnt + 1 as integer
  set ocidNewImageData to ""
  set ocidImageData to ""
  set ocidPdfPage to ""
  set ocidDistImage to ""
end repeat

####ファイルを保存する
set boolResponse to ocidActivDoc's writeToURL:ocidSaveFilePathURL


####保存先を開く
set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
set boolSelectFileResults to appSharedWorkspace's selectFile:ocidSaveFilePath inFileViewerRootedAtPath:ocidContainerSaveDirPath

|

[PDF化]複数の画像ファイルをPDFにまとめる(短辺サイズ指定)

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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use framework "PDFKit"
use framework "Quartz"
use framework "QuartzCore"
use scripting additions

property refMe : a reference to current application
set appFileManager to refMe's NSFileManager's defaultManager()


#####設定項目 短辺の長さmm
set numShortSize to 210 as integer


###################################
###ポイント換算
set numMaxPtSize to numShortSize * 2.83465 as number
###小数点2桁に(ここは好みの問題)
set numMaxPtSize to ((round (numMaxPtSize * 100) rounding down) / 100) as number
###################################
#####ファイル選択ダイアログ
###################################
###ダイアログのデフォルト
set ocidUserDesktopPath to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set aliasDefaultLocation to ocidUserDesktopPath as alias
set listChooseFileUTI to {"public.image"}
set strPromptText to "画像ファイルを選んでください" as text
###ダイアログを前面に出す
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder"
    activate
    set listAliasFilePath to (choose file strPromptText with prompt strPromptText default location (aliasDefaultLocation) of type listChooseFileUTI with multiple selections allowed without invisibles and showing package contents) as list
  end tell
else
  tell current application
    activate
    set listAliasFilePath to (choose file strPromptText with prompt strPromptText default location (aliasDefaultLocation) of type listChooseFileUTI with multiple selections allowed without invisibles and showing package contents) as list
  end tell
end if
#############################################
##まずはリストをファイル名順にソート
#############################################
###初期化
set ocidFilePathArray to refMe's NSMutableArray's alloc()'s initWithCapacity:0
repeat with itemAliasFilePath in listAliasFilePath
  set strFilePath to POSIX path of itemAliasFilePath as text
  (ocidFilePathArray's addObject:strFilePath)
end repeat
###ファイルリストをソート
set ocidSortedArray to (ocidFilePathArray's sortedArrayUsingSelector:"compare:")
#############################################
#####保存先 ダイアログ
#############################################
###並び替えたリストの最初のパス
set strFirstFilePath to ocidSortedArray's objectAtIndex:0
set ocidFilePathStr to refMe's NSString's stringWithString:strFirstFilePath
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 aliasDefaultLocation to ocidContainerDirPathURL as alias
####ファイル名を取得
set ocidFileName to ocidContainerDirPathURL's lastPathComponent()
####ファイル名から拡張子を取っていわゆるベースファイル名を取得
set ocidPrefixName to ocidFileName's stringByDeletingPathExtension
###ファイル名
set strPrefixName to ocidPrefixName as text
###拡張子
set strFileExtension to "pdf"
###ダイアログに出すファイル名
set strDefaultName to (strPrefixName & ".image." & strFileExtension) as text
set strPromptText to "名前を決めてください"
set strPromptMes to "名前を決めてください"
###選んだファイルの同階層をデフォルトの場合
#set aliasDefaultLocation to ocidContainerDirPathURL as alias
###選んだファイルの一つ上の階層の場合
set ocidDefaultLocation to ocidContainerDirPathURL's URLByDeletingLastPathComponent()
set aliasDefaultLocation to ocidDefaultLocation as alias
####デスクトップの場合
##set aliasDefaultLocation to (path to desktop folder from user domain) as alias
####ファイル名ダイアログ
####実在しない『はず』なのでas «class furl»
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder"
    activate
    set aliasSaveFilePath to (choose file name strPromptMes default location aliasDefaultLocation default name strDefaultName with prompt strPromptText) as «class furl»
  end tell
else
  tell current application
    activate
    set aliasSaveFilePath to (choose file name strPromptMes default location aliasDefaultLocation default name strDefaultName with prompt strPromptText) as «class furl»
  end tell
end if
set strSaveFilePath to POSIX path of aliasSaveFilePath as text
set ocidSaveFilePathStr to refMe's NSString's stringWithString:strSaveFilePath
set ocidSaveFilePath to ocidSaveFilePathStr's stringByStandardizingPath()
set ocidContainerSaveDirPath to ocidSaveFilePath's stringByDeletingLastPathComponent()
set ocidSaveFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:ocidSaveFilePath isDirectory:false
###拡張子取得
set strFileExtensionName to ocidSaveFilePathURL's pathExtension() as text
###ダイアログで拡張子を取っちゃった時対策
if strFileExtensionName is not strFileExtension then
  set ocidSaveFilePathURL to ocidSaveFilePathURL's URLByAppendingPathExtension:strFileExtension
end if
#############################################
####本処理
#############################################
####PDFドキュメント初期化
set ocidActivDoc to refMe's PDFDocument's alloc()'s init()
###画像のファイル数 使わない画像の数でrepeatするときはこれ
set numCntAllFileNo to (ocidSortedArray count) as integer
###画像のカウンター初期化
set numFileCnt to 0 as integer
###ファイルリストを順番に処理
repeat with itemSortedArray in ocidSortedArray
  ###########ファイルから
  set strFilePath to itemSortedArray as text
  set ocidFilePathStr to (refMe's NSString's stringWithString:strFilePath)
  set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
  set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false)
  ###########画像読み込み
  set ocidImageData to (refMe's NSImage's alloc()'s initWithContentsOfURL:ocidFilePathURL)
  set ocidImageSize to ocidImageData's |size|()
  set numW to ocidImageSize's width
  set numH to ocidImageSize's height
  ####短辺を指定したmmMAXで設定
  if numW > numH then
    log "横方"
    set numNewH to numMaxPtSize as number
    set numPerHW to numNewH / numH as number
    set numNewW to numW * numPerHW as number
  else if numW < numH then
    log "縦型"
    set numNewW to numMaxPtSize as number
    set numPerHW to numNewW / numW as number
    set numNewH to numH * numPerHW as number
  else
    log "正方形"
    set numNewW to numMaxPtSize as number
    set numPerHW to numNewW / numW as number
    set numNewH to numH * numPerHW as number
  end if
  set ocidNewSize to refMe's NSSize's NSMakeSize(numNewW, numNewH)
  ###中間ファイルとしてのTIFFに変換
  set ocidDistImage to ocidImageData's TIFFRepresentation()
  set ocidBmpImageRep to (refMe's NSBitmapImageRep's imageRepWithData:ocidDistImage)
  ##NSBitmapImageRepのサイズを変更
  (ocidBmpImageRep's setSize:ocidNewSize)
  ####新しく↑で作ったサイズで新しいイメージを初期化して
  set ocidNewImageData to (refMe's NSImage's alloc()'s initWithSize:ocidNewSize)
  ####このイメージにサイズ変更したNSBitmapImageRepを入れる
  (ocidNewImageData's addRepresentation:ocidBmpImageRep)
  ###PDFページに
  set ocidPdfPage to (refMe's PDFPage's alloc()'s initWithImage:ocidNewImageData)
  ###ページに挿入する
  (ocidActivDoc's insertPage:ocidPdfPage atIndex:numFileCnt)
  ####次ページ用にカウントアップ
  set numFileCnt to numFileCnt + 1 as integer
  set ocidNewImageData to ""
  set ocidImageData to ""
  set ocidPdfPage to ""
end repeat

####ファイルを保存する
set boolResponse to ocidActivDoc's writeToURL:ocidSaveFilePathURL


####保存先を開く
set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
set boolSelectFileResults to appSharedWorkspace's selectFile:ocidSaveFilePath inFileViewerRootedAtPath:ocidContainerSaveDirPath

|

[単ページ]イメージファイルをPDFに変換(短辺サイズ指定)

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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use framework "PDFKit"
use framework "Quartz"
use framework "QuartzCore"
use scripting additions

property refMe : a reference to current application
set appFileManager to refMe's NSFileManager's defaultManager()

#####設定項目 短辺の長さmm
set numShortSize to 210 as integer


###################################
###ポイント換算
set numMaxPtSize to numShortSize * 2.83465 as number
###小数点2桁に(ここは好みの問題)
set numMaxPtSize to ((round (numMaxPtSize * 100) rounding down) / 100) as number

###################################
#####ファイル選択ダイアログ
###################################
###ダイアログのデフォルト
set ocidUserDesktopPath to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set aliasDefaultLocation to ocidUserDesktopPath as alias
set listChooseFileUTI to {"public.image"}
set strPromptText to "画像ファイルを選んでください" as text

###ダイアログを前面に出す
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder"
    activate
    set listAliasFilePath to (choose file with prompt strPromptText default location (aliasDefaultLocation) of type listChooseFileUTI with multiple selections allowed without invisibles and showing package contents) as list
  end tell
else
  tell current application
    activate
    set listAliasFilePath to (choose file with prompt strPromptText default location (aliasDefaultLocation) of type listChooseFileUTI with multiple selections allowed without invisibles and showing package contents) as list
  end tell
end if

#############################################
##まずはリストをファイル名順にソート
#############################################
###初期化
set ocidFilePathArray to refMe's NSMutableArray's alloc()'s initWithCapacity:0
repeat with itemAliasFilePath in listAliasFilePath
  set strFilePath to POSIX path of itemAliasFilePath as text
  (ocidFilePathArray's addObject:strFilePath)
end repeat
###ファイルリストをソート
set ocidSortedArray to (ocidFilePathArray's sortedArrayUsingSelector:"compare:")
#############################################
#####保存先 ダイアログ
#############################################
try
  tell application "Finder"
    set aliasResponse to (choose folder "画像を書き出すフォルダを選択してください" with prompt "画像を書き出すフォルダを選択してください" default location aliasDefaultLocation without multiple selections allowed, invisibles and showing package contents)
  end tell
on error
  log "エラーしました"
  return
end try
set strFilePath to POSIX path of aliasResponse as text
set ocidFilePathStr to refMe's NSString's stringWithString:strFilePath
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidSaveDirPathURL to refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false
#############################################
####本処理
#############################################

repeat with itemSortedArray in ocidSortedArray
  ###########ファイルから
  set ocidFilePathStr to (refMe's NSString's stringWithString:itemSortedArray)
  set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
  set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false)
  set ocidFileName to ocidFilePathURL's lastPathComponent()
  set strBaseFileName to ocidFileName's stringByDeletingPathExtension() as text
  ###出力用のファイル名
  set strSaveFileName to strBaseFileName & ".pdf"
  set ocidSaveFilePathURL to (ocidSaveDirPathURL's URLByAppendingPathComponent:strSaveFileName)
  
  ##########################################
  ####PDFドキュメント初期化
  set ocidActivDoc to refMe's PDFDocument's alloc()'s init()
  ####入力イメージ読み込み
  set ocidImageData to (refMe's NSImage's alloc()'s initWithContentsOfURL:ocidFilePathURL)
  set ocidImageSize to ocidImageData's |size|()
  set numW to ocidImageSize's width
  set numH to ocidImageSize's height
  ###################################
  if numW > numH then
    log "横方"
    set numNewH to numMaxPtSize as number
    set numPerHW to numNewH / numH as number
    set numNewW to numW * numPerHW as number
  else if numW < numH then
    log "縦型"
    set numNewW to numMaxPtSize as number
    set numPerHW to numNewW / numW as number
    set numNewH to numH * numPerHW as number
  else
    log "正方形"
    set numNewW to numMaxPtSize as number
    set numPerHW to numNewW / numW as number
    set numNewH to numH * numPerHW as number
  end if
  set ocidNewSize to refMe's NSSize's NSMakeSize(numNewW, numNewH)
  ###中間ファイルとしてのTIFFに変換
  set ocidDistImage to ocidImageData's TIFFRepresentation()
  set ocidBmpImageRep to (refMe's NSBitmapImageRep's imageRepWithData:ocidDistImage)
  ##NSBitmapImageRepのサイズを変更
  (ocidBmpImageRep's setSize:ocidNewSize)
  ####新しく↑で作ったサイズで新しいイメージを初期化して
  set ocidNewImageData to (refMe's NSImage's alloc()'s initWithSize:ocidNewSize)
  ####このイメージにサイズ変更したNSBitmapImageRepを入れる
  (ocidNewImageData's addRepresentation:ocidBmpImageRep)
  
  set ocidPdfPage to (refMe's PDFPage's alloc()'s initWithImage:ocidNewImageData)
  ###ページに挿入する
  (ocidActivDoc's insertPage:ocidPdfPage atIndex:0)
  ####ファイルを保存する
  set boolResponse to (ocidActivDoc's writeToURL:ocidSaveFilePathURL)
  
  ###各種解放
  set ocidImageData to ""
  set ocidActivDoc to ""
  set ocidPdfPage to ""
end repeat

####保存先を開く
set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
appSharedWorkspace's openURL:ocidSaveDirPathURL





|

[単ページ]イメージファイルをPDFに変換(画像の解像度サイズ)

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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use framework "PDFKit"
use framework "Quartz"
use framework "QuartzCore"
use scripting additions

property refMe : a reference to current application
set appFileManager to refMe's NSFileManager's defaultManager()

###################################
#####ファイル選択ダイアログ
###################################
###ダイアログのデフォルト
set ocidUserDesktopPath to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set aliasDefaultLocation to ocidUserDesktopPath as alias
set listChooseFileUTI to {"public.image"}
set strPromptText to "画像ファイルを選んでください" as text
###ダイアログを前面に出す
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder"
    set listAliasFilePath to (choose file with prompt strPromptText default location (aliasDefaultLocation) of type listChooseFileUTI with multiple selections allowed without invisibles and showing package contents) as list
  end tell
else
  tell current application
    set listAliasFilePath to (choose file with prompt strPromptText default location (aliasDefaultLocation) of type listChooseFileUTI with multiple selections allowed without invisibles and showing package contents) as list
  end tell
end if

#############################################
##まずはリストをファイル名順にソート
#############################################
###初期化
set ocidFilePathArray to refMe's NSMutableArray's alloc()'s initWithCapacity:0
repeat with itemAliasFilePath in listAliasFilePath
  set strFilePath to POSIX path of itemAliasFilePath as text
  (ocidFilePathArray's addObject:strFilePath)
end repeat
###ファイルリストをソート
set ocidSortedArray to (ocidFilePathArray's sortedArrayUsingSelector:"compare:")
#############################################
#####保存先 ダイアログ
#############################################
try
  set aliasResponse to (choose folder "画像を書き出すフォルダを選択してください" with prompt "画像を書き出すフォルダを選択してください" default location aliasDefaultLocation without multiple selections allowed, invisibles and showing package contents)
on error
  log "エラーしました"
  return
end try
set strFilePath to POSIX path of aliasResponse as text
set ocidFilePathStr to refMe's NSString's stringWithString:strFilePath
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidSaveDirPathURL to refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false
#############################################
####本処理
#############################################

repeat with itemSortedArray in ocidSortedArray
  ###########ファイルから
  set ocidFilePathStr to (refMe's NSString's stringWithString:itemSortedArray)
  set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
  set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false)
  set ocidFileName to ocidFilePathURL's lastPathComponent()
  set strBaseFileName to ocidFileName's stringByDeletingPathExtension() as text
  ###出力用のファイル名
  set strSaveFileName to strBaseFileName & ".pdf"
  set ocidSaveFilePathURL to (ocidSaveDirPathURL's URLByAppendingPathComponent:strSaveFileName)
  
  ##########################################
  ####入力イメージ読み込み
  set ocidImageData to (refMe's NSImage's alloc()'s initWithContentsOfURL:ocidFilePathURL)
  ####PDFドキュメント初期化
  set ocidActivDoc to refMe's PDFDocument's alloc()'s init()
  set ocidPdfPage to (refMe's PDFPage's alloc()'s initWithImage:ocidImageData)
  ###ページに挿入する
  (ocidActivDoc's insertPage:ocidPdfPage atIndex:0)
  ####ファイルを保存する
  set boolResponse to (ocidActivDoc's writeToURL:ocidSaveFilePathURL)
  
  ###各種解放
  set ocidImageData to ""
  set ocidActivDoc to ""
  set ocidPdfPage to ""
end repeat



|

[単ページ]イメージファイルをPDFに変換(72ppi換算サイズで作成)

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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use framework "PDFKit"
use framework "Quartz"
use framework "QuartzCore"
use scripting additions

property refMe : a reference to current application
set appFileManager to refMe's NSFileManager's defaultManager()




###################################
#####ファイル選択ダイアログ
###################################
###ダイアログのデフォルト
set ocidUserDesktopPath to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set aliasDefaultLocation to ocidUserDesktopPath as alias
set listChooseFileUTI to {"public.image"}
set strPromptText to "画像ファイルを選んでください" as text
###ダイアログを前面に出す
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder"
    set listAliasFilePath to (choose file with prompt strPromptText default location (aliasDefaultLocation) of type listChooseFileUTI with multiple selections allowed without invisibles and showing package contents) as list
  end tell
else
  tell current application
    set listAliasFilePath to (choose file with prompt strPromptText default location (aliasDefaultLocation) of type listChooseFileUTI with multiple selections allowed without invisibles and showing package contents) as list
  end tell
end if
#############################################
##まずはリストをファイル名順にソート
#############################################
###初期化
set ocidFilePathArray to refMe's NSMutableArray's alloc()'s initWithCapacity:0
repeat with itemAliasFilePath in listAliasFilePath
  set strFilePath to POSIX path of itemAliasFilePath as text
  (ocidFilePathArray's addObject:strFilePath)
end repeat
###ファイルリストをソート
set ocidSortedArray to (ocidFilePathArray's sortedArrayUsingSelector:"compare:")
#############################################
#####保存先 ダイアログ
#############################################
try
  set aliasResponse to (choose folder "画像を書き出すフォルダを選択してください" with prompt "画像を書き出すフォルダを選択してください" default location aliasDefaultLocation without multiple selections allowed, invisibles and showing package contents) as alias
on error
  log "エラーしました"
  return
end try
set strFilePath to POSIX path of aliasResponse as text
set ocidFilePathStr to refMe's NSString's stringWithString:strFilePath
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidSaveDirPathURL to refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false
#############################################
####本処理
#############################################

repeat with itemSortedArray in ocidSortedArray
  ###########ファイルから
  set ocidFilePathStr to (refMe's NSString's stringWithString:itemSortedArray)
  set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
  set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false)
  set ocidFileName to ocidFilePathURL's lastPathComponent()
  set strBaseFileName to ocidFileName's stringByDeletingPathExtension() as text
  ###出力用のファイル名
  set strSaveFileName to strBaseFileName & ".pdf"
  set ocidSaveFilePathURL to (ocidSaveDirPathURL's URLByAppendingPathComponent:strSaveFileName)
  ##########################################
  ####入力イメージ読み込み
  set ocidImageData to (refMe's NSImage's alloc()'s initWithContentsOfURL:ocidFilePathURL)
  ####サイズ取得
  set ocidImageSize to ocidImageData's |size|()
  set numW to ocidImageSize's width
  set numH to ocidImageSize's height
  ####ピクセルサイズを取得
  set ocidImageRepArray to ocidImageData's representations()
  set ocidBitmapRep to (ocidImageRepArray's objectAtIndex:0)
  set numPixW to ocidBitmapRep's pixelsWide() as integer
  set numPixH to ocidBitmapRep's pixelsHigh() as integer
  #####サイズをピクセルサイズに設定=72ppi
  set ocidNewSize to refMe's NSSize's NSMakeSize(numPixW, numPixH)
  (ocidBitmapRep's setSize:ocidNewSize)
  ##########################################
  ####新しく↑で作ったサイズで新しいイメージを初期化して
  set ocidNewImageData to (refMe's NSImage's alloc()'s initWithSize:ocidNewSize)
  ####このイメージにサイズ変更したNSBitmapImageRepを入れる
  (ocidNewImageData's addRepresentation:ocidBitmapRep)
  ####PDFドキュメント初期化
  set ocidActivDoc to refMe's PDFDocument's alloc()'s init()
  set ocidPdfPage to (refMe's PDFPage's alloc()'s initWithImage:ocidNewImageData)
  ###ページに挿入する
  (ocidActivDoc's insertPage:ocidPdfPage atIndex:0)
  ####ファイルを保存する
  set boolResponse to (ocidActivDoc's writeToURL:ocidSaveFilePathURL)
  
  ###各種解放
  set ocidBitmapRep to ""
  set ocidNewImageData to ""
  set ocidImageData to ""
  set ocidActivDoc to ""
  set ocidPdfPage to ""
end repeat

return "処理終了"

|

その他のカテゴリー

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 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