Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the '10.5: Use Automator to create audiobooks from PDFs' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.5: Use Automator to create audiobooks from PDFs
Authored by: ephramz on May 08, '08 10:36:31PM
I use the following script to batch convert every open document in TextEdit to speech, convert in iTunes to the current converter, and properly label the artist, album, track number, and lyrics (text of the document) using the first 3 lines of the text which are of the form:

Chapter #.
Title
Author

This could easily be modified to work with Preview on PDF documents. I tried doing this in Preview, but it was too difficult to get the looping to work right. This script has a lot of "try" blocks to avoid the crashing of the script from timeout errors when TextEdit doesn't respond for a long time while it's converting. Hope this is helpful.

set AppleScript's text item delimiters to " "
tell application "TextEdit"
	repeat with doc from 1 to count of documents
		set txt to text of document doc
		set chapter to word 2 of paragraph 1 of document doc
		set sname to ((words 1 thru -1) of ((paragraph 2 of document doc)))
		set author to ((words 1 thru -1) of ((paragraph 3 of document doc)))
		set pth to (path to music folder as text) & "chapter.aiff"
		log pth
		try
			say txt saving to pth
		on error
			set done to false
			repeat until done
				try
					do shell script "sleep 60"
					get name of front document
					set done to true
				end try
			end repeat
		end try
		tell application "iTunes"
			try
				set newtrack to item 1 of (convert pth)
			on error
				set done to false
				repeat until done
					try
						do shell script "sleep 60"
						get name of newtrack
						set done to true
					end try
				end repeat
			end try
			tell newtrack
				set artist to author as text
				set lyrics to txt as text
				set track number to chapter
				set name to sname as text
			end tell
		end tell
	end repeat
end tell


[ Reply to This | # ]