AppleScript to open current page in PDF Expert

This should do it. Note that there’s no error checking done in the macro.

-- DEVONthink - Get current PDF page and save it to Keyboard Maestro variable

tell application id "DNtp"
	try
		if not (exists think window 1) then
			error "Please open a window"
		else
			set theWindow to think window 1
		end if
		
		set theRecord to content record of theWindow
		
		if theRecord ≠ missing value then
			set theType to type of theRecord as string
			if theType ≠ "PDF document" then error "Please open a PDF record"
			set thePath to path of theRecord
			do shell script "open -a " & quoted form of (POSIX path of (path to application "PDF Expert")) & space & quoted form of thePath
			set thePage to (current page of think window 1) + 1
		else
			error "Please open a PDF record"
		end if
		
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
		return
	end try
end tell

tell application id "com.stairways.keyboardmaestro.engine"
	setvariable "theCurrentPDF_Page" to thePage
end tell

1 Like