Jump to content

Search Bibdesk library


Recommended Posts

  • 2 weeks later...
  • 3 months later...

Sebastian, thank you for  a great workflow.

 

I have one feature suggestion - obviously, since I am unable to estimate how difficult this would be to implement, this is a mere suggestion. It would be great if one could set a default BibDesk template and then have one additional modifier which - provided the bib fiel containing the publication is open - copies the selected publication formatted according to the preset template to the clipboard. In essence, it would implement Bibdesk's "Copy using template" with a preset template.

 

I am suggesting this because I often write short texts outside of LaTeX where I still cite publications I keep in Bibdesk.

 

For what it's worth, I know it is possible to access the Bibdesk templates in AppleScript (which seems to break rich text) like this:

 

tell application "BibDesk"

 

set theTemplate to "OxfordLegal"

 

set theDocument to document 1

set thePublications to the selection of document 1

 

tell theDocument to set the clipboard to (templated text using theTemplate for thePublications)

 

end tell

Link to comment

Sebastian, thank you for  a great workflow.

 

I have one feature suggestion - obviously, since I am unable to estimate how difficult this would be to implement, this is a mere suggestion. It would be great if one could set a default BibDesk template and then have one additional modifier which - provided the bib fiel containing the publication is open - copies the selected publication formatted according to the preset template to the clipboard. In essence, it would implement Bibdesk's "Copy using template" with a preset template.

Great idea. I have set up a beta version. I hope that I have introduced no new bugs:

 

https://bitbucket.org/schoeps/alfred/downloads/BibDesk_Search_beta.alfredworkflow

 

If you press [CTRL]+[Enter] Alfred copies the publication string to the clipboard. I use the Bibdesk template "abbrvTemplate" for now but this can be changed easily. Please give feedback.

Edited by Sebastian
Link to comment

Sebastian,

 

thanks. It works great so far.

 

As expected, the copying does not preserve the formatting, but that is a limitation of AppleScript itself and doesn't bother me as I use character style templates in my documents anyways.

 

I have made one minor modification. I added 

tell application "System Events"
set activeApp to name of first application process whose frontmost is true
set process_bid to get the bundle identifier of process activeApp
set activeApp to file of (application processes where bundle identifier is process_bid)
set activeApp to activeApp as string
end tell

at the very beginning and changed the end of the script to

tell application activeApp to activate

return theResult

As you can see, I also changed the name of the result from result to theResult - for some reason, it wouldnt't work otherwise with my changes. The idea behind these changes was to re-activate the formerly frontmost app after the clipboard was set. The activeApp part is somewhat complex to account for users who have different apps with the same name (I do because of Parallels).

 

Cheers,

 

Jan Jakob

Edited by jay-squared
Link to comment

As expected, the copying does not preserve the formatting, but that is a limitation of AppleScript itself and doesn't bother me as I use character style templates in my documents anyways.

 

I have made one minor modification. I added  ... As you can see, I also changed the name of the result from result to theResult - for some reason, it wouldnt't work otherwise with my changes. The idea behind these changes was to re-activate the formerly frontmost app after the clipboard was set. The activeApp part is somewhat complex to account for users who have different apps with the same name (I do because of Parallels).

 

I have played around with 

templated rich text

in the applescript to preserve formatting but this seems not to work.

 

However, I added your changes to "Beta 2": BibDesk_Search_beta2.alfredworkflow. Thanks!

I will use this version a few more days and then update the main download link.

Edited by Sebastian
Link to comment
  • 1 month later...
  • 4 weeks later...

Sorry, I am new to Alfred. I don't get how the modifier keys work. What I am looking for is to get be able to copy just the citetation key of the associated reference and paste it to my document. 

I am able to search the references. I am getting results. But, I don't understand how can I copy just the citation key. Can sb explain please?

Link to comment

I am getting a result like /Users/~/Library/Caches/Metadata/edu.ucsd.cs.mmccrack.bibdesk/Yimam2006.bdskcache when I try to copy

 

 

There is a readme for each workflow, you can access it by double-clicking on the workflow icon within Alfred's preferences.

Your question is hopefully answered there:

 

BibDesk Search (Version 2.1)

 

This workflow allows to search your Bibdesk library. It relies on Spotlight and Bibdesk, i.e., it finds only entries that are cached in the directory "~/Library/Caches/Metadata/edu.ucsd.cs.mmccrack.bibdesk/"

 

You can use the following actions:

- [return] to open in Bibdesk

- [cmd]+[return] to copy the citekey to clipboard 

- [shift]+[return] to open an attached pdf in your favorite viewer

- [alt]+[return] to copy a citation string ("abbrvTemplate")

 

The artwork is property of BibDesk.app (http://bibdesk.sourceforge.net) which is published under the BSD License.

 

Link to comment

The readme doesn't actually match the commands in the workflow.  The actual commands are, if I read correctly:

 

- [return] to open in Bibdesk

- [ctrl]+[return] to copy the citation to the clipboard

- [alt]+[return] to open an attached pdf in your favorite viewer

- [shift]+[return] to copy a citation string ("abbrvTemplate")

- [command]+[return] to reveal linked file in Finder

 

But at this point, besides return, only alt-return and shift-return work - these both rely on bash scripts.  The other two rely on Applescripts which don't work on my machine.

Link to comment

I am loving this workflow with the exception of problems running some of the sub-commands (like @dfay).

 

^↩ says it will copy a citation to clipboard, but returns the following Applescript error in the Alfred debugger:

 

    NSAppleScriptErrorAppName = BibDesk;
    NSAppleScriptErrorBriefMessage = "An error of type 6 has occurred.";
    NSAppleScriptErrorMessage = "BibDesk got an error: An error of type 6 has occurred.";
    NSAppleScriptErrorNumber = 6;
    NSAppleScriptErrorRange = "NSRange: {802, 47}";

 

⌘↩ is supposed to reveal the PDF in Finder, but instead spits out this Applescript error:

 

 

    NSAppleScriptErrorAppName = Finder;

    NSAppleScriptErrorBriefMessage = "Handler can\U2019t handle objects of this class.";
    NSAppleScriptErrorMessage = "Finder got an error: Handler can\U2019t handle objects of this class.";
    NSAppleScriptErrorNumber = "-10010";
    NSAppleScriptErrorRange = "NSRange: {165, 14}";

 

All other commands work as expected.

 

Any ideas?

Link to comment

As you may have guessed, the scripts are working fine on my computer. Thus we have to debug it together... I have uploaded a debug build here: BibDesk_Search_debug.alfredworkflow

It should show dialogs with the path to the entry selected in Alfred. 

 

Let's have a look at the more difficult case, i.e., what happens if you press ^↩. For this we analyze the Applescript.
Can you copy the following into the Applescript editor and adapt q to contain the path to your bdskfile? What happens if you run it? 

set q to "/Users/????/Library/Caches/Metadata/edu.ucsd.cs.mmccrack.bibdesk/????.bdskcache"

--remember active app
tell application "System Events"
set activeApp to name of first application process whose frontmost is true
set process_bid to get the bundle identifier of process activeApp
set activeApp to file of (application processes where bundle identifier is process_bid)
set activeApp to activeApp as string
end tell

-- check whether BibDesk is ready
tell application "BibDesk"
activate
if (count of documents) = 0 then
beep
display dialog "Please open your BibDesk database" buttons {"OK"} default button 1
return
end if
end tell

tell document 1 of application "BibDesk"
set bibkey to do shell script "mdls -name net_sourceforge_bibdesk_citekey '" & q & "'| cut -d'\"' -f 2"
set thePub to get publications whose cite key is bibkey
set theResult to (templated text using "abbrvTemplate" for thePub)
end tell

tell application activeApp to activate
return theResult
Edited by Sebastian
Link to comment

The path isn't the issue.  The error message in the copy to clipboard script is because there's a hard-coded template name "abbrvTemplate" which isn't one of the BibDesk defaults.  

set theResult to (templated text using "abbrvTemplate" for thePub)

When I change that to a text template (Jim Harrison's "plainTemplateNonNumbered" that comes with CiteInPages) that I have installed on my machine it works.

 

Not sure what's up with the reveal in Finder script.

Edited by dfay
Link to comment

The path isn't the issue.  The error message in the copy to clipboard script is because there's a hard-coded template name "abbrvTemplate" which isn't one of the BibDesk defaults.  

Thanks! I have created a new beta version (BibDesk_Search_beta.alfredworkflow) that now includes its own Bibdesk template. Can you please try it? 

 

I have also corrected the readme:

You can use the following actions:
- [return] to open in Bibdesk
- [cmd]+[return] to reveal attached pdf in finder
- [alt]+[return] to open attached pdf in your favorite viewer
- [shift]+[return] to copy the citekey to clipboard 
- [ctrl]+[return] to copy a citation string
Link to comment

Hmm...I installed this and now Alfred displays the message

 

Incompatible Workflow

This workflow was created with a newer version of Alfred

Please upgrade Alfred to the latest version (or pre-release) to use this workflow

 

I am running Alfred 2.2 b243 which is the newest....I can't find a link to download a newer Alfred beta.

 

The old version seems to be active, though, or the new one has issues - return, shift and alt options work; cmd and ctrl don't.

Link to comment

If you select "Automatically check for pre-releases" in the Alfred Update pane, you will be able to update to version 2.3 (264), which is the most up-to-date-version. Tho, it is, as the selection would suggest, a pre-release beta.

Link to comment

Hmm...I installed this and now Alfred displays the message

 

Incompatible Workflow

This workflow was created with a newer version of Alfred

Please upgrade Alfred to the latest version (or pre-release) to use this workflow

 

I am running Alfred 2.2 b243 which is the newest....I can't find a link to download a newer Alfred beta.

 

The old version seems to be active, though, or the new one has issues - return, shift and alt options work; cmd and ctrl don't.

 

Can you try the workflow with the latest pre-release alfred? Thanks!

Link to comment

Thanks - I have the latest pre-release.

 

Here's what I see

 

- [return] to open in Bibdesk

 

works fine, but the debugger displays a message:

 

[ERROR: alfred.workflow.input.scriptfilter] Code 1: Exited with error code but no message

 

 

- [cmd]+[return] to reveal attached pdf in finder

 

doesn't work, debugger says

 

[ERROR: alfred.workflow.action.applescript] {

    NSAppleScriptErrorAppName = Finder;

    NSAppleScriptErrorBriefMessage = "Handler can\U2019t handle objects of this class.";

    NSAppleScriptErrorMessage = "Finder got an error: Handler can\U2019t handle objects of this class.";

    NSAppleScriptErrorNumber = "-10010";

    NSAppleScriptErrorRange = "NSRange: {230, 14}";

}

 

 

- [alt]+[return] to open attached pdf in your favorite viewer

 

works fine, but the debugger displays a message:

 

[ERROR: alfred.workflow.input.scriptfilter] Code 1: Exited with error code but no message

 

 

- [shift]+[return] to copy the citekey to clipboard 

 

works fine, but the debugger displays a message:

 

[ERROR: alfred.workflow.input.scriptfilter] Code 1: Exited with error code but no message

 

 

- [ctrl]+[return] to copy a citation string

 

works fine, but the debugger displays a message:

 

[ERROR: alfred.workflow.input.scriptfilter] Code 1: Exited with error code but no message

 

 

 

In fact, on trying this a few times, the Code 1 error message is coming before I hit any of the modifier keys.  Which would make sense since it refers to the script filer.

Edited by dfay
Link to comment

Also....if I uncomment the display dialog on line 5, cmd+return displays the correct file but the spaces are escaped with %20.

 

in Applescript Editor, this works:

 

set f to "Dragonfly:Users:somebody:Documents:unruh 2014 evidencing the resti.pdf"

tell application "Finder" to reveal f

 

but this
 
set f to "Dragonfly:Users:somebody:Documents:unruh%202014%20evidencing%20the%20resti.pdf"
tell application "Finder" to reveal f
 
gives the same error message.
Link to comment

set f to "Dragonfly:Users:somebody:Documents:unruh%202014%20evidencing%20the%20resti.pdf"

tell application "Finder" to reveal f
 
gives the same error message.

 

That is good news! Now, we know that spaces in file names seem to be the bad guys (I would never have found this issue because I use the bibkeys as filenames). I will have look to it! 

Link to comment
For those interested, I've just posted a new BibDesk workflow that borrows the same design of my Zotero workflow (ZotQuery) but works with BibDesk and .bib files. 

 

While Sebastian's workflow was an initial inspiration, I've gone a few new directions and added many different types of queries. I'd love to get some feedback.

 

The workflow post is here

 

stephen

Edited by smarg19
Link to comment

That is good news! Now, we know that spaces in file names seem to be the bad guys (I would never have found this issue because I use the bibkeys as filenames). I will have look to it! 

 

Problem seems to be solved I had to convert from URL encoding. Now I use PHP for that

set thePOSIXfile to do shell script "php -r \"echo rawurldecode('" & theURL & "');\""

Please test it: BibDesk_Search_beta.alfredworkflow

Edited by Sebastian
Link to comment

I am getting the error intermittently still...some files with spaces work perfectly, others give the "Finder got an error: Handler can\U2019t handle objects of this class." message.  I'm puzzled.  I'll see if I can figure out what is making the difference.

 

Thanks for all your work on this.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...