20-item Limit on PubMed Search

The Pubmed search in Data/New from Template/Education/Search Pubmed is very helpful.

However, it retrieves only 20 items.

I do not see the 20-item limit hardcoded in the script.

Is this a limitation PubMed has created? Is there any way to exceed the 20-item limit?

No, it’s just the default limit. The next version of DEVONthink 3.0 will come with an updated template that downloads up to 100 results. If you need more you can easily edit the template with Script Editor and change the number to your liking.

Thank you - but I cannot see where the 20-item limit is coded here. Can you help?

-- Smart template adding a PubMed query to DEVONthink

-- Written by Eric Böhnisch-Volkmann, modified by Christian Grunenberg

-- © 2009–2017 DEVONtechnologies, LLC

**property** pDefaultQuery : ""

**property** pURLSearch : "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi"

**property** pURLFetch : "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi"

**property** pURLView : "http://www.ncbi.nlm.nih.gov/pubmed/"

-- Import helper library

**tell** *application* "Finder" **to** **set** pathToAdditions **to** (( **path to** *application* *id* "DNtp" as *string* ) & "Contents:Resources:Template Script Additions.scpt") **as** *alias*

**set** helperLibrary **to** **load script** pathToAdditions

**try**

-- We're later working in DEVONthink, we need to cache localized strings while still in our realm

**set** theTemplateFile **to** helperLibrary's pathToLocalizedResources() & "%articleTitle%.rtf"

**tell** *application* *id* "DNtp"

-- Ask the user for their query, then make group for the results

**set** theQuery **to** « *event* DTpacd89» **my** helperLibrary's localizedString("New PubMed Query") **given** « *class* dtxt»:pDefaultQuery, « *class* info»:( **my** helperLibrary's localizedString("Please enter your query for PubMed:"))

**set** theQueryEscaped **to** **my** helperLibrary's replaceText(" ", "+", theQuery)

« *event* DTpacd40» **my** helperLibrary's localizedString("Researching on PubMed") **given** « *class* DTsp»:-1

« *event* DTpacd41» **my** helperLibrary's localizedString("Sending query")

-- Run the search, get list of IDs

**set** theSearchURL **to** (pURLSearch & "?db=pubmed&term=" & theQueryEscaped & "&retmode=xml") **as** *string*

**set** theXML **to** « *event* DTpacd36» theSearchURL **given** « *class* DTec»:"UTF-8"

**if** theXML **is** *missing value* **or** theXML **is** "" **then**

**error** "Download failed."

**else** **if** theXML **contains** "503 Service Temporarily Unavailable" **then**

**error** **my** helperLibrary's localizedString("503 Service Temporarily Unavailable")

**end** **if**

**tell** *application* "System Events"

**set** theXMLData **to** **make** new *XML data* with data theXML

**set** theSearchResultElement **to** **first** *XML element* **of** theXMLData **whose** name **is** "eSearchResult"

**set** theIdListElement **to** **first** *XML element* **of** theSearchResultElement **whose** name **is** "IdList"

**set** theIDs **to** value **of** **every** *XML element* **of** theIdListElement -- The actual result item IDs

**end** **tell**

**if** theIDs **is** *missing value* **or** theIDs **is** {} **then** **error** **my** helperLibrary's localizedString("No results.")

-- Download articles

« *event* DTpacd41» **my** helperLibrary's localizedString("Downloading result list")

**set** theIDString **to** *item* 1 **of** theIDs

**repeat** **with** theID **in** ( *items* 2 **through** -1 **of** theIDs)

**set** theIDString **to** theIDString & "," & theID

**end** **repeat**

**set** theFetchURL **to** (pURLFetch & "?db=pubmed&id=" & theIDString & "&retmode=xml") **as** *string*

**set** theXML **to** « *event* DTpacd36» theFetchURL **given** « *class* DTec»:"UTF-8"

**if** theXML **is** *missing value* **or** theXML **is** "" **then**

**error** "Download failed."

**else** **if** theXML **contains** "503 Service Temporarily Unavailable" **then**

**error** "503 Service Temporarily Unavailable"

**end** **if**

-- Process articles

**tell** *application* "System Events"

**set** theXMLData **to** **make** new *XML data* with data theXML

**set** thePubmedArticleElements **to** **every** *XML element* **of** ( **first** *XML element* **of** theXMLData **whose** name **is** "PubmedArticleSet") **whose** name **is** "PubmedArticle"

**end** **tell**

**if** thePubmedArticleElements **is** **not** {} **then**

« *event* DTpacd41» **my** helperLibrary's localizedString("Making a group for the results")

**set** theGroup **to** « *event* DTpacd08» {« *class* DTty»:« *constant* DtypDTgr», name:( **my** helperLibrary's localizedString("PubMed Research: ") & theQuery) **as** *string* } **given** « *class* DTin»:« *class* DTcg»

**if** theGroup **is** *missing value* **then** **error** **my** helperLibrary's localizedString("Could not create group.")

« *event* DTpacd40» **my** helperLibrary's localizedString("Downloading articles from PubMed") **with** « *class* DTcb» **given** « *class* DTsp»:( **count** **of** thePubmedArticleElements)

**repeat** **with** thePubmedArticleElement **in** thePubmedArticleElements

**tell** *application* "System Events"

**set** theArticleWrapperElement **to** **first** *XML element* **of** thePubmedArticleElement

**set** theArticleElement **to** ( **first** *XML element* **of** theArticleWrapperElement **whose** name **is** "Article")

**set** theArticle **to** {pubmedID:"", link:"", name:"", abstract:"", publication:{}, authors:{}, publicationtypes:{}}

-- Get article ID and so the URL

**try**

**set** **the** pubmedID **of** theArticle **to** (value **of** **first** *XML element* **of** theArticleWrapperElement **whose** name **is** "PMID")

**end** **try**

**set** **the** link **of** theArticle **to** (pURLView & pubmedID **of** theArticle) **as** *string*

-- Get article name

**try**

**set** name **of** theArticle **to** (value **of** **first** *XML element* **of** theArticleElement **whose** name **is** "ArticleTitle")

**tell** *application* *id* "DNtp" **to** « *event* DTpacd41» (name **of** theArticle)

**end** **try**

-- Get article abstract

**try**

**set** abstract **of** theArticle **to** value **of** ( **first** *XML element* **of** ( **first** *XML element* **of** theArticleElement **whose** name **is** "Abstract") **whose** name **is** "AbstractText")

**end** **try**

-- Get publication information

**set** thePublication **to** {publication:"", vol:"", issue:"", publicationdate:""}

**try**

**set** theJournalIssueElement **to** ( **first** *XML element* **of** ( **first** *XML element* **of** theArticleElement **whose** name **is** "Journal") **whose** name **is** "JournalIssue")

**try**

**set** **the** vol **of** thePublication **to** value **of** ( **first** *XML element* **of** theJournalIssueElement **whose** name **is** "Volume")

**end** **try**

**try**

**set** **the** issue **of** thePublication **to** value **of** ( **first** *XML element* **of** theJournalIssueElement **whose** name **is** "Issue")

**end** **try**

**try**

**set** **the** publication **of** thePublication **to** (value **of** **first** *XML element* **of** ( **first** *XML element* **of** theArticleElement **whose** name **is** "Journal") **whose** name **is** "Title")

**end** **try**

**try**

**set** theMedlineDate **to** (value **of** **first** *XML element* **of** ( **first** *XML element* **of** theJournalIssueElement **whose** name **is** "PubDate") **whose** name **is** "MedlineDate")

**set** publicationdate **of** thePublication **to** theMedlineDate

**on** **error**

**try**

**set** thePublicationMonth **to** (value **of** **first** *XML element* **of** ( **first** *XML element* **of** theJournalIssueElement **whose** name **is** "PubDate") **whose** name **is** "Month")

**set** publicationdate **of** thePublication **to** publicationdate **of** thePublication & thePublicationMonth

**end** **try**

**try**

**set** thePublicationDay **to** (value **of** **first** *XML element* **of** ( **first** *XML element* **of** theJournalIssueElement **whose** name **is** "PubDate") **whose** name **is** "Day")

**set** publicationdate **of** thePublication **to** publicationdate **of** thePublication & " " & thePublicationDay

**end** **try**

**try**

**set** thePublicationYear **to** (value **of** **first** *XML element* **of** ( **first** *XML element* **of** theJournalIssueElement **whose** name **is** "PubDate") **whose** name **is** "Year")

**set** publicationdate **of** thePublication **to** publicationdate **of** thePublication & ", " & thePublicationYear

**end** **try**

**end** **try**

**end** **try**

**set** publication **of** theArticle **to** thePublication

-- Get author names

**set** theAuthorElements **to** {}

**try**

**set** theAuthorElements **to** **every** *XML element* **of** ( **first** *XML element* **of** theArticleElement **whose** name **is** "AuthorList")

**end** **try**

**if** theAuthorElements ≠ {} **then**

**repeat** **with** theAuthorElement **in** theAuthorElements

**try**

**set** theAuthor **to** {firstname:"", initial:"", lastname:""}

**set** firstname **of** theAuthor **to** (value **of** **first** *XML element* **of** theAuthorElement **whose** name **is** "ForeName")

**set** initial **of** theAuthor **to** (value **of** **first** *XML element* **of** theAuthorElement **whose** name **is** "Initials")

**set** lastname **of** theAuthor **to** (value **of** **first** *XML element* **of** theAuthorElement **whose** name **is** "LastName")

**set** authors **of** theArticle **to** (authors **of** theArticle) & {theAuthor}

**end** **try**

**end** **repeat**

**end** **if**

-- Get publication types

**try**

**set** thePublicationTypeListElement **to** ( **first** *XML element* **of** theArticleElement **whose** name **is** "PublicationTypeList")

**set** thePublicationTypes **to** ( **every** *XML element* **of** thePublicationTypeListElement **whose** name **is** "PublicationType")

**repeat** **with** thePublicationType **in** thePublicationTypes

**set** publicationtypes **of** theArticle **to** (publicationtypes **of** theArticle) & {value **of** thePublicationType}

**end** **repeat**

**end** **try**

**end** **tell**

-- Prepate strings for some elements

**set** theAuthorsString **to** ""

**repeat** **with** theAuthor **in** authors **of** theArticle

**set** theAuthorString **to** firstname **of** theAuthor

**if** (theAuthorString ≠ "" **and** initial **of** theAuthor ≠ "") **then** **set** theAuthorString **to** theAuthorString & " " & initial **of** theAuthor

**if** (theAuthorString ≠ "" **and** lastname **of** theAuthor ≠ "") **then** **set** theAuthorString **to** theAuthorString & " " & lastname **of** theAuthor

**if** theAuthorString ≠ "" **then**

**if** theAuthorsString ≠ "" **then** **set** theAuthorsString **to** theAuthorsString & ", "

**set** theAuthorsString **to** theAuthorsString & theAuthorString

**end** **if**

**end** **repeat**

**set** thePublicationString **to** publication **of** publication **of** theArticle

**if** thePublicationString ≠ "" **then**

**if** vol **of** publication **of** theArticle ≠ "" **then**

**set** thePublicationString **to** thePublicationString & "; vol. " & vol **of** publication **of** theArticle

**else**

**set** thePublicationString **to** thePublicationString & ";"

**end** **if**

**end** **if**

**if** thePublicationString ≠ "" **and** issue **of** publication **of** theArticle ≠ "" **then** **set** thePublicationString **to** thePublicationString & " issue " & issue **of** publication **of** theArticle

**if** thePublicationString ≠ "" **and** publicationdate **of** publication **of** theArticle ≠ "" **then** **set** thePublicationString **to** thePublicationString & "; " & publicationdate **of** publication **of** theArticle

**if** publicationtypes **of** theArticle = {} **then**

**set** theTypeString **to** ""

**else**

**set** theTypeString **to** *item* 1 **of** publicationtypes **of** theArticle

**if** ( **count** **of** publicationtypes **of** theArticle) > 1 **then**

**repeat** **with** thePublicationType **in** *items* 2 **through** -1 **of** publicationtypes **of** theArticle

**set** theTypeString **to** theTypeString & ", " & thePublicationType

**end** **repeat**

**end** **if**

**end** **if**

-- Add article to DEVONthink

**if** abstract **of** theArticle ≠ "" **then**

**set** theAbstractString **to** abstract **of** theArticle

**else**

**set** theAbstractString **to** **my** helperLibrary's localizedString("No abstract available.") & return & return

**end** **if**

**set** thePlaceholders **to** {|%articleTitle%|:name **of** theArticle, |%articleAuthors%|:theAuthorsString, |%articleLocation%|:thePublicationString, |%articleType%|:theTypeString, |%articleAbstract%|:theAbstractString, |%articleLink%|:{|URL|:link **of** theArticle, |name|: **my** helperLibrary's localizedString("Click here to view article in PubMed")}}

**set** theRecord **to** « *event* DTpacd01» theTemplateFile **given** « *class* DTto»:theGroup, « *class* DTph»:thePlaceholders

« *event* DTpacd9a» (pubmedID **of** theArticle) **given** « *class* DTfo»:"pmid", « *class* DTto»:theRecord

**set** *URL* **of** theRecord **to** link **of** theArticle

**if** « *class* DTca» **is** *true* **then** **exit** **repeat**

**end** **repeat**

**end** **if**

« *event* DTpacd43»

**end** **tell**

**on** **error** errMsg number errNum

**tell** *application* *id* "DNtp"

« *event* DTpacd43»

**if** errNum ≠ -128 **then** **display alert** **my** helperLibrary's localizedString("An error has occured.") message errMsg & " :: " & errNum as *warning*

**end** **tell**

**end** **try**

It’s coded into PubMed. You can change it by appending &retmax=100 to the URL in this line:

set theSearchURL to (pURLSearch & "?db=pubmed&term=" & theQueryEscaped & "&retmode=xml&retmax=100") as string

Thanks

There must be something to the Script Editor I do not understand

After I make the above edit I get an error - even if I return the script back to its default the error still appears.

My original backup copy of the script still works but if I copy and edit it I am corrupting it somehow so it does not work any more.

Did you just add the &retmax=100 or did you copy and paste the code? Sometimes macOS likes to turn straight into curly quotes.

Anyway, here’s the updated template:

5 PubMed.templatescriptd.zip (32.5 KB)

That works -thanks