Jake.codes

Names from Screenshots

Friday, January 03, 2014

-- A proof of concept
--
-- Returns the first proper name of an image using: 
--
-- - PDFpenPro 
-- ---- https://itunes.apple.com/us/app/pdfpenpro-6/id609313570?mt=12&uo=4&at=1l3v3KV
-- - Syn
-- ---- https://github.com/stephencelis/syn/
-- - JSON Helper
-- ---- https://itunes.apple.com/us/app/json-helper-for-applescript/id453114608?mt=12&uo=4&at=1l3v3KV
tell application "PDFpenPro 6"
	-- launch the image
	open theFile as alias
	tell document 1
		-- run it through PDFpen's OCR
		ocr
		repeat while performing ocr
			delay 1
		end repeat
		delay 1
		set ocrText to plain text of page 1
		-- You don't want to save your image as a OCR'd PDF for this.
		close without saving
	end tell
	quit
end tell

tell application "JSON Helper"
	-- Output the first person name returned with Syn.
	-- Make sure the path to syn (`which syn` will help)
	-- is the same as I use here.
	set theJSON to read JSON from (do shell script "echo '" & ocrText & "' | /usr/local/bin/syn -H -fjson | head -1")
	-- Take the name and output it as a dialog box
	display dialog token of theJSON as text
end tell