Dual PDF Viewer as ASObjC

Here is my Dual PDF viewer hardcoded in ASObjC.

Could be running directly in Script Editor, its very fast :slight_smile:

use framework "Foundation"
use framework "AppKit"
use framework "Quartz"
use scripting additions

property arguments : missing value
property errorDescription : false

on run
	-- Set the PDF document on the left side.
	set thePdfDoc1 to POSIX path of (path to desktop) & "KS_Cocoa_Alerts.pdf"
	-- Set the PDF document on the right side.
	set thePdfDoc2 to POSIX path of (path to desktop) & "KS_Cocoa_Alerts.pdf"
	-- Set the arguments 
	set arguments to {title:"Dual PDF Viewer", pdfLeft:thePdfDoc1, pdfRight:thePdfDoc2}
	-- display dialog "The main thread is: " & (my NSThread's isMainThread() as boolean)
	if not my NSThread's isMainThread() as boolean then
		my performSelectorOnMainThread:"performSplitView:" withObject:arguments waitUntilDone:true
		my performSplitView:arguments
	end if
	-- Error handler for performSelectorOnMainThread:withObject:waitUntilDone:
	if errorDescription is not false then
		log errorDescription
	end if
end run

on performSplitView:arguments
		set {theWidth, theHeight} to {1200, 800}
		set thePDFViewLeft to createPDFView(arguments's pdfLeft, 0, 0, theWidth / 2, theHeight)
		set thePDFViewRight to createPDFView(arguments's pdfRight, 0, 0, theWidth / 2, theHeight)
		set theSplitView to createSplitView(0, 0, theWidth, theHeight)
		theSplitView's setDividerStyle:(current application's NSSplitViewDividerStyleThin)
		theSplitView's setVertical:true
		theSplitView's addSubview:thePDFViewLeft
		theSplitView's addSubview:thePDFViewRight
		set theWindow to createWindowWithRect(0, 0, theWidth, theHeight)
		theWindow's setTitle:(arguments's title)
		theWindow's setContentView:theSplitView
		set theWindowController to createWindowController(theWindow)
		theWindowController's showWindow:me
		theWindowController's |window|'s |center|()
		theWindowController's |window|'s makeKeyAndOrderFront:me
		-- Error handler for performSelectorOnMainThread:withObject:waitUntilDone:
	on error error_message number error_number
		set errorDescription to error_message & " with error number " & error_number
	end try
end performSplitView:

on createPDFView(thePath, xMin, yMin, xLen, yLen)
	set theURL to current application's |NSURL|'s fileURLWithPath:thePath
	set pdfDoc to current application's PDFDocument's alloc()'s initWithURL:theURL
	set pdfViewSize to current application's NSMakeRect(xMin, yMin, xLen, yLen)
	set thePDFView to current application's PDFView's alloc()'s initWithFrame:pdfViewSize
	thePDFView's setDocument:pdfDoc
	return thePDFView
end createPDFView

on createSplitView(xMin, yMin, xLen, yLen)
	set splitViewSize to current application's NSMakeRect(xMin, yMin, xLen, yLen)
	set theSplitView to current application's NSSplitView's alloc()'s initWithFrame:splitViewSize
	return theSplitView
end createSplitView

on createWindowWithRect(xMin, yMin, xLen, yLen)
	set windowSize to current application's NSMakeRect(xMin, yMin, xLen, yLen)
	set winStyle to (current application's NSWindowStyleMaskTitled as integer) + (current application's NSWindowStyleMaskClosable as integer)
	set theWindow to current application's NSWindow's alloc()'s initWithContentRect:windowSize styleMask:winStyle backing:2 defer:true
	return theWindow
end createWindowWithRect

on createWindowController(theWindow)
	set theWindowController to current application's NSWindowController's alloc()'s initWithWindow:theWindow
	return theWindowController
end createWindowController