Import from Clipboard

Users asking other users for AppleScripts that work with Bookends.
Post Reply
Dellu
Posts: 187
Joined: Sun Mar 27, 2016 5:30 am

Import from Clipboard

Post by Dellu »

Can you guys help me with applescript to import references from clipboard using Bibtex format?

Assume I have a number of references in the clipboard; they are in bibtex format. I want to hit a keyboard shortcut and simply insert them into my library (or the hit list), without going through the long process of menu navigation.

It seems easy to script. But, I have little experience with Apple-script. I would highly appreciate if any of you guys with some applescript experience can help me.

iandol
Posts: 403
Joined: Fri Jan 25, 2008 2:31 pm

Re: Import from Clipboard

Post by iandol »

As far as I can see from the Applescript dictionary, Bookends doesn't offer a method to import from the clipboard via applescript (maybe I'm wrong or there is a trick). One solution is to use UI scripting: this triggers keystrokes etc. but is a bit kludgey and prone to occasional failure. This simple script should activate bookends, then press the key to call up the import dialog, then press enter. It assumes the settings in that dialog are already set up.

Code: Select all

#!/usr/bin/osascript	
tell application "Bookends"
	activate
	delay 0.1
end tell

tell application "System Events"
	keystroke "i" using {command down, shift down}
	delay 0.9
	keystroke return
end tell
BUT, what if the settings are not correct in the dialog? Then complexity escalates:

https://dougscripts.com/itunes/2021/04/ ... scripting/
https://pfiddlesoft.com/uibrowser/

You should be able to simulate clicking the settings, but you'll need to test how it works...
Last edited by iandol on Fri Oct 15, 2021 5:11 am, edited 1 time in total.

Dellu
Posts: 187
Joined: Sun Mar 27, 2016 5:30 am

Re: Import from Clipboard

Post by Dellu »

Dear @iandol,
Thank you so much. This is very useful. I will check the settings before I import.

Thank you!

iandol
Posts: 403
Joined: Fri Jan 25, 2008 2:31 pm

Re: Import from Clipboard

Post by iandol »

Here is a version which selects the options in the dialog:

Code: Select all

tell application "Bookends"
	activate
	delay 0.1
end tell

tell application "System Events"
	tell application process "Bookends"
		click menu item "From File or Clipboard…" of menu 1 of menu item "Import References" of menu 1 of menu bar item "File" of menu bar 1
		delay 0.1
		tell pop up button 1 of window "Import References"
			click
			delay 0.2
			click menu item "BibTeX.fltr" of menu 1
		end tell
		delay 0.1
		set theCheckbox to checkbox "Import to Hits List" of window "Import References"
		if value of theCheckbox is 0 then click theCheckbox
		click radio button "clipboard" of window "Import References"
		delay 0.1
		click button "OK" of window "Import References"
	end tell
end tell

Dellu
Posts: 187
Joined: Sun Mar 27, 2016 5:30 am

Re: Import from Clipboard

Post by Dellu »

This is exactly what I have been looking for.
This is really great: fully automated.

Thank you so much

Post Reply