AppleScript名:連番JPEGファイルを読み込んで連結したPDFを作成(新規作成) |
— Created 2016-09-20 by Takaaki Naganoya — 2016 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "QuartzCore" use framework "Quartz" use framework "AppKit" set aExt to ".jpg" set aFol to choose folder set fList to getFilePathList(aFol, aExt) of me set f2List to my sort1DList:fList ascOrder:true –sort by ascending set newFile to POSIX path of (choose file name with prompt "新規PDFファイルの名称を選択") set newFilePath to current application’s NSString’s stringWithString:newFile –Make Blank PDF set aPDFdoc to current application’s PDFDocument’s alloc()’s init() set pageNum to 0 repeat with i in f2List set j to contents of i set aURL to (current application’s |NSURL|’s fileURLWithPath:j) set bImg to (current application’s NSImage’s alloc()’s initWithContentsOfURL:aURL) (aPDFdoc’s insertPage:(current application’s PDFPage’s alloc()’s initWithImage:bImg) atIndex:pageNum) set pageNum to pageNum + 1 end repeat aPDFdoc’s writeToFile:newFilePath –ASOCで指定フォルダのファイルパス一覧取得(拡張子指定つき) on getFilePathList(aFol, aExt) set aPath to current application’s NSString’s stringWithString:(POSIX path of aFol) set aFM to current application’s NSFileManager’s defaultManager() set nameList to (aFM’s contentsOfDirectoryAtPath:aPath |error|:(missing value)) as list set anArray to current application’s NSMutableArray’s alloc()’s init() repeat with i in nameList set j to i as text if (j ends with aExt) and (j does not start with ".") then –exclude invisible files set newPath to (aPath’s stringByAppendingString:j) (anArray’s addObject:newPath) end if end repeat return anArray as list end getFilePathList –1D List(文字)をsort / ascOrderがtrueだと昇順ソート、falseだと降順ソート on sort1DList:theList ascOrder:aBool set aDdesc to current application’s NSSortDescriptor’s sortDescriptorWithKey:"self" ascending:aBool selector:"localizedCaseInsensitiveCompare:" set theArray to current application’s NSArray’s arrayWithArray:theList return (theArray’s sortedArrayUsingDescriptors:{aDdesc}) as list end sort1DList:ascOrder: |
More from my site
(Visited 79 times, 1 visits today)