2つのPDFの指定ページのテキスト内容をvimdiffで差分表示するAppleScriptです。
Terminal上でvimdiffによる差分比較を表示します。Mac AppStoreに出したアプリ(Double PDF)の部品として使ったらリジェクトされました。Terminal.appを使うものはリジェクトなんだそうで。
半日ぐらいですぐに別のルーチンに差し替えたので本Scriptはあっという間に闇から闇へと葬られました。
FileMergeがAppleScript用語辞書を持っていて単独配布されていたらいろいろ問題は解決される気がします。
AppleScript名:2つのPDFのテキストの指定ページの差分をVimdiffで表示する v2 |
— Created 2017-06-24 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "Quartz" set aPageNum to 103 –diffを表示する対象ページ set aPath to POSIX path of (choose file of type {"com.adobe.pdf"}) set a1Name to makeTmpFileStrPath(aPath) of me set aStr to retBodyStringFromPdf(aPath, aPageNum) of me set aStr1 to cleanUpText(aStr as string, string id 13, string id 10) of me –改行コードをCRからLFに置換 aStr1’s writeToFile:a1Name atomically:true encoding:(current application’s NSUTF8StringEncoding) |error|:(missing value) set bPath to POSIX path of (choose file of type {"com.adobe.pdf"}) set b1Name to makeTmpFileStrPath(bPath) of me set bStr to retBodyStringFromPdf(bPath, aPageNum) of me set bStr1 to cleanUpText(bStr as string, string id 13, string id 10) of me –改行コードをCRからLFに置換 bStr1’s writeToFile:b1Name atomically:true encoding:(current application’s NSUTF8StringEncoding) |error|:(missing value) set sText to "vimdiff " & quoted form of (a1Name as string) & " " & quoted form of (b1Name as string) doComInTerminalWindow(sText) of me on makeTmpFileStrPath(aPath) set aTmpPath to current application’s NSString’s stringWithString:(POSIX path of (path to temporary items)) set aUUID to current application’s NSUUID’s UUID()’s UUIDString() set aName to aUUID’s stringByAppendingPathExtension:"txt" set a1FullPath to (aTmpPath’s stringByAppendingString:aName) return a1FullPath end makeTmpFileStrPath on retBodyStringFromPdf(thePath as string, targPageNum as integer) set anNSURL to (current application’s |NSURL|’s fileURLWithPath:thePath) set theDoc to current application’s PDFDocument’s alloc()’s initWithURL:anNSURL set theCount to theDoc’s pageCount() as integer if targPageNum > theCount then return "" set aPage to (theDoc’s pageAtIndex:(targPageNum – 1)) set tmpStr to (aPage’s |string|()) return tmpStr end retBodyStringFromPdf on doComInTerminalWindow(aCMD) using terms from application "Terminal" tell application id "com.apple.Terminal" activate set wCount to count (every window whose visible is true) if wCount = 0 then –ウィンドウが1枚も表示されていない場合 do script "pwd" activate set size of front window to {1280, 700} do script aCMD in front window else –すでにウィンドウが表示されている場合 do script "pwd" in front window activate set size of front window to {1280, 700} do script aCMD in front window end if end tell end using terms from end doComInTerminalWindow on cleanUpText(someText, targStr, repStr) set theString to current application’s NSString’s stringWithString:someText set targString to current application’s NSString’s stringWithString:targStr set repString to current application’s NSString’s stringWithString:repStr set theString to theString’s stringByReplacingOccurrencesOfString:targString withString:repString options:(current application’s NSRegularExpressionSearch) range:{location:0, |length|:length of someText} return theString end cleanUpText |
More from my site
(Visited 131 times, 1 visits today)
Terminal.appでコマンドを実行する – AppleScriptの穴 says:
[…] → 2つのPDFのテキストの指定ページの差分をVimdiffで表示する v2 […]