Rude and crude Book Projecct Builder

This is a rough first hack of a AppleScript to create a project to read a book: Ideally, Omni would add the ability to insert a variable into the task name and the repeating task would increment by an increment value. But, until that day (that may never come) this will have to do. The downside is that it creates all the tasks.

on appIsRunning(GTDAppName)
tell application "System Events"
	return (count of (application processes whose name is GTDAppName)) is not 0
end tell

end appIsRunning

repeat
display dialog “Enter Name of Book” default answer "Test "
try
if the text returned of result is not “” then
set the _bookname to the text returned of the result
exit repeat
end if
on error
beep
end try
end repeat

repeat
display dialog “Beginning Chapter” default answer “1”
try
if the text returned of result is not “” then
set the _begin to the text returned of the result as number
exit repeat
end if
on error
beep
end try
end repeat

repeat

display dialog "Ending Chapter" default answer "2"
try
	if the text returned of result is not "" then
		set the _end to the text returned of the result as number
		exit repeat
	end if
on error
	beep
end try

end repeat

display dialog ("Create Reading List Actions for " & _bookname & " from Chapters " & _begin & " to " & _end) ¬
buttons {“Create Actions”, “Cancel”} default button 1
if button returned of the result is “Create Actions” then

if appIsRunning("OmniFocus") then
	tell application "OmniFocus"
		tell default document
			set personalFolder to folder named "Personal"
			tell personalFolder
				set booksFolder to folder named "Books"
				tell booksFolder
					set _ri to {unit:(day), steps:(2), fixed:(false)}
					set _projectName to "Read " & _bookname
					make project with properties {name:(_projectName), status:(active), sequential:(true), review interval:(_ri), note:("Chapters " & _begin & " to " & _end)}
					set theProject to project named _projectName
					tell theProject
						repeat with chapter from _begin to _end
							make task with properties {name:("Read Chapter " & chapter)}
						end repeat
					end tell
				end tell
			end tell
		end tell
	end tell
	
	-- if OmniFocus is not running, launch it first and then create the Quick Entry
else
	tell application "OmniFocus"
		activate
		tell default document
			set personalFolder to folder named "Personal"
			tell personalFolder
				set booksFolder to folder named "Books"
				tell booksFolder
					set _ri to {unit:(day), steps:(2), fixed:(false)}
					set _projectName to "Read " & _bookname
					make project with properties {name:(_projectName), status:(active), sequential:(true), review interval:(_ri), note:("Chapters " & _begin & " to " & _end)}
					set theProject to project named _projectName
					tell theProject
						repeat with chapter from _begin to _end
							make task with properties {name:("Read Chapter " & chapter)}
						end repeat
					end tell
				end tell
			end tell
		end tell
	end tell
end if

end if

1 Like

So sorry about terrible formatting. Maybe Omni could enable uploading of AppleScript files.

I’ve found on this forum software it is best to select the whole applescript with the mouse and then use the </> icon in the post toolbar to encode the whole selection at once. If you mark code manually, some of the applescript will jump out (probably due to its design as a “readable” language). Try to edit your post now.

Also, two underscores are needed to keep your variables consistent:

display dialog ("Create Reading List Actions for " & _bookname & " from Chapters " & _begin & " to " & _end)

instead of

display dialog ("Create Reading List Actions for " & bookname & " from Chapters " & _begin & " to " & end)

That’s exactly what I did! I just retried it and same thing happens. Here’s what I see in the AppleScript editor. The apparent inconstancy of variable names (two without leading underscore) was also done by pasting the code into the browser.