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 3 out of 7. View the first page

  1. 61 Posted by findingbenjamin on 08 Aug, 2014 06:09 PM

    findingbenjamin's Avatar

    Hello Matthias,

    I've sent several full-days trying to figure this out; I appreciate your quick response!

    When I read something in a PDF that I want to include in a paper I'm writing, I open up a 'Scratch Pad' window in Scrivener which allows me add a note that can be inserted into any section/file of my current writing document. Since these snippets are going into various areas of my paper, I want to keep track of where every idea came from. I might write 20 sentences of notes about a single PDF which could end up in 20 different paragraphs of my own paper; therefore, for each note I take, I want to have the URL, cite key refs attached to it.

    Ideally, it would look something like this:

    ====
    (Author, year): Title of Paper.
    Blue notes to indicate that they were cut and pasted or direct quotes from other sources, notes, blah, blah, blah blah.
    papers3://author/uuid/AD77A6A2-7820-46D0-9EA0-2B8F0B475E8F
    My own notes/words in a different color to make it obvious that these are mine.
    {cite key}
    ====

    I use keyboard Maestro to create macros to do similar stuff like the one above, but I think applescripting could make it a much cleaner process. And like I said, what I haven't been able to do is to start with a PDF in skim and retrieve the url links and matching papers3 info.

    Looking forward to your response.

    Cheers,

    Benjamin

  2. 62 Posted by matthias on 08 Aug, 2014 10:03 PM

    matthias's Avatar

    Hi Benjamin,

    thanks for the detailed info and the example, that's helpful.

    for each note I take, I want to have the URL, cite key refs attached to it.

    Ok, except for the different colors that should be easily doable. If you just want the publication info from Papers inserted into your note, then it's also not necessary to open/select the PDF in Papers, you'd just grab the info via AppleScript from Papers and copy it to the clipboard – or, if Scrivener's scratch pad is scriptable, insert it right there.

    I haven't looked at Skim's AppleSript dictionary but I guess it's easy to get the text selected in a PDF. If so, you could select the text in Skim that you'd like to have included as direct quote, then run the script. The script would then assemble your note "template" for Scrivener. In addition, it could even create an accompanying Skim or Papers annotation and (if possible) link to the note in Scrivener.

    I'll try to make a small sample script along these lines but I cannot really promise if or when this will happen. Please feel free to remind me about it!

    Best regards, Matthias

  3. 63 Posted by findingbenjamin on 11 Aug, 2014 01:32 PM

    findingbenjamin's Avatar

    If you could help me with just the first part, I can piece together the rest. I need to figure out a script/macro that can return papers' information (link url, author, title etc...) by using the current PDF I'm reading in Skim as the starting point.

    I want make the current PDF in Skim the current PDF in papers3.

    I download a lot of PDFs, but those PDFs don't always save to the papers3 database. This slows down the actual writing process when I'm trying to insert a citekey, and the search comes up empty. I wrote a macro in keystroke maestro that, after copying the title of the paper in Skim, opens papers3 and does a search by title. This usually tells me if I actually have the paper; however, due to differences in the PDF markup, the title from the copy-paste doesn't always match what's in my database, and I mistakingly believe I don't have the paper.

    Would love it if anyone could chime in with ideas or suggestions.

    Cheers,

    benjamin

  4. 64 Posted by matthias on 11 Aug, 2014 01:41 PM

    matthias's Avatar

    Hi Benjamin,

    If you could help me with just the first part, I can piece together the rest. I need to figure out a script/macro that can return papers' information (link url, author, title etc...) by using the current PDF I'm reading in Skim as the starting point.

    Ok, I'll try to do that.

    I want make the current PDF in Skim the current PDF in papers3.

    Note that you can get the information of a certain object (publication, PDF, author, etc) from Papers without "making it the current PDF" (i.e., selecting it's corresponding publication) in Papers. Is there any other/additional reason why you'd like to select the PDF in Papers.

    If you just want to get the corresponding publication's info (Papers link, etc), then I'd suggest to amke another script that simply selects the publication in Papers whose PDF is currently displayed in Skim. That way, these scripts are independent from each other.

    I wrote a macro in keystroke maestro that, after copying the title of the paper in Skim, opens papers3 and does a search by title.

    Just to understand you correctly: The PDF that's displayed in Skim is actually from your Papers library? If so, then I guess I could simply search by file path (instead of title).

    Thanks,
    Matthias

  5. 65 Posted by findingbenjamin on 11 Aug, 2014 01:57 PM

    findingbenjamin's Avatar

    Matthias,

    If I'm reading an article using paper's reader and I select file>export>notes, the window switches to the selected article in the Library--which is not necessarily the same paper I'm annotating. The same problem occurs when I'm reading an article in Skim.

    Usually the PDF displayed in Skim is in my Papers library. I've tried searching by path, but then when I open it in Papers, an additional record is opened for the same paper.

    A script that simply selects the publication in Papers whose PDF is currently displayed in Skim is exactly what I'm looking for. If the script finds the article in Papers; it would ideally display it in Papers, and If it finds nothing; then I know I need to make a new record in Papers. I generally like to have the current PDF displayed in Papers so I can confirm metadata and make changes as I gather more information.

    Thanks for your help.

    b

  6. 66 Posted by matthias on 11 Aug, 2014 02:25 PM

    matthias's Avatar

    Hi Benjamin,

    A script that simply selects the publication in Papers whose PDF is currently displayed in Skim is exactly what I'm looking for.

    Here's a script that takes the frontmost PDF in Skim and selects its corresponding publication in Papers (if there's any):

    set pdfPath to ""
    
    tell application "Skim"
        set pdfDocs to every document
        if pdfDocs is {} then
            display dialog "Please open a PDF and run this script again." & linefeed & linefeed & "This script takes the frontmost PDF in Skim and selects its corresponding publication in Papers." with title "No open document…" with icon 1 buttons {"OK"} default button "OK"
        else
            set pdfDoc to first item of pdfDocs
            set pdfFile to file of pdfDoc
            set pdfPath to POSIX path of pdfFile
        end if
    end tell
    
    tell application "Papers"
        set pdfList to every primary file item whose full path is pdfPath
        if (count of pdfList) is 0 then
            display dialog "Couldn't find a publication for this PDF:" & linefeed & linefeed & pdfPath with title "No Papers publication…" with icon 1 buttons {"OK"} default button "OK"
        else if (count of pdfList) is 1 then
            set thePublication to publication item of first item of pdfList
            if thePublication is not missing value then
                set pubList to thePublication as list
                tell front library window to set selected publications to pubList
            end if
        end if
    end tell
    

    I generally like to have the current PDF displayed in Papers so I can confirm metadata and make changes as I gather more information.

    I see. Thanks for the clarification

    Best, Matthias

  7. 67 Posted by matthias on 11 Aug, 2014 02:52 PM

    matthias's Avatar

    Hi Benjamin,

    I need to figure out a script/macro that can return papers' information (link url, author, title etc...) by using the current PDF I'm reading in Skim as the starting point.

    Here's a variant of the above posted script which takes the front PDF document in Skim and:

    1) selects its corresponding publication in Papers.
    2) returns a text block with info for the publication/PDF (author, year, title, Papers link etc.)

    If you have some text selected in the frontmost PDF document in Skim, this text will be also included in the returned info.

    set pdfPath to ""
    
    tell application "Skim"
        set pdfDocs to every document
        if pdfDocs is {} then
            display dialog "Please open a PDF and run this script again." & linefeed & linefeed & "This script takes the frontmost PDF in Skim and selects its corresponding publication in Papers." with title "No open document…" with icon 1 buttons {"OK"} default button "OK"
        else
            set pdfDoc to first item of pdfDocs
            set pdfFile to file of pdfDoc
            set pdfPath to POSIX path of pdfFile
            set selectedText to selection of document 1 as text
        end if
    end tell
    
    tell application "Papers"
        set pdfList to every primary file item whose full path is pdfPath
        if (count of pdfList) is 0 then
            display dialog "Couldn't find a publication for this PDF:" & linefeed & linefeed & pdfPath with title "No Papers publication…" with icon 1 buttons {"OK"} default button "OK"
        else if (count of pdfList) is 1 then
            set aPub to publication item of first item of pdfList
            if aPub is not missing value then
                set pubList to aPub as list
                tell front library window to set selected publications to pubList
                return my papersInfoForPublication(aPub, selectedText)
            end if
        end if
    end tell
    
    
    -- Returns metadata info (like author, year & title) and the Papers link for the given publication
    -- The text in includeText will be included in the returned output
    on papersInfoForPublication(aPub, includeText)
        tell application "Papers"
            set pubInfo to {"===", ¬
                "(" & author info of aPub & ", " & publication year of aPub & "): " & title of aPub, ¬
                includeText, ¬
                item url of aPub, ¬
                "", ¬
                "{" & citekey of aPub & "}", ¬
                "===" & linefeed}
            return my mergeTextItems(pubInfo, linefeed & linefeed)
        end tell
    end papersInfoForPublication
    
    
    -- 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
    

    Hope this helps,
    Matthias

  8. 68 Posted by findingbenjamin on 11 Aug, 2014 04:20 PM

    findingbenjamin's Avatar

    Matthias,

    These scripts are perfect! You have done a fantastic job; and I thank you for your willingness to help!

    Cheers,

    Benjamin

  9. 69 Posted by matthias on 11 Aug, 2014 05:01 PM

    matthias's Avatar

    Hi Benjamin,

    These scripts are perfect!

    Great, I'm glad they work for you!

    Best, Matthias

  10. 70 Posted by findingbenjamin on 11 Aug, 2014 05:27 PM

    findingbenjamin's Avatar

    The first time I use this script, it works just fine. But on subsequent attempts, the citekey returns as "{missing value}."

    set pdfPath to ""
    tell application "Skim"
    set pdfDocs to every document
    if pdfDocs is {} then
    display dialog "Please open a PDF and run this script again." & linefeed & linefeed & "This script takes the frontmost PDF in Skim and selects its corresponding publication in Papers." with title "No open document…" with icon 1 buttons {"OK"} default button "OK"
    else
    set pdfDoc to first item of pdfDocs
    set pdfFile to file of pdfDoc
    set pdfPath to POSIX path of pdfFile
    set selectedText to selection of document 1 as text
    end if
    end tell
    tell application "Papers"
    set pdfList to every primary file item whose full path is pdfPath
    if (count of pdfList) is 0 then
    display dialog "Couldn't find a publication for this PDF:" & linefeed & linefeed & pdfPath with title "No Papers publication…" with icon 1 buttons {"OK"} default button "OK"
    else if (count of pdfList) is 1 then
    set aPub to publication item of first item of pdfList
    if aPub is not missing value then
    set pubList to aPub as list
    tell front library window to set selected publications to pubList
    return my papersInfoForPublication(aPub, selectedText)
    end if
    end if
    end tell
    -- Returns metadata info (like author, year & title) and the Papers link for the given publication
    -- The text in includeText will be included in the returned output
    on papersInfoForPublication(aPub, includeText)
    tell application "Papers"
    set pubInfo to {"===", ¬
    "(" & author info of aPub & ", " & publication year of aPub & "): " & title of aPub, ¬
    includeText, ¬
    item url of aPub, ¬
    "", ¬
    "{" & citekey of aPub & "}", ¬
    "===" & linefeed}
    return my mergeTextItems(pubInfo, linefeed & linefeed)
    end tell
    end papersInfoForPublication
    -- 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

    "===

    (Yokoe, 2009): Pitfalls in sentinel lymph node biopsy

    papers3://publication/doi/10.1007/s12282-009-0170-4

    {missing value}

    ===
    "

     Also, what do I need to do in order to format the return without any spaces? ie, so it appears like this:

    ===
    (Yokoe, 2009): Pitfalls in sentinel lymph node biopsy
    papers3://publication/doi/10.1007/s12282-009-0170-4
    {Yokoe:2009cx}
    ===

    I realize I need to do some further reading/study on scripts in order to fully understood what you've done with the above. If you don't have time, I totally understand. Thanks again for all your help.

    Cheers,

    benjamin

  11. 71 Posted by matthias on 11 Aug, 2014 06:43 PM

    matthias's Avatar

    Hi Benjamin,

    But on subsequent attempts, the citekey returns as "{missing value}."

    Ah, right, I forgot to tell you about this, sorry! It's nothing wrong with the script or you not understanding correctly. It's simply a bug in the current Papers version! :-/ The fact that cite key returns "missing value" should not depend on how often you run the script. Instead it happens with certain publications. I think that all publications that have never been exported (e.g., to BibTeX) will likely have this problem.

    If you have a publication whose citekey is returned as "missing value", please try to export this publication as BibTeX once, then run the script again. Does this help?

    I'll try to fix this citekey issue as soon as possible.

    Also, what do I need to do in order to format the return without any spaces?

    That should be easy: In the lower half of the second script that I've posted above, in function papersInfoForPublication(), there's this line:

    return my mergeTextItems(pubInfo, linefeed & linefeed)
    

    Please change this line so that it reads:

    return my mergeTextItems(pubInfo, linefeed)
    

    Now, only a single newline should get inserted between elements.

    Best, Matthias

  12. 72 Posted by Lars Lundqvist on 11 Aug, 2014 09:47 PM

    Lars Lundqvist's Avatar

    Matthias,
    I only made a minor adjustment in the script you kindly provided, and it gives me exactly what I want, except for one minor detail. The Papers link isn't a link when I paste the info from the Clipboard into some other app. It's just plain text.
    Do you have any idea? I looked at Benjamin Turners script but can't see why his output seems to be a link whereas mine is not.
    /Lars

    Edit:
    The only change I made to the script was to add the formatted reference before the item url.

    set pubText to formatted reference of aPub & linefeed & linefeed ¬
    & item url of aPub & linefeed & linefeed ¬
    & "{" & citekey of aPub & "}" & linefeed & linefeed ¬
    & mergedNotes & linefeed

  13. 73 Posted by matthias on 12 Aug, 2014 10:40 AM

    matthias's Avatar

    Hi Lars,

    The Papers link isn't a link when I paste the info from the Clipboard into some other app. It's just plain text.

    I fear, by default any output from AppleScript is plain text. And I'm not really sure how to convert it to rich text.

    FWIW, TextEdit.app allows you to select the link and then choose to convert it into a clickable link (via the contextual menu).

    The behavior also differs among different apps. Some will automatically convert something that looks like a link.

    I looked at Benjamin Turners script but can't see why his output seems to be a link whereas mine is not.

    I couldn't reproduce this. For me, all output from all scripts is just plain text.

    Matthias

  14. 74 Posted by Rafal on 12 Aug, 2014 02:43 PM

    Rafal's Avatar

    Hello
    Is it possible to write a script that assigns attributes such as title and author to PDF files?
    Is it possible to write a script that exports articles (PDF files) with change files names to "Author, Year - Title" ?.
    Sorry for the simple questions, but I do not know much about writing scripts :(
    Looking forward to your response.
    Best wishes
    Rafal

  15. 75 Posted by matthias on 12 Aug, 2014 04:17 PM

    matthias's Avatar

    Hi Rafal,

    Is it possible to write a script that assigns attributes such as title and author to PDF files?

    I'm not entirely sure what you mean. Do you mean setting the publication metadata (such as title and authors) as extended attributes?

    Is it possible to write a script that exports articles (PDF files) with change files names to "Author, Year - Title" ?.

    When using Papers to export files (or when using the "Send via Email" commands from the "Share" menu) Papers uses the file renaming settings that you've specified in the "Library" tab of the Papers preferences. So, you shouldn't need a script to export files with names set to "Author, Year - Title". Instead, adjust the file renaming settings in the prefs and click the "Apply" button.

    Hope this helps,
    Matthias

  16. 76 Posted by rafal.kocierz on 12 Aug, 2014 04:35 PM

    rafal.kocierz's Avatar

    Thanks for your help :)
    >> Is it possible to write a script that assigns attributes such as title and author to PDF files?
    >
    > I'm not entirely sure what you mean. Do you mean setting the publication metadata (such as title and authors) as extended attributes?
    >
    > Is it possible to write a script that exports articles (PDF files) with change files names to "Author, Year - Title" ?.
    Yes :) Look at the screenshot.

    >> Is it possible to write a script that exports articles (PDF files) with change files names to "Author, Year - Title" ?.
    >
    > When using Papers to export files (or when using the "Send via Email" commands from the "Share" menu) Papers uses the file renaming settings that you've specified in the "Library" tab of the Papers preferences. So, you shouldn't need a script to export files with names set to "Author, Year - Title". Instead, adjust the file renaming settings in the prefs and click the "Apply" button.

    Thank you very much, I forgot about this feature.

    Thanks again for your help

    Best regards
    Rafal

    Wiadomość napisana przez matthias <[email blocked]> w dniu 12 sie 2014, o godz. 18:18:

  17. 77 Posted by matthias on 12 Aug, 2014 06:29 PM

    matthias's Avatar

    Hi Rafal,

    you're welcome

    Do you mean setting the publication metadata (such as title and authors) as extended attributes?

    yes :) Look at the screenshot.

    Ok, thanks, so you mean the PDF metadata (document attributes). This would be more difficult from AppleScript than setting the OS X extended attributes via AppleScript, though AppleScript-ObjC (a technology where you can call Cocoa functionality from within AppleScript) might be helpful. What is the use case for your request? Maybe this info helps to come up with an equally working solution.

    Thanks,
    Matthias

  18. 78 Posted by rafal.kocierz on 12 Aug, 2014 07:29 PM

    rafal.kocierz's Avatar

    The above mentioned functionwill by useful for me to searching articles
    on the computer where I have not installed Papers (on work) -
    synchronization via Dropbox.
    Mayby I will try touse piece of code given earlier anduse PDFpen or Skim
    (applescript).
    1. Open the file in PDFpen or Skim
    2. Readfile information from the Papers database by file name (path)
    3. Writing metadata to PDF

    Best wishes
    Rafal

    matthias wrote:

  19. 79 Posted by findingbenjamin on 12 Aug, 2014 09:05 PM

    findingbenjamin's Avatar

    I should have chimed in earlier. My script only returns text as well.

    -b

  20. 80 Posted by matthias on 13 Aug, 2014 01:44 PM

    matthias's Avatar

    Hi Rafal,

    thanks for the clarification.

    The above mentioned functionwill by useful for me to searching articles on the computer where I have not installed Papers (on work) - synchronization via Dropbox.

    The below script will walk all selected publications that have a PDF, and set the PDF document attributes (Title, Author, Subject, Keywords) to appropriate publication metadata. By default, the title contains the DOI which helps Papers to automatically match the paper on import.

    Note that the script may be a bit slow. Thus, I'd try it with just a few papers first.

    Also, it's important to note that this script cannot be run without the "Papers Scripting Lib" which is attached to this post. This is a scripting library that must be unzipped and then placed into your Library folder, inside a "Script Libraries" folder (i.e., at ~/Library/Script Libraries/). You may need to create the "Script Libraries" folder if it's not there yet.

    Let me know if the script doesn't work for you.

    Hope this helps, Matthias

    -- This script requires the Papers Scripting Lib
    
    use PapersLib : script "PapersScriptingLib"
    use scripting additions
    
    -- Set to `false` if you don't want the DOI to get appended to the publication title.
    -- On import, Papers will recognize a DOI in the title field and can use it for auto-matching.
    property appendDOIToTitle : true
    
    tell application "Papers"
        set selectedPubs to selected publications of front library window
        if selectedPubs is {} then
            display dialog "Please select some publication(s) with a PDF and run the script again." with title "No publications selected." buttons {"OK"} default button "OK" with icon 1
        else
            set allPubsWithPDF to {}
            repeat with aPub in selectedPubs
                set pdfFile to primary file item of aPub
                if pdfFile is not missing value then
                    copy aPub to end of allPubsWithPDF
                    set pubTitle to title of aPub
                    if appendDOIToTitle then
                        set pubDOI to doi of aPub
                        if pubDOI is not "" and pubDOI is not missing value then
                            set pubTitle to pubTitle & " " & pubDOI
                        end if
                    end if
                    -- multiple authors separated by semicolon can be parsed by Papers on import 
                    set pubAuthors to PapersLib's regexReplace(author names of aPub, ", and ", ", ")
                    set pubAuthors to PapersLib's regexReplace(pubAuthors, ",", ";")
                    set pubSource to bundle info of aPub
                    set pubKeywords to name of every keyword item of aPub
                    set pdfPath to full path of pdfFile
                    my setPDFDocumentAttributes(pdfPath, pubTitle, pubAuthors, pubSource, pubKeywords, missing value)
                end if
            end repeat
            if allPubsWithPDF is {} then
                display dialog "Couldn't set any PDF document attributes since the selection didn't contain any PDFs." with title "No publications with PDF selected." buttons {"OK"} default button "OK" with icon 1
            else
                display dialog "Modified PDF document attributes of " & (count of allPubsWithPDF) & " publication(s)." with title "Script Done." buttons {"OK"} default button "OK" with icon 1
            end if
        end if
    end tell
    
    on setPDFDocumentAttributes(pdfPOSIXPath, theTitle, theAuthor, theSubject, theKeywords, theCreator)
        if POSIX file pdfPOSIXPath exists then
            if theTitle is not "" and theTitle is not missing value then
                PapersLib's setTitleDocumentAttribute:theTitle forPDFAt:pdfPOSIXPath
            end if
            if theAuthor is not "" and theAuthor is not missing value then
                PapersLib's setAuthorDocumentAttribute:theAuthor forPDFAt:pdfPOSIXPath
            end if
            if theSubject is not "" and theSubject is not missing value then
                PapersLib's setSubjectDocumentAttribute:theSubject forPDFAt:pdfPOSIXPath
            end if
            if theKeywords is not {} and theKeywords is not missing value then
                PapersLib's setKeywordsDocumentAttribute:theKeywords forPDFAt:pdfPOSIXPath
            end if
            if theCreator is not "" and theCreator is not missing value then
                PapersLib's setCreatorDocumentAttribute:theCreator forPDFAt:pdfPOSIXPath
            end if
        end if
    end setPDFDocumentAttributes
    
  21. 81 Posted by Stephan.Zellerh... on 13 Aug, 2014 02:06 PM

    Stephan.Zellerhoff's Avatar

    Hi Matthias!

    Just a short feedback:

    I was able to set the papers link in the spotlight comments in the virtual disk and index these files in devonthink. Afterwards, I used a script provided by devonthink to put the contents of the spotlight comments into the url field. Thereby, I could open the corresponding pdf in papers by clicking on the link even though the virtual disk was not mounted anymore. Unfortunately, this is not working anymore after I upgraded to the current version (3.2.2). Moreover, when I used „reveal in finder“ I am redirected to the real files inside the library - not the virtual disk. This was not the case before the upgrade and before changing the naming pattern in the papers preferences. Any clues how to restore the old behavior?

    Best,

    Stephan

    Am 05.08.2014 um 15:12 schrieb matthias <[email blocked]<mailto:[email blocked]>>:

  22. 82 Posted by matthias on 13 Aug, 2014 02:24 PM

    matthias's Avatar

    Hi Stephan,

    I was able to set the papers link in the spotlight comments in the virtual disk.

    I'm curious about how you did it. I mean, does the spotlight comment stick (even after the virtual disk is unmounted and then re-mounted). Also, does the original PDF file in the Papers library package receive the same Spotlight comment?

    Thereby, I could open the corresponding pdf in papers by clicking on the link even though the virtual disk was not mounted anymore. Unfortunately, this is not working anymore after I upgraded to the current version (3.2.2).

    What happens exactly when you click the Papers link? And do you happen to have multiple versions of Papers installed. This would probably confuse the system which app version should be launched (and the wrong one might get launched).

    Moreover, when I used „reveal in finder“ I am redirected to the real files inside the library - not the virtual disk. This was not the case before the upgrade and before changing the naming pattern in the papers preferences.

    Hmm, are you sure about that one? I think that the "Reveal File in Finder" menu command did always reveal the original (and not the virtual) file.

    Matthias

  23. 83 Posted by rafal.kocierz on 13 Aug, 2014 03:18 PM

    rafal.kocierz's Avatar

    Hello Mathias
    Thanks for your work, you are incredible :)
    However, something goes wrong :( When I run the script I get the error "can not change the file to reference type"

    :

  24. 84 Posted by matthias on 13 Aug, 2014 03:24 PM

    matthias's Avatar

    Hi Rafal,

    you're welcome!

    When I run the script I get the error "can not change the file to reference type"

    Thanks also for the screenshot. It appears that the path to the PDF has colons as folder separators (an "HFS" path) while it should have slashes instead (a "POSIX" aka UNIX-style path). I have no idea how that would happen. Which operation system version are you using?

    And what do you get if you run this in ScriptEditor.app:

    set v to AppleScript's version
    

    thanks, Matthias

  25. 85 Posted by rafal.kocierz on 13 Aug, 2014 03:29 PM

    rafal.kocierz's Avatar

    I’m using OS X 10.9.4 and AppleScript version 2.3.2
    mayby:
    http://macscripter.net/viewtopic.php?id=16020
    http://snipplr.com/view/2752/unixhfs-path-conversion/

    Wiadomość napisana przez matthias <[email blocked]> w dniu 13 sie 2014, o godz. 17:25:

  26. 86 Posted by rafal.kocierz on 13 Aug, 2014 03:36 PM

    rafal.kocierz's Avatar

    Please, look at the screenshot (at results)

    Wiadomość napisana przez matthias <[email blocked]> w dniu 13 sie 2014, o godz. 17:25:

  27. 87 Posted by matthias on 13 Aug, 2014 03:41 PM

    matthias's Avatar

    Hi Rafal,

    for testing purposes, please find and remove this line

    if POSIX file pdfPOSIXPath exists then
    

    and please also remove the last end if line.

    Does that make for any difference?

    Thanks,
    Matthias

  28. 88 Posted by rafal.kocierz on 13 Aug, 2014 03:45 PM

    rafal.kocierz's Avatar

    Hi Matthias
    I only remove „POSIX file” from this line, and script is working properly :) thanks a lot :) you are best :)
    Again, thanks for your work,
    Rafal

    Wiadomość napisana przez matthias <[email blocked]> w dniu 13 sie 2014, o godz. 17:42:

  29. 89 Posted by matthias on 13 Aug, 2014 03:52 PM

    matthias's Avatar

    Hi Rafal,

    I only remove „POSIX file” from this line, and script is working properly

    Hmm, ok. I'm glad that you've got it working! But I fear that test then doesn't test for the existence of the file anymore. If this works any better, then please use this instead:

    set thePOSIXFile to POSIX file pdfPOSIXPath
    if thePOSIXFile exists then
    

    If not, then keep the script as you have it now.

    Best regards, Matthias

  30. 90 Posted by rafal.kocierz on 13 Aug, 2014 03:56 PM

    rafal.kocierz's Avatar

    Thanks for all your work

    Wiadomość napisana przez matthias <[email blocked]> w dniu 13 sie 2014, o godz. 17:52:

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