Reading Books On A Schedule

Reading Books On A Schedule
0.0 0

(Joe Buhlig) #1

For years I have wanted to read more books. Prolific readers rave about the benefits and world-renowned leaders often attribute their ideas and successes to their habit of reading, but to me the benefits of having read a lot of books was secondary to the innate sense that a realm of knowledge and experience was available to me, but I was missing it.


This is a companion discussion topic for the original entry at http://joebuhlig.com/reading-books-on-a-schedule/

(Keith) #2

I realize that asking this question pretty much proves I shouldn’t use the referenced script, but if I may ask anyway, where are we supposed to put the script after downloading? I assume it’s:

~/Library/Application Scripts/com.omnigroup.OmniFocus2

Thank you. I think I might have use for this soon: my book pile has gotten dangerously high and it’s beyond time to start working my way down the stack!


#3

I also have a problem with the script. I cannot insert the date correctly. I have made a test entry:

  1. Name: Test.
  2. Pages: 140.
  3. Start date: 17.06.2016.
  4. Finish date: 01.07.2016.

I. When entering the dates “20160617” and “20160701” for start and finish dates, respectively, I get the following task in my inbox:


#4

II. When entering the dates “2016-06-17” and “2016-07-01” for start and finish dates, respectively, I get the following tasks in my inbox:

III. When entering the dates “2016.06.17” and “2016.07.01” for start and finish dates, respectively, I get a script error.

IV. When entering the dates “2016/06/17” and “2016/07/01” for start and finish dates, respectively, I get a script error.

I really appreciate any help you can provide.
Cheers
M.


#5

There a link to the target folder for scripts. In OmniFocus, the menu bar HELP > Open Scripts Folder. You can then drag it to the toolbar of OmniFocus for faster use.


(John Johnson) #6

Thanks Joe – this what just what I was looking for. I took the liberty of modifying your code (AppleScript version only), to cast the input start and end dates as dates, to create the daily reading tasks under a parent project named for the book’s title, and to revise the daily page assignments. Code follows (sorry if there’s a better way to do this than copy & paste):

-- Set variables.

-- Set context.
set myContext to "Read"

-- Get book info.
set bookTitle to text returned of (display dialog "What's the title of the book?" default answer "") as string
set numPages to text returned of (display dialog "How many pages are in the book?" default answer 0) as integer

-- Get reading info.
set startDate to date (text returned of (display dialog "When will you start reading?" default answer "m/d/yy"))
set endDate to date (text returned of (display dialog "When will you end reading?" default answer "m/d/yy"))
set deferDate to startDate
set numDays to (endDate - deferDate) div days + 1
set pagesPerDay to floor(numPages / numDays) as integer
set startPage to 1
set endPage to pagesPerDay as integer

tell application "OmniFocus"
	tell default document
		-- Set the context.
		set theContext to first context whose name is myContext
		
		-- Create a project with the book's title and the selected context.
		set theProject to make new project with properties {name:bookTitle, note:((bookTitle & return & numPages & return & "Begin reading: " & startDate as string) & return & "End reading: " & endDate as string), context:theContext, sequential:true}
		
		set i to 1
		
		-- Create a project task for each day of the reading cycle.
		repeat until i = numDays + 1
			-- For the last day, set the end page to the final page of the book.
			if i = numDays then
				set endPage to numPages
			end if
			
			-- Set the task title.
			set taskTitle to "Read " & bookTitle & " pages " & startPage & "-" & endPage
			-- Create the task.
			tell theProject to make new task with properties {name:taskTitle, defer date:deferDate, context:theContext}
			
			-- Increment the start page, end page, and defer date.
			set startPage to endPage + 1
			set endPage to startPage + pagesPerDay - 1
			set deferDate to deferDate + (60 * 60 * 24)
			
			-- Increment the counter.
			set i to i + 1
		end repeat
		
		return bookTitle & ": " & numPages & " pages; " & i - 1 & " tasks created."
	end tell
end tell

on floor(x)
	set y to x div 1
	
	if x < 0 and x mod 1 is not 0 then
		set y to y - 1
	end if
	
	return y
end floor

(Joe Buhlig) #7

@mathefff23 has your answer here:


@j_j, I edited your post only to wrap the code block with the AppleScript formatting. :wink: Nice job.


@mathefff23, something weird is going on there. The dates should be in the format YYYYMMDD in both cases. If that continues to give you fits, you can alter it. Replace this:

set startDate to text returned of (display dialog "When should this start?" default answer "yyyymmdd")
set endDate to text returned of (display dialog "When should this end?" default answer "yyyymmdd")
set deferYear to text 1 thru 4 of startDate
set deferMonth to text 5 thru 6 of startDate
set deferDay to text 7 thru 8 of startDate
set dateString to deferMonth & "/" & deferDay & "/" & deferYear
set deferDate to date dateString

set endYear to text 1 thru 4 of endDate
set endMonth to text 5 thru 6 of endDate
set endDay to text 7 thru 8 of endDate
set endDateString to endMonth & "/" & endDay & "/" & endYear
set endDate to date endDateString
set numDays to ((endDate - deferDate) div days) + 1

With this:

set startDate to date (text returned of (display dialog "When should this start?" default answer "m/d/yy"))
set endDate to date (text returned of (display dialog "When should this end?" default answer "m/d/yy"))
set deferDate to startDate

For everyone, you may want to grab the latest version of the code. I found a bug that was creating one too many tasks.


(Simon) #8

Many thanks for the script, but it’s not working my end. I keep getting the following error when I run it:

`AppleScript reported the following error:

The operation couldn’t be completed. osascript: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/QXPScriptingAdditions.osax" cannot be used with the current OS because it has no OSAXHandlers entry in its Info.plist.
/Users/user/Library/Application Scripts/com.omnigroup.OmniFocus2/ReadBookTasks.scpt: execution error: OmniFocus got an error: Can’t get flattened context 1 of document of window 1 whose name = "Read". Invalid index. (-1719)`

Any ideas?


#9

Do you have @Read context in OmniFocus already? Maybe it is missing it and cannot set a task.


#10

After replacing the text and giving the start and finish dates as “6/18/16” and “7/1/16” I receive the following error: “The variable numDays is not defined. (-2753)”.


(Simon) #11

Ok, Adding a @Read context made the script parse.

There are some date issues:

yyyymmdd get interpreted as yyyyddmm. I set the start date to 20160701 and end date to 20160901 and only got three entries. I tried 20160107 and 20160109 and got 63 entries (wich is correct).

I should add that I’m in the UK and have UK date settings in OSX


(Keith) #12

Drat!! I knew there was a menu command. I checked every menu (twice!) but never checked the Help menu. :-/

Thanks!


#13

I don’t have AppleScript skills, but it looks to me as if this script could also be used, with a few modifications, to plan writing books on a schedule.


(Martin Zielinski) #14

Hi Joe, i set it up and it works perfect :slight_smile: thanks
Only thing is that i have to change the date order in yyyyddmm and then it’s no problem


(Joe Buhlig) #15

Let me guess: you’re across the pond? :wink:


(Martin Zielinski) #16

That’s absolutely correct Mr. Buhlig :slight_smile:


(Martin Barker) #17

Hi @joebuhlig I’ve downloaded your updated script, but it’s throwing up an error or either setting the date hundreds of years in the future. I’ve tried all of the above fixes, do you have any ideas? I am also across the pond…Scotland. I appreciate any help you can offer. Thank you.


(Joe Buhlig) #18

Give this a try:

Different countries format the date differently on the system so you have to account for it in the way you enter the date. I have a task to fix this in the future but it hasn’t made it’s way up the list yet.


(Martin Barker) #19

Hi @joebuhlig, I managed to get it working, it just required a little script rewrite to adress the different date formatting. Thank you for your help and thank you for making great content.


(Newton Mota) #20

@MartindBarker Would you mind to share the final code? I found the script reading the Joe’s site and couldn’t find a way to make it work or solve it. Every time I run the script it messes with the dates and also creates tons of tasks (like one for two or four pages of a book).