Scripting support in Papers

matthias's Avatar

matthias

12 Jul, 2014 01:50 PM

Hi,

this is meant as a public space to gather feedback, questions and sample scripts for the AppleScript support in Papers 3.0.35 and above.

Matthias (from the Papers Mac team)

Showing page 2 out of 7. View the first page

  1. 31 Posted by matthias on 23 Jul, 2014 08:12 AM

    matthias's Avatar

    Hi Johannes, many thanks for your script!

    Originally I thought that this:

    set pubList to every publication item
    set myList to {}
    repeat with i from 1 to count of pubList
        set aPub to item i of pubList
        if author names of aPub is not "" then
            copy aPub to end of myList
        end if
    end repeat
    
    could be replaced by just this (to make the script shorter):
    set myList to every publication item whose author names is not ""
    

    While the result would be the same, your repeat loop is actually much faster.

    When checking for the publication year, I think you need to include a check for "missing value":

    set myCleanList to {}
    repeat with i from 1 to count of myList
        set aPub to item i of myList
        set pubYear to publication year of aPub
        if pubYear is not "" and pubYear is not missing value then
            copy aPub to end of myCleanList
        end if
    end repeat
    

    It would be useful to create a variant of your script that works on the selected publications only, i.e. instead of:

    set pubList to every publication item
    

    it would use:

    set pubList to selected publications of front library window
    

    However, with the current script version, the citekey uniquing would then only be done among the list of selected publications, so that wouldn't work. Your script could, however, always ask Papers for the full list of cite keys:

    set refList to citekey of every publication item
    

    and then check that the generated citekey is not yet in that list.

    Thanks again for your efforts! I'm sure this will be useful to many other users.

    Matthias

  2. 32 Posted by matthias on 23 Jul, 2014 08:15 AM

    matthias's Avatar

    Hi xiehongming,

    I sometimes add a paper to A collections mistakenly, then How can I remove from A collections in Papers and let the paper remain in B collections?

    Please note that this is not a thread for general support requests, this thread is meant specifically for scripting-related questions, feedback and sample scripts. Please write your general questions to support -at- mekentosj -dot- com.

    Thanks!
    Matthias

  3. 33 Posted by jeff on 23 Jul, 2014 10:41 AM

    jeff's Avatar

    Hi xiehongming,
    I'll save you the trouble of writing to support. If A > B, then it's not possible. Removing A (or moving to B) will remove from B, and Support said, "this is the expected behavior." :-(

  4. 34 Posted by Axel on 23 Jul, 2014 02:24 PM

    Axel's Avatar

    Hi,

    I wonder whether it is possible to generate a script that will insert the LaTeX cite key for any paper that is currently highlighted in my Papers window using a text expander application such as Typinator. Does anybody know how to implement that?

    The idea is that I have Papers open on one screen while I'm writing in TeXShop and when I want to cite the respective paper which is active in my Papers app I can easily insert the cite key to that specific paper by Typinator.

    Any help with this would be great.

    Axel

  5. 35 Posted by matthias on 24 Jul, 2014 05:53 AM

    matthias's Avatar

    Hi Axel,

    I wonder whether it is possible to generate a script that will insert the LaTeX cite key for any paper that is currently highlighted in my Papers window using a text expander application such as Typinator.

    I'm not sure about Typinator, but TeXShop should be supported by Citations. I.e., you could simply use Citations to insert cite keys of publications in your Papers library.

    Alternatively, the AppleScript below will replace the current selection in the front TeXShop document with a "\cite{…}" string containing the cite keys of all publications selected in your Papers library.

    Please note that the cite keys must be defined, i.e., this script will not generate them if they are missing. You can enter your preferred cite command in the properties (citekeyPrefix & citekeySuffix) at the top of the script.

    Hope this helps,
    Matthias

    property citekeyPrefix : "\\cite{"
    property citekeySuffix : "}"
    
    set citekeyList to my citekeysOfSelectedPapers()
    tell application "TeXShop" to set selection of front document to my citekeyStringFromCiteKeys(citekeyList)
    
    on citekeysOfSelectedPapers()
        tell application id "com.mekentosj.papers3"
            set selectedPubs to selected publications of front library window
            set citekeyList to {}
            repeat with aPub in selectedPubs
                set aCitekey to citekey of aPub
                if aCitekey is not "" and aCitekey is not missing value then
                    copy aCitekey to end of citekeyList
                end if
            end repeat
        end tell
        return citekeyList
    end citekeysOfSelectedPapers
    
    on citekeyStringFromCiteKeys(citekeyList)
        set prevTIDs to text item delimiters of AppleScript
        set text item delimiters of AppleScript to ", "
        set citekeyText to (citekeyPrefix & citekeyList as text) & citekeySuffix
        set text item delimiters of AppleScript to prevTIDs
        return citekeyText
    end citekeyStringFromCiteKeys
    
  6. 36 Posted by Axel on 24 Jul, 2014 01:59 PM

    Axel's Avatar

    Hi Matthias,

    Thanks for pointing me in the right direction - this almost did what I needed. Here is what works for me:

    property citeKeyPrefix : "\\cite{"
    property citeKeySuffix : "}"
    set citekeyList to my citeKeysOfSelectedPapers()
    on citeKeysOfSelectedPapers()
        tell application id "com.mekentosj.papers3"
            set selectedPubs to selected publications of front library window
            set citekeyList to {}
            repeat with aPub in selectedPubs
                set aCitekey to citekey of aPub
                if aCitekey is not "" and aCitekey is not missing value then
                    copy aCitekey to end of citekeyList
                end if
            end repeat
        end tell
        return citekeyList
    end citeKeysOfSelectedPapers
    on citekeyStringFromCiteKeys(citekeyList)
        set prevTIDs to text item delimiters of AppleScript
        set text item delimiters of AppleScript to ", "
        set citekeyText to (citeKeyPrefix & citekeyList as text) & citeKeySuffix
        set text item delimiters of AppleScript to prevTIDs
        return citekeyText
    end citekeyStringFromCiteKeys
    return citekeyStringFromCiteKeys(citekeyList)
    

    That way I can call the script from Typinator just by using the following text expansion:

    {Scripts/papers_latex_citation_key.applescript}
    

    and it is also no longer specific to TeXShop but works with any text editor.

    Thanks again!
    Axel

  7. 37 Posted by matthias on 24 Jul, 2014 05:27 PM

    matthias's Avatar

    Hi Axel,

    I'm glad this was helpful to you.

    Thanks for pointing me in the right direction - this almost did what I needed. Here is what works for me:

    Cool, thanks for that. This is surely useful to other users.

    Best, Matthias

  8. 38 Posted by Chris on 03 Aug, 2014 12:12 AM

    Chris's Avatar

    I am trying to use applescript to pull notes and highlights from my papers. I would like to pull highlights individually, but I cannot seem to get anywhere. I cannot get any annotation items without running into an error.

    This, for example:

    tell application "Papers"  
        set p to selected publications of front library window  
        set text_1 to first highlight item of p  
    end tell
    

    I get

    error "Can’t get highlight item 1 of {publication item id \"D828CD87-D962-4155-8B2E-B2FFF1A0A340\" of application \"Papers\"}." number -1728 from «class PHiA» 1 of {«class PPub» id "D828CD87-D962-4155-8B2E-B2FFF1A0A340"}
    

    Any help is appreciated, thanks!

  9. 39 Posted by Stephan on 03 Aug, 2014 12:18 PM

    Stephan's Avatar

    Hi,

    I just upgraded to Papers3, because scripting support was added. Thank you so much for this, as it will extend papers´ usefulness tremendously! I am curiously looking forward to a script which adds notes et cetera to devonthink as it was already suggested here. Any news on this?

    Thanks!

    Stephan

  10. 40 Posted by matthias on 03 Aug, 2014 02:04 PM

    matthias's Avatar

    Hi Chris & Stephan,

    I promised to cook up a sample script for export of individual notes soon, but then got stuck in other activities, sorry! I'll try to look into this ASAP.

    Chris, re. your test script:

    tell application "Papers"
    set p to selected publications of front library window set text_1 to first highlight item of p
    end tell
    The first line (selected publications of front library window) returns a list of publications, even if this list only contains a single publication. I.e., you need to refer to the contained publication via first item of p and not just of p (which would refer to the list instead).

    Then, the annotations are elements of the (PDF) file, not the publication. I know this may sound not really intuitive, but it reflects Papers internal model. And it's in a way more future proof, if at some point, you could annotate multiple files that are all attached to the same publication.

    So, to get a list of all annotations for the first selected publication, you could use something like this:

    tell application "Papers"
        set p to selected publications of front library window
        set allAnnotations to annotation items of primary file item of first item of p
    end tell
    

    Note that, at the moment, you cannot refer to only the highlight items of a certain file item. This reminds me of an important item on my scripting TODO list: For the file item class, I need to add individual elements for note item, highlight item & ink annotation item. Currently, you can only get all of them at once. But you could of course filter them via AppleScript so that only the highlight items are left:

    set p to selected publications of front library window
    set allAnnotations to annotation items of primary file item of first item of p
    set allHighlightAnnotations to {}
    repeat with anAnnotation in allAnnotations
        if class of anAnnotation is highlight item then
            copy anAnnotation to end of allHighlightAnnotations
        end if
    end repeat
    get allHighlightAnnotations
    

    What is your ultimate goal? Export all highlight items of the selected publication(s) to individual text files? Or export all highlight items of all publications to individual text files?

    Thanks, Matthias

  11. 41 Posted by Stephan.Zellerh... on 03 Aug, 2014 02:31 PM

    Stephan.Zellerhoff's Avatar

    Hi Matthias!

    My ultimate goal is to export abstracts, citekeys, notes & highlights of a paper to a devonthink note. This note file should include a paper link url so that the corresponding pdf can be opened in papers easily. Maybe, indexing the corresponding pdf in devonthink is also possible (maybe difficult with the new library container - osxfuse??)? Once, there was a script by Robin Trew, but it stopped working a while ago due to changes in the papers database. I include a copy of it, but it was slightly modified for my setup…

    Best,
    Stephan

    Am 03.08.2014 um 16:05 schrieb matthias <[email blocked]<mailto:[email blocked]>>:

  12. 42 Posted by Stephan on 03 Aug, 2014 08:42 PM

    Stephan's Avatar

    Hi Matthias!

    Another request: Is it possible to place the paper link of each paper inside the spotlight comment box using a script? Opening the correct pdf in papers3 is then facilitated while using preview or e.g. foxtrot.

    Thanks in advance

    Stephan

  13. 43 Posted by matthias on 04 Aug, 2014 08:40 AM

    matthias's Avatar

    Hi Stephan,

    Is it possible to place the paper link of each paper inside the spotlight comment box using a script?

    Yes, that should be possible. You can get the Papers link of a publication like this:

    tell application "Papers"
        set selectedPubs to selected publications of front library window
        set papersLink to item url of first item of selectedPubs
    end tell
    

    Here's a script that takes all publications that are currently selected in Papers and copies their Papers link to the corresponding PDF file's Finder/Spotlight comment:

    tell application "Papers"
        set selectedPubs to selected publications of front library window
        repeat with aPub in selectedPubs
            set pdfPath to full path of primary file item of aPub
            if pdfPath is not "" or pdfPath is not missing value then
                set papersLink to item url of aPub
                tell me to set pdfFile to POSIX file pdfPath
                tell application "Finder" to set comment of (pdfFile as alias) to papersLink
            end if
        end repeat
    end tell
    

    Opening the correct pdf in papers3 is then facilitated while using preview or e.g. foxtrot

    How would this be done, also via a script?

    I'd like to provide similar functionality for the Papers virtual disk. I.e., somehow allow users to easily open the publication that corresponds to the selected PDF in Papers.

    Best, Matthias

  14. 44 Posted by Stephan.Zellerh... on 04 Aug, 2014 09:34 AM

    Stephan.Zellerhoff's Avatar

    Hi Matthias!

    I am thinking about a script-based OSx service that extracts the papers3 url from the spotlight comments and opens the pdf in papers3. This should be also be possible while browsing the papers virtual disks, shouldn´t it?

    Best,
    Stephan

    Von: matthias [mailto:[email blocked]]
    Gesendet: Montag, 4. August 2014 10:41
    An: [email blocked]
    Betreff: Re: Scripting support in Papers [Papers for Mac - Questions #105370]

  15. 45 Posted by matthias on 04 Aug, 2014 11:40 AM

    matthias's Avatar

    Hi Stephan,

    My ultimate goal is to export abstracts, citekeys, notes & highlights of a paper to a devonthink note. This note file should include a paper link url so that the corresponding pdf can be opened in papers easily. […] Once, there was a script by Robin Trew, but it stopped working a while ago due to changes in the papers database. I include a copy of it

    Thanks for the script and the info! I'll try to look into it but due to the complexity of the script, I might first start out a bit more simple. Still it's a very valuable resource!

    Best, Matthias

  16. 46 Posted by matthias on 04 Aug, 2014 12:11 PM

    matthias's Avatar

    Hi Stephan,

    I am thinking about a script-based OSx service that extracts the papers3 url from the spotlight comments and opens the pdf in papers3.

    Using Automator (see, e.g., here or here) or ThisService I think it should be possible to create a service from an AppleScript like this:

    tell application "Finder"
        set selectedFiles to selection as list
        repeat with aFile in selectedFiles
            set fileComment to comment of aFile
            if fileComment starts with "papers3://" and fileComment does not contain " " then
                open location fileComment
            end if
        end repeat
    end tell
    

    This should be also be possible while browsing the papers virtual disks, shouldn´t it?

    Theoretically yes, in practice unfortunately not. I tried hard to have the virtual disk mirror the Finder/Spotlight comments from the real PDF files on disk. While I could get labels working nicely (you can set Mavericks labels via the virtual disk, and they get applied to the real files, and vice versa), it never worked for comments. Sorry for the inconvenience!

    Best,
    Matthias

  17. 47 Posted by Stephan.Zellerh... on 04 Aug, 2014 01:31 PM

    Stephan.Zellerhoff's Avatar

    Hi Matthias!

    Thanks for your help! I will try your script ASAP. When I manually add a papers link to the comment field using finder, and then use xattr on the pdf file in the papers3 library virtual disk, I get something like this:

    com.apple.metadata:kMDItemFinderComment:
    00000000 62 70 6C 69 73 74 30 30 5F 10 3F 70 61 70 65 72 |bplist00_.?paper|
    00000010 73 33 3A 2F 2F 70 75 62 6C 69 63 61 74 69 6F 6E |s3://publication|
    00000020 2F 75 75 69 64 2F 36 41 31 34 42 44 35 44 2D 38 |/uuid/6A14BD5D-8|
    00000030 37 45 33 2D 34 39 32 38 2D 38 43 32 30 2D 30 33 |7E3-4928-8C20-03|
    00000040 44 36 30 39 45 33 36 30 30 30 08 00 00 00 00 00 |D609E36000......|
    00000050 00 01 01 00 00 00 00 00 00 00 01 00 00 00 00 00 |................|
    00000060 00 00 00 00 00 00 00 00 00 00 4A |..........J|
    0000006b

    Apparently, there is the link embedded in the comment. I will play around a bit with this…

    Best,

    Stephan

    Am 04.08.2014 um 14:12 schrieb matthias <[email blocked]<mailto:[email blocked]>>:

  18. 48 Posted by matthias on 04 Aug, 2014 02:59 PM

    matthias's Avatar

    Hi Chris,

    I am trying to use applescript to pull notes and highlights from my papers. I would like to pull highlights individually, but I cannot seem to get anywhere.

    The script below will save all Papers notes and highlight annotations of all selected publications to individual text files.

    I realise that the script could be more structured/polished and that the text file layout is not exactly what you imagined. But it should serve as a good starting point, and it should be easy to modify the text file layout or the output folder path etc.

    Hope this helps!
    Matthias

    tell application "Papers"
        set selectedPubs to selected publications of front library window
        set allAnnotations to {}
        repeat with aPub in selectedPubs
            set pubAnnotations to annotation items of primary file item of aPub
            repeat with anAnnotation in pubAnnotations
                copy anAnnotation to end of allAnnotations
            end repeat
        end repeat
        
        set desktopFolderPath to POSIX path of file ((path to desktop from user domain) as string)
        set containerFolderPath to my createNewFolder(desktopFolderPath, "Papers Annotations")
        
        my writeAnnotationsToTextFiles(containerFolderPath, allAnnotations)
    end tell
    
    
    --- Takes a list of Papers annotations and writes them to individual text files.
    --- Text files will be written to subfolders (one per publication) within the given container folder.
    --- Note that annotations for publications that don't have a title will be ignored.
    on writeAnnotationsToTextFiles(containerFolderPath, annotationsList)
        tell application "Papers"
            set previousPubTitle to ""
            set fileNamePrefix to 1
            set ct to count of annotationsList
            repeat with i from 1 to ct
                set anAnnotation to item i of annotationsList
                set aPubTitle to title of publication item of source file of anAnnotation
                if aPubTitle is not "" and aPubTitle is not missing value then
                    -- NOTE: this will only be correct if annotationsList is sorted by publication
                    if aPubTitle is not equal to previousPubTitle then
                        set previousPubTitle to aPubTitle
                        set fileNamePrefix to 1
                    else
                        set fileNamePrefix to fileNamePrefix + 1
                    end if
                    set theSubFolderPath to my createNewFolder(containerFolderPath, aPubTitle)
                    set theFileName to fileNamePrefix & "-" & resource type of anAnnotation & ".txt"
                    set theFilePath to theSubFolderPath & theFileName
                    tell me to set theAnnotationFile to POSIX file theFilePath
                    set theAnnotationText to my summarizeAnnotation(anAnnotation)
                    my writeTextToFile(theAnnotationFile, theAnnotationText)
                end if
            end repeat
        end tell
    end writeAnnotationsToTextFiles
    
    
    -- Takes a Papers note or highlight annotation and returns a formatted summary of the annotation as text.
    on summarizeAnnotation(anAnnotation)
        tell application "Papers"
            set anAnnotationClass to class of anAnnotation
            set annotationSummary to ""
            if anAnnotationClass is highlight item or anAnnotationClass is note item then
                set aPub to publication item of source file of anAnnotation
                set {aPubTitle, anItemURL, aCitekey} to {title, item url, citekey} of aPub
                if aPubTitle is "" or aPubTitle is missing value then
                    set aPubTitle to "(Untitled)"
                end if
                if aCitekey is "" or aPubTitle is missing value then
                    set aCitekey to "(Undefined cite key)"
                end if
                set annotationSummary to formatted reference of aPub & linefeed & aCitekey & linefeed & anItemURL ¬
                    & linefeed & linefeed & content summary of anAnnotation & linefeed & linefeed
            end if
            return annotationSummary
        end tell
    end summarizeAnnotation
    
    
    --- Creates a new folder of the given name at the given folder location (specified as POSIX path),
    --- and returns the newly created (or existing) folder's POSIX path.
    on createNewFolder(aFolderPOSIXPath, aFolderName)
        set aFolderName to cleanFolderName(aFolderName)
        set containerFolder to POSIX file aFolderPOSIXPath as alias
        tell application "Finder"
            set newFolderPath to (folder containerFolder as string) & aFolderName
            if not (exists folder newFolderPath) then
                set newFolderPath to (make new folder at folder containerFolder with properties {name:aFolderName}) as string
            end if
            return POSIX path of (alias newFolderPath)
        end tell
    end createNewFolder
    
    
    on cleanFolderName(aFolderName)
        set aFolderName to my replaceText(":", " - ", aFolderName)
        set aFolderName to my replaceText("/", " - ", aFolderName)
        set aFolderName to my replaceText("  ", " ", aFolderName) -- removes double whitespace (a regex replace would be better)
        return aFolderName
    end cleanFolderName
    
    
    -- Replaces a string of text with another.
    on replaceText(find, replace, someText)
        considering case
            set prevTIDs to text item delimiters of AppleScript
            set text item delimiters of AppleScript to find
            set textItemList to text items of someText
            set text item delimiters of AppleScript to replace
            set newText to textItemList as text
            set text item delimiters of AppleScript to prevTIDs
        end considering
        return newText
    end replaceText
    
    
    --- Saves a text file to the given file. Note that this will replace any existing file content.
    on writeTextToFile(aFile, theText)
        set aFileRef to open for access aFile with write permission
        set eof aFileRef to 0
        write theText to aFileRef as «class utf8»
        close access aFileRef
    end writeTextToFile
    
  19. 49 Posted by matthias on 04 Aug, 2014 03:03 PM

    matthias's Avatar

    Hi Chris,

    as a quick follow-up to my previous post, it's worth noting that you can run the script multiple times, and it will add new files for newly created annotations. However, if you modify any of these annotation text files, the next time you run the script, these changes will get overridden again!

    This probably means we should try to add a comment field for highlight annotations ASAP. :-)

    Best,
    Matthias

  20. 50 Posted by Stephan.Zellerh... on 05 Aug, 2014 09:06 AM

    Stephan.Zellerhoff's Avatar

    Hi!

    Both your scripts work well. Exporting the link to the spotlight comments and also opening the PDF in papers again. But, as you mentioned before, the comments are lost After restarting. Do you know how to change the mount options for the virtual disk?

    Best,

    Stephan

    Am 04.08.2014 um 13:40 schrieb "matthias" <[email blocked]<mailto:[email blocked]>>:

  21. 51 Posted by matthias on 05 Aug, 2014 01:12 PM

    matthias's Avatar

    Hi Stephan,

    Both your scripts work well.

    I'm glad to hear this.

    But, as you mentioned before, the comments are lost After restarting. Do you know how to change the mount options for the virtual disk?

    Mount options need to be changed in Papers itself. However, I don't think there's some mount option that would make for a different behavior w.r.t. this issue (but I'd be happy to be proven wrong!). I'll try to look into this again.

    Also, if Spotlight comments from the real files cannot be mirrored in the virtual disk, Papers could (on mount) set the Papers link as the Spotlight comment for all virtual files (not sure if that's possible, though). This way, you'd only need the second script/service to open the corresponding publication in Papers.

    Best,
    Matthias

  22. 52 Posted by Axel on 07 Aug, 2014 07:44 PM

    Axel's Avatar

    Hi Matthias,

    I have one more idea for a script that would be useful to me:

    Is it possible to write a script that I could start from Alfred to use a DOI and then search for the paper using the ID tag in the search function of the Papers App?

    This would be really helpful when searching for a large number of papers from a list or website.

    Best wishes,
    Axel

  23. 53 Posted by Lars Lundqvist on 07 Aug, 2014 10:27 PM

    Lars Lundqvist's Avatar

    Referring back to my first post in this thread, I need a very simple script that collect the three items you get if you choose Copy As - Papers Link, Papers citation, Notes, and put them on the Clipboard, i.e. a script that reduces three consecutive copy-paste into one. But to do that I need to know the variable names for those three items in Papers3.

    Where do I find the internat Papers3 variable names so that I can refer to them?

  24. 54 Posted by matthias on 08 Aug, 2014 10:01 AM

    matthias's Avatar

    Hi Axel,

    Is it possible to write a script that I could start from Alfred to use a DOI and then search for the paper using the ID tag in the search function of the Papers App?

    I'm not really sure I understand what you're trying to do. Did I understand you correctly that you want to use Alfred to find a paper in your Papers library by DOI?

    This AppleScript selects all publications in your library that match the given DOI:

    tell application "Papers"
        activate
        set dialogResult to display dialog "Select publications with DOI:" default button "OK" cancel button "Cancel" with icon 1 default answer ""
        if button returned of dialogResult is "Cancel" then error -128
        set aDOI to text returned of dialogResult
        set pubList to every publication item whose doi is aDOI
        tell front library window to set selected publications to pubList
    end tell
    

    Let me know if you wanted to do something else.

    Best,
    Matthias

  25. 55 Posted by Axel on 08 Aug, 2014 10:28 AM

    Axel's Avatar

    Hi Matthias,

    Thanks for having a go at this. I think I didn’t explain too well what I was after though - what I wanted to do is the following scenario:

    1) I have a list of references from a really old paper that doesn’t yet have clickable links for its references but I would like to import all the references into my Papers library.

    2) Using the CrossRef simple text query I can get most of the DOIs by copy and paste from the old paper

    3) I would now like to copy each DOI into my clipboard and then start and Alfred workflow that opens Papers, enters the DOI into the search dialog (the only corresponding to the symbol with the magnifying glass and the plus sign) and runs the search query with my favourite search engines.

    4) I would then manually have a look at the results list and import the correct paper with a click

    Do you have an idea how to best achieve this?

    Best wishes,
    Axel

  26. 56 Posted by matthias on 08 Aug, 2014 10:49 AM

    matthias's Avatar

    Hi Axel, thanks for clarifying what you're after. I fear that isn't possible with AppleScript at the moment (however, see the suggestions below).

    However, have you tried to copy the list of references from the PDF and simply paste that list into the sheet that is displayed when you chose "File > New Paper > From Reference…"?

    Notes about the "New From Reference" feature:

    • I think that the used CrossRef service only accepts 20 records in one go. So you might need to perform multiple passes – but that would be still faster than doing it manually.
    • Also please note that each reference must be on a single line. I.e., when copying references from a 2-column PDF, the references often contain return/newline characters. So before pasting, you'd need to edit the copied text to remove the extra return/newline characters so that each reference is on a single line.

    And here's yet another approach:

    As mentioned in our Getting Started Guide, you can use the AppleScript match command to complete metadata for newly created publications. I.e., for each paper you'd like to import, you could create a new publication with just the DOI or the title (you can simply use the entire reference as the title), and then let Papers fetch missing metadata (and possibly the PDF) via matching:

    tell application "Papers"
        set newPub to make new publication item with properties {title:"Stapleton, Seth, Michelle LaRue, Nicolas Lecomte, Stephen Atkinson, David Garshelis, Claire Porter, and Todd Atwood. 2014. “Polar Bears From Space: Assessing Satellite Imagery as a Tool to Track Arctic Wildlife.” Edited by Yan Ropert-Coudert. PLoS ONE 9 (7). Public Library of Science: e101513"}
        delay 0.5
        set selected publications of front library window to (newPub as list)
        set matchedPubs to match (newPub as list) with replacing metadata
    end tell
    

    Hope this helps,
    Matthias

  27. 57 Posted by matthias on 08 Aug, 2014 11:37 AM

    matthias's Avatar

    Hi Lars,

    I Copy As - Notes, Link and Magic citation (i.e three copy-paste) to get the wanted info from Papers 3 to Scapple for further thought and analyses. Would it be possible to write an Apple script that does all of this in one move and not three?

    Here's an AppleScript that copies all notes & highlight annotations of all selected publications to the clipboard.
    For each publication, the Papers link as well as the cite key are included above the notes & annotations.

    tell application "Papers"
        set selectedPubs to selected publications of front library window
        set allPubTexts to {}
        repeat with aPub in selectedPubs
            set pubNotes to content summary of every annotation item of primary file item of aPub
            set mergedNotes to my mergeTextItems(pubNotes, linefeed & linefeed & "---" & linefeed & linefeed)
            set pubText to item url of aPub & linefeed & linefeed ¬
                & "{" & citekey of aPub & "}" & linefeed & linefeed ¬
                & mergedNotes & linefeed
            copy pubText to end of allPubTexts
        end repeat
        set the clipboard to my mergeTextItems(allPubTexts, linefeed & linefeed & linefeed & "---------" & linefeed & linefeed & linefeed & linefeed)
        display dialog "Copied notes of " & (count of selectedPubs) & " publications to the clipboard." buttons {"OK"} default button "OK" with icon 1
    end tell
    
    
    -- Merges the given list of text items using the given separator string
    on mergeTextItems(textItemList, aSeparator)
        considering case
            set prevTIDs to text item delimiters of AppleScript
            set text item delimiters of AppleScript to aSeparator
            set mergedText to textItemList as text
            set text item delimiters of AppleScript to prevTIDs
        end considering
        return mergedText
    end mergeTextItems
    

    HTH, Matthias

  28. 58 Posted by matthias on 08 Aug, 2014 11:41 AM

    matthias's Avatar

    Hi Lars, as a quick follow-up to my previous post, you wrote:

    Where do I find the internat Papers3 variable names so that I can refer to them?

    The Papers AppleScript dictionary documents all available objects, properties & commands. Please see our Getting Started Guide, esp. this section: http://support.mekentosj.com/kb/papers-3-for-mac-how-to/scripting-p...

  29. 59 Posted by findingbenjamin on 08 Aug, 2014 03:44 PM

    findingbenjamin's Avatar

    This discussion has been extremely helpful; I appreciate all the advice offered thus far!

    I'm using Scrivener, Skim and Papers3; for writing, reading, and file management. If I'm reading a PDF in Skim, and make a note about that article, I'd like to write a script that can, using the open PDF in skim, pull up and select the same source in papers3 and make a reference that includes: (eg. item URL, cite key, title, author name, publication year), so that every note I take will have a 'reference stamp' linking back to the original document. I've seen similar questions posted here using TextEdit and BibDesk, but I'm missing a couple of steps.

    One of the main things I want to be able to do is automatically have the current PDF in Skim display the same document in Papers3. That way, even if I have a bunch of PDFs open, and I want to make a reference, when I run a macro to get the citekey or item url, it will retrieve the information of the PDF that's open and I won't have to manually search papers3 to make sure the correct one is selected. Does that make sense?

  30. 60 Posted by matthias on 08 Aug, 2014 04:18 PM

    matthias's Avatar

    Hi Benjamin,

    I'm glad that the discussion is useful for you!

    If I'm reading a PDF in Skim, and make a note about that article, I'd like to write a script that can, using the open PDF in skim, pull up and select the same source in papers3

    That should be doable.

    and make a reference that includes: (eg. item URL, cite key, title, author name, publication year), so that every note I take will have a 'reference stamp' linking back to the original document.

    I'm not sure I fully understand. You want to annotate the PDF in Skim, then open the publication that corresponds to the same PDF in Papers, and then make another note entry where? In Skim or in Papers?

    Or do you meant to supplement your note in Skim with the item URL, cite key & reference info from Papers?

    Thanks, Matthias

Discussions are closed to public comments.
If you need help with Papersapp please start a new discussion.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac