Ability to Use AppleEvents to Retrive Temporary Citiation Key

Users asking other users for AppleScripts that work with Bookends.
Post Reply
dave83
Posts: 38
Joined: Fri Oct 02, 2015 8:55 am

Ability to Use AppleEvents to Retrive Temporary Citiation Key

Post by dave83 »

Jon,

A user on the Literature & Latte forum pointed out an issue with my Bookends to OPML AppleScript dealing with the temporary citation key I create -- its the default {author, date, #id} format. This user changes the temporary citation format within the Bookends preferences and I don't see how to extract this user's defined temporary citation format without using a keyboard command. The keyboard command caused some unintended consequences while in Scrivener. If a user has Scrivener defined as the default word processor in Bookends, is in Scrivener and executes the script, then the temporary citations of all selected references are pasted into their document. Nothing that foresight and user procedures can't fix, but I am looking for a more robust/elegant solution.

Additionally, RFLD event to retrieve "thedate" returns the user's values; regardless of format. For example, dates can be separated by any character (/,-,{space}, etc) or not separated (20170801). This presents a challenge in extracting just the year. Therefore, I was previously just using the keyboard command to return back what you use.

Any ideas or suggestions are greatly appreciated.

Thanks.
Cheers,
Dave
Jon
Site Admin
Posts: 10048
Joined: Tue Jul 13, 2004 6:27 pm
Location: Bethesda, MD
Contact:

Re: Ability to Use AppleEvents to Retrive Temporary Citiation Key

Post by Jon »

I'm not seeing why it matters. There are three options to create the temporary citation. They all work, it's a matter of personal preference:

Author, Date, Unique ID
By Content (Bookends creates a mixture of fields that unambiguously identifies a reference)
By Format (whatever the user designs)

If they don't like Author, Date, Unique ID (which is generally preferred) they can do a Proofreading scan at any time to convert them to the preference they have chosen.

Is this for creating the temp citation of Author, Date, Unique ID also? If so, the contents of the date field are what you want, not the year. When Bookends scans it matches the contents of the temp citation with the reference's contents. An exception so this rule if that if you specify the Unique ID the rest of the citation is simple for the user's benefit -- it's ignored since the Unique ID contains all the information Bookends needs to make an unambiguous match.

Jon
Sonny Software

P.S. I see the post on the Scrivener forum. nontroppo is incorrect about it being useless for him -- as I said above, any of the 3 options to create a temporary citation work, regardless of what the user has set in Preferences.
dave83
Posts: 38
Joined: Fri Oct 02, 2015 8:55 am

Re: Ability to Use AppleEvents to Retrive Temporary Citiation Key

Post by dave83 »

Jon,

Again, thanks for the quick reply. I'll convey this information concerning the use of temporary citation and ability to do Proofreading scans back to nontroppo over on the Scrivener post.

As part of the OPML notecards I create, I add the temporary citation on each note. This allows me to work off my iPad in Scrivener and insert the citation keys by copying them from the notecard into the text.

As for the date field, yes I am creating a temporary citation using the Author, Date, Unique ID format. I eliminated the CMD-Y keyboard command from the script and now just use the AppleEvents to extract the "author", "thedate", and "unique-id". I then output the temporary citation in the default format: {author, date, #Unique ID}. So, if I understand the last statement, since I have the Unique ID in the temporary citation, Bookends will properly find the correct reference regardless of the other contents -- correct?

FYI - Below are outputs from a test of I conducted to try to get just the year. Note that the temporary citation generated from the CMD-Y had just the year; although the Date field contained "2 August 2017". This was why I was looking to get just the year.

CMD-Y Output —

{Glogowski et al., 2017, #18324}

——————————————————————
RIS Format — (if used AppleEvent GUID)

TY - JOUR
AU - Glogowski, David
AU - Glogowski, Jeanne
AU - Glogowski, Megan
T1 - Test Title
KW - testing, cybersecurity, research
PY - 2 August 2017
JA - Journal of Testing
SP - 250

——————————————————————
“thedate” from RFLD —
2 August 2017


Again, thanks.
Cheers,
Dave
Jon
Site Admin
Posts: 10048
Joined: Tue Jul 13, 2004 6:27 pm
Location: Bethesda, MD
Contact:

Re: Ability to Use AppleEvents to Retrive Temporary Citiation Key

Post by Jon »

Yes, the Unique ID overrides anything else in the temp citation.

If you want the year, look for a 4 digit number that begins with a 1 or a 2. That will work in the vast majority of real-world examples you encounter. If there is none (e.g. the data was entered as 01/05/17) then just output the whole thing (of course you could handle this case, too, but it's probably not worth it).

Jon
Sonny Software
iandol
Posts: 465
Joined: Fri Jan 25, 2008 2:31 pm

Re: Ability to Use AppleEvents to Retrive Temporary Citiation Key

Post by iandol »

Hi, actually I am the user over on the Scrivener forum. I use an automated Pandoc workflow[1] with Scrivener so my temporary citations are of the form [@user1]. User1 is set as the BibTeX key. I tried running the OPML export script and it failed to give any authors or dates:

Code: Select all

<outline text="No Author(s), Undated (ID:83964)"  _note="blah blah"></outline>
...then checked the code quickly to see it was expecting the default temp citation. Yes I could reset my preferences and BibTeX setting each time before running the script... I only had a brief chance to look at your code so I may well have got the intent of using the temporary citation wrong, but I didn't understand why you couldn't use the uniqueID to retrieve the formatted citation directly — why do you have to use system events and the temporary citation?

My big worry was the system events ⌘Y mechanism to get the temporary citation copied to clipboard — this deleted a large chunk of text in my Scrivener on first run, as I have Bookends linked to Scrivener. So a user must turn off Bookends linking first or deliberately ensure no document text is selected before running the script.

I'll be happy to have a better look at the code this weekend and see if I can use «event ToySGUID» to yield the same result that you have. I hope that it is possible to make this more robust across different Bookends configurations as this will be genuinely useful to many academic Scrivener users!

A big thanks again for doing the work to get this set up!!!

----
[1] pandoc-citeproc uses CSL files to generate the final bibliography into multiple formats without needing to do any manual scan.
dave83
Posts: 38
Joined: Fri Oct 02, 2015 8:55 am

Re: Ability to Use AppleEvents to Retrive Temporary Citiation Key

Post by dave83 »

iandol,

I just posted a revised script which removed the CMD-Y. On both forums -- literally just minutes ago. As you stated the keyboard command and the unintended consequence of replacing text.

As for the temporary citation format, without doing this keyboard command, I can not extract the user's defined temporary citation format. Therefore, I I use the default temporary citation format as its the most common. The rationale for including the temporary citation is this allows me to work off my iPad in Scrivener and insert the citation keys by copying them from the notecard into the text. As for the your use of another temporary citation format, as you can see from this thread, the format of the temporary citation does not matter to Bookends as long as it can resolve it a specific reference in Bookends. Since I provide the Bookends Unique ID, the rest is merely for our readability. Additionally, as Jon noted, you can always do a Proofreading Scan (see Bookends User Guide v12.7, pg 225-226) to convert the temporary citation to your preferred temporary citation prior to doing a full Scan.
Cheers,
Dave
iandol
Posts: 465
Joined: Fri Jan 25, 2008 2:31 pm

Re: Ability to Use AppleEvents to Retrive Temporary Citiation Key

Post by iandol »

Dave, actually I think it is fine to use the default temporary citation format as part of the output OPML — I thought your original code was parsing the cite_key_components (original line ~154) taken from the clipboard temporary citations to first author/year, and this was broken when I tried to use your script. But now see that your new version uses «event ToySRFLD» for authors etc. and doesn't need the temporary citation so that is great.

Anyway, I suppose it would be nice to be able to have a new «applescript event» to handle temporary citations directly, but as you've demonstrated, it is not necessary for your new script and you can DIY the temp citation from the other events: "set cite_key to ref_author & ", " & ref_date & ", #" & ref_nbr"
Post Reply