Script: Report Stats
Posted: Mon Jun 28, 2021 7:00 pm
This script will report stats for the front library window.
* Blank (missing) attachments --> also colored to a specific label color
* Empty (no) attachments
* Blank (missing) attachments --> also colored to a specific label color
* Empty (no) attachments
Code: Select all
(*
Report Statistics
version 2021-06-28
author jjw
- open a library
- run this script
- searches over all publications for blank (missing) attachment and empty (no) attachment
*)
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
-- set this to the label color value to assign for a blank (missing) attachment
-- set to -1 to ignore label color change
property blankLabel : -1
on run {}
-- set values
set theListBlank to {}
set theListEmpty to {}
tell application "Bookends"
activate
-- collect the bibliographies to process
set thePList to every publication item of front library window
set nTotal to the number of items in thePList
-- process
repeat with thePub in thePList
if the attachment items of thePub is not {} then
-- process publications that should have attachments
set theAttachmentFullPath to (the path of the first attachment item of thePub) as text
if theAttachmentFullPath is "" then
-- store info when attachment file path is blank
set thePubDate to the publication date string of thePub as text
set thePubAuthors to the authors of thePub as text
copy {pubDate:thePubDate, pubAuthors:thePubAuthors, pubPath:theAttachmentFullPath} to the end of theListBlank
if blankLabel ≥ 0 then set the label color of thePub to blankLabel
end if
else
-- store info for publications without attachments
set thePubDate to the publication date string of thePub as text
set thePubAuthors to the authors of thePub
set thePubID to the id of thePub as text
copy the {pubDate:thePubDate, pubAuthors:thePubAuthors, pubID:thePubID} to the end of theListEmpty
end if
end repeat
my reportValues(nTotal, theListBlank, theListEmpty)
end tell
end run
on reportValues(nTotal, theListBlank, theListEmpty)
set nBlank to the number of items in theListBlank
set nEmpty to the number of items in theListEmpty
set theDialog to "Total: " & nTotal & tab & tab ¬
& "Blank: " & nBlank & tab & tab ¬
& "Empty: " & nEmpty
display dialog theDialog buttons {"OK"}
end reportValues