Page 1 of 1

I need to know the total number of pages

Posted: Wed Jan 19, 2022 1:41 pm
by Philologist
Is it possible to show or find out somehow the total number of pages for a group or of selected references in the Library Window?

I think this can be quite useful, both for private use (how long will it take me to read all the books in the group?) or for teachers who are creating reading lists for students and want to make sure that it's manageable.

Re: I need to know the total number of pages

Posted: Wed Jan 19, 2022 2:48 pm
by Jon
No, that's not possible. The best thing I can think of is to create a format that outputs the pages field, and then you can add them up yourself.

Jon
Sonny Software

Re: I need to know the total number of pages

Posted: Fri Jan 21, 2022 10:50 pm
by Philologist
Jon wrote: Wed Jan 19, 2022 2:48 pm The best thing I can think of is to create a format that outputs the pages field
That's a good idea. I created a new format and called it "Number of pages." For books, journal articles and reviews it has only one field, namely Pages range (p-). When I select references in Bookends and then choose "Copy Formatted" from the Edit menu a long column of numbers is inserted into my word processor (Nisus Writer Pro). The numbers are both single numbers (= page numbers of books) and a page range (journal articles, book chapters). A Nisus macro calculates the page range and adds up all the numbers, so within two seconds I have the total number I'm looking for.

In the search for the ultimate simplicity, I wonder whether I can use an AppleScript for this. Regarding Bookends, all I need to know now is how to execute the command "Copy Formatted" within an AppleScript. I guess it should have the format

tell application "Bookends"
[command for Copy Formatted]
end tell

Can the menu command Copy Formatted be triggered with an AppleScript?

Re: I need to know the total number of pages

Posted: Sat Jan 22, 2022 8:21 am
by Jon
The AppleScript can ask Bookends for the formatted reference directly, no need to use the clipboard. NWP is also scriptable, so you could insert the formatted references you received in a document and invoke the macro.

Jon
Sonny Software

Re: I need to know the total number of pages

Posted: Sat Jan 22, 2022 3:15 pm
by Philologist
Jon wrote: Sat Jan 22, 2022 8:21 am The AppleScript can ask Bookends for the formatted reference directly
Yes, that's the question I'm asking. What AppleScript command do I use in order to achieve this?
I checked Bookend's AppleScript Dictionary, but I didn't find the necessary command.

Re: I need to know the total number of pages

Posted: Sat Jan 22, 2022 5:08 pm
by Jon
There are many examples in the online documentation (and in the user guide), including how to get formatted references (and even put them in the clipboard).

https://www.sonnysoftware.com/scriptingbookends/

Here's just one


tell application "Bookends"
tell front library window
set formattedReference to format last publication item
set the clipboard to formattedReference
end tell
end tell



Jon
Sonny Software

Re: I need to know the total number of pages

Posted: Mon Jan 24, 2022 12:54 am
by Philologist
Unfortunately I'm not very familiar with AppleScript. The example you gave will only consider the last publication item, but I need to calculate the total number for all selected references, or all references in a group, not just for the last one.

Anyway, I managed to find the right script I was looking for. If anyone else wants to do this, he or she can use the following script:

tell application "Bookends"
tell front library window
set NumberOfPages to publication items of group hits
if NumberOfPages is not {} then
set TotalOfPages to format NumberOfPages using "Number of pages.fmt"
set the clipboard to TotalOfPages
end if
end tell
end tell

"Number of pages.fmt" is—as I mentioned earlier—a format which outputs only the page numbers.

Thanks for pointing me in the right direction.