Re: [Bibdesk-users] Script hook to protect Address field

2010-04-02 Thread Peter Cowan
On Fri, Apr 2, 2010 at 2:13 PM, Christiaan Hofman  wrote:
>
> On Apr 2, 2010, at 21:54, Peter Cowan wrote:
>
>> On Fri, Apr 2, 2010 at 9:53 AM, Christiaan Hofman  wrote:
>>>
>>> On Apr 1, 2010, at 23:29, Peter Cowan wrote:
>>>
 On Thu, Apr 1, 2010 at 2:03 PM, Christiaan Hofman  
 wrote:
>
> On Apr 1, 2010, at 22:15, Peter Cowan wrote:
>
>> I'm using biblatex in the TeX preview window.  And, since I often
>> import directly from ISI using the Web of Science Search function, I
>> get regular errors related to commas in the address or institution
>> field.  Perhaps there is a solution through biblatex to this problem,
>> but I'm fine with either protecting or deleting the
>> Address/Institution field on import.
>>
>> Script hooks seem like the perfect solution to this problem, but I am
>> not an applescript users.  I've tried to cobble something together
>> based on the available example and got the following which doesn't
>> appear to work, on import (from Web of Science) nothing happens no
>> errors no braces.  Any nudges in the right direction are appreciated.
>>
>> I apologize if this has been discussed on the list before, my searches
>> did not reveal anything aside from confirmation of the biblatex TeX
>> preview issue.
>>
>> Cheers
>>
>> Peter
>>
 [snip old code]
>
> This won't work, because you call the external scripts outside the 
> "perform BibDesk action..." handler. The script hook will only call that 
> handler, so anything outside it (like defining the protectLib and 
> errorLib) will be ignored. Therefore reference to those external scripts 
> will fail. You'll have to move everything to inside the script hook 
> handler.

 Christiaan,

 Thanks for the reply, I've moved the load script calls inside of the
 handler, but alas it still doesn't work.  The current version is
 below.

 I apologize for being such an applescript newb, but is there a
 workflow you follow for developing this applescripts, e.g. debugging
 hints, setting "breakpoints" etc.

 Cheers

 Peter
>>>
>>>
>>> [snip]
>>>
>>> BTW, another possibility is that this actually works, but you expect it to 
>>> do something different from what it actually does. What this most certainly 
>>> does NOT do is to enclose the Address value in braces, and the check you 
>>> added make me think that that's what you (wrongly) expect it to do. So 
>>> perhaps you should also say what you expect it to do, and what you did 
>>> exactly to make it do that, perhaps with explicit samples.
>>
>> Christian and Fischlin,
>>
>> Thanks for your replies.   Indeed I'm trying to wrap the Address Field
>> in curly braces so that biblatex won't puke on those bib items.  I
>> thought that wrapping something in braces was called protecting, but
>> perhaps I am wrong.
>>
>> You are correct the above script most definitely did not do what I was
>> hoping for.
>>
>> An explicit example:
>>
>> I usually use the Web of Science SCI search to import references.  If
>> I search for au=(watson AND crick) the first hit is
>>
>> CRICK, FHC and WATSON, JD. 1956. STRUCTURE OF SMALL VIRUSES. Nature.
>> 177(4506):473-475.
>>
>> However, this citation causes an error using my tex preview template
>> (below, require biblatex).  The relevant part of the log is:
>>
>> Too many commas in name 1 of "PORTERS SOUTH, 4 CRINAN ST, LONDON N1
>> 9XW, ENGLAND" for entry cite-key
>>
>> If I change the address field to
>>
>> {PORTERS SOUTH, 4 CRINAN ST, LONDON N1 9XW, ENGLAND}
>>
>> it is compiled and previewed correctly.
>>
>
> That sounds like a totally different problem. The warning says it's 
> interpreting this as a name. So either you've put the address in an author 
> field or something, or biblatex has a problem. It should never interpret an 
> address as a name IMHO.

This is from a direct import using the "Import" button while searching
WOS from bibdesk.  I agree it seems like a biblatex problem to me, but
I've not found mention of it on the biblatex list, I may send a bug
report that way.

This is the how the above example is imported by BibDesk:

@article{CRICK.F:1956,
Address = {PORTERS SOUTH, 4 CRINAN ST, LONDON N1 9XW, ENGLAND},
Author = {CRICK, FHC and WATSON, JD},
Date-Added = {2010-04-02 15:28:17 -0700},
Date-Modified = {2010-04-02 15:28:17 -0700},
Isi = {A1956ZQ08700022},
Isi-Recid = {3737785},
Isi-Ref-Recids = {1399833 25231 154301 694402 25230 239834 3611023
3395518 3500753 3437398 176937 3474554 175967 2741553 137080 43856
3395520 3397795 3437394 3742607 103203 3611269 2741574 3395809 3397793
261765 3649114 665053 3742608 2741559 3742609 482156},
Journal = {Nature},
Number = {4506},
Pages = {473-475},
Publisher = {MACMILLAN MAGAZINES LTD},
Times-Cited = {327},
Title = {STRUCTURE OF 

Re: [Bibdesk-users] Script hook to protect Address field

2010-04-02 Thread Christiaan Hofman

On Apr 2, 2010, at 21:54, Peter Cowan wrote:

> On Fri, Apr 2, 2010 at 9:53 AM, Christiaan Hofman  wrote:
>> 
>> On Apr 1, 2010, at 23:29, Peter Cowan wrote:
>> 
>>> On Thu, Apr 1, 2010 at 2:03 PM, Christiaan Hofman  
>>> wrote:
 
 On Apr 1, 2010, at 22:15, Peter Cowan wrote:
 
> I'm using biblatex in the TeX preview window.  And, since I often
> import directly from ISI using the Web of Science Search function, I
> get regular errors related to commas in the address or institution
> field.  Perhaps there is a solution through biblatex to this problem,
> but I'm fine with either protecting or deleting the
> Address/Institution field on import.
> 
> Script hooks seem like the perfect solution to this problem, but I am
> not an applescript users.  I've tried to cobble something together
> based on the available example and got the following which doesn't
> appear to work, on import (from Web of Science) nothing happens no
> errors no braces.  Any nudges in the right direction are appreciated.
> 
> I apologize if this has been discussed on the list before, my searches
> did not reveal anything aside from confirmation of the biblatex TeX
> preview issue.
> 
> Cheers
> 
> Peter
> 
>>> [snip old code]
 
 This won't work, because you call the external scripts outside the 
 "perform BibDesk action..." handler. The script hook will only call that 
 handler, so anything outside it (like defining the protectLib and 
 errorLib) will be ignored. Therefore reference to those external scripts 
 will fail. You'll have to move everything to inside the script hook 
 handler.
>>> 
>>> Christiaan,
>>> 
>>> Thanks for the reply, I've moved the load script calls inside of the
>>> handler, but alas it still doesn't work.  The current version is
>>> below.
>>> 
>>> I apologize for being such an applescript newb, but is there a
>>> workflow you follow for developing this applescripts, e.g. debugging
>>> hints, setting "breakpoints" etc.
>>> 
>>> Cheers
>>> 
>>> Peter
>> 
>> 
>> [snip]
>> 
>> BTW, another possibility is that this actually works, but you expect it to 
>> do something different from what it actually does. What this most certainly 
>> does NOT do is to enclose the Address value in braces, and the check you 
>> added make me think that that's what you (wrongly) expect it to do. So 
>> perhaps you should also say what you expect it to do, and what you did 
>> exactly to make it do that, perhaps with explicit samples.
> 
> Christian and Fischlin,
> 
> Thanks for your replies.   Indeed I'm trying to wrap the Address Field
> in curly braces so that biblatex won't puke on those bib items.  I
> thought that wrapping something in braces was called protecting, but
> perhaps I am wrong.
> 
> You are correct the above script most definitely did not do what I was
> hoping for.
> 
> An explicit example:
> 
> I usually use the Web of Science SCI search to import references.  If
> I search for au=(watson AND crick) the first hit is
> 
> CRICK, FHC and WATSON, JD. 1956. STRUCTURE OF SMALL VIRUSES. Nature.
> 177(4506):473-475.
> 
> However, this citation causes an error using my tex preview template
> (below, require biblatex).  The relevant part of the log is:
> 
> Too many commas in name 1 of "PORTERS SOUTH, 4 CRINAN ST, LONDON N1
> 9XW, ENGLAND" for entry cite-key
> 
> If I change the address field to
> 
> {PORTERS SOUTH, 4 CRINAN ST, LONDON N1 9XW, ENGLAND}
> 
> it is compiled and previewed correctly.
> 

That sounds like a totally different problem. The warning says it's 
interpreting this as a name. So either you've put the address in an author 
field or something, or biblatex has a problem. It should never interpret an 
address as a name IMHO. 

> The applescript I sent before was an effort to do that wrapping on
> import.  I however was unable to get the protectLib to work at all

That's probably because you haven't really used it. This protects individual 
words or phrases (which is really the correct thing to do in bibtex), and you 
have to tell it which words and phrases to protect. Just enclosing a value in 
braces is crude and generally the wrong thing to do, because the capitalization 
is supposed to be determined by the style and not by the data, except for 
certain special words (like acronyms.)

> so
> I ended up with this *working* script hook.  A couple of caveats, the
> errorLib has never produced anything to me, it seem unlikely given my
> applescript skills, that I produced no errors.  

Errors really mean errors, in that they would normally fail the script if you 
don't escape them. 

> And, secondly this
> method won't, of course, catch cases where the field is already in
> braces, so some Address fields could end up double wrapped.
> Suggestions for improvements are welcome.

Define the following in your applescript and use it instead of protectString():

on encloseInBraces(theString)
  

Re: [Bibdesk-users] Script hook to protect Address field

2010-04-02 Thread Peter Cowan
On Fri, Apr 2, 2010 at 9:53 AM, Christiaan Hofman  wrote:
>
> On Apr 1, 2010, at 23:29, Peter Cowan wrote:
>
>> On Thu, Apr 1, 2010 at 2:03 PM, Christiaan Hofman  wrote:
>>>
>>> On Apr 1, 2010, at 22:15, Peter Cowan wrote:
>>>
 I'm using biblatex in the TeX preview window.  And, since I often
 import directly from ISI using the Web of Science Search function, I
 get regular errors related to commas in the address or institution
 field.  Perhaps there is a solution through biblatex to this problem,
 but I'm fine with either protecting or deleting the
 Address/Institution field on import.

 Script hooks seem like the perfect solution to this problem, but I am
 not an applescript users.  I've tried to cobble something together
 based on the available example and got the following which doesn't
 appear to work, on import (from Web of Science) nothing happens no
 errors no braces.  Any nudges in the right direction are appreciated.

 I apologize if this has been discussed on the list before, my searches
 did not reveal anything aside from confirmation of the biblatex TeX
 preview issue.

 Cheers

 Peter

>> [snip old code]
>>>
>>> This won't work, because you call the external scripts outside the "perform 
>>> BibDesk action..." handler. The script hook will only call that handler, so 
>>> anything outside it (like defining the protectLib and errorLib) will be 
>>> ignored. Therefore reference to those external scripts will fail. You'll 
>>> have to move everything to inside the script hook handler.
>>
>> Christiaan,
>>
>> Thanks for the reply, I've moved the load script calls inside of the
>> handler, but alas it still doesn't work.  The current version is
>> below.
>>
>> I apologize for being such an applescript newb, but is there a
>> workflow you follow for developing this applescripts, e.g. debugging
>> hints, setting "breakpoints" etc.
>>
>> Cheers
>>
>> Peter
>
>
> [snip]
>
> BTW, another possibility is that this actually works, but you expect it to do 
> something different from what it actually does. What this most certainly does 
> NOT do is to enclose the Address value in braces, and the check you added 
> make me think that that's what you (wrongly) expect it to do. So perhaps you 
> should also say what you expect it to do, and what you did exactly to make it 
> do that, perhaps with explicit samples.

Christian and Fischlin,

Thanks for your replies.   Indeed I'm trying to wrap the Address Field
in curly braces so that biblatex won't puke on those bib items.  I
thought that wrapping something in braces was called protecting, but
perhaps I am wrong.

You are correct the above script most definitely did not do what I was
hoping for.

An explicit example:

I usually use the Web of Science SCI search to import references.  If
I search for au=(watson AND crick) the first hit is

CRICK, FHC and WATSON, JD. 1956. STRUCTURE OF SMALL VIRUSES. Nature.
177(4506):473-475.

However, this citation causes an error using my tex preview template
(below, require biblatex).  The relevant part of the log is:

Too many commas in name 1 of "PORTERS SOUTH, 4 CRINAN ST, LONDON N1
9XW, ENGLAND" for entry cite-key

If I change the address field to

{PORTERS SOUTH, 4 CRINAN ST, LONDON N1 9XW, ENGLAND}

it is compiled and previewed correctly.

The applescript I sent before was an effort to do that wrapping on
import.  I however was unable to get the protectLib to work at all so
I ended up with this *working* script hook.  A couple of caveats, the
errorLib has never produced anything to me, it seem unlikely given my
applescript skills, that I produced no errors.  And, secondly this
method won't, of course, catch cases where the field is already in
braces, so some Address fields could end up double wrapped.
Suggestions for improvements are welcome.

property theFieldToSet : "Address"

using terms from application "BibDesk"
  on perform BibDesk action with publications thePubs for script hook
theScriptHook

set errorLib to (load script file ¬
  ((path to home folder as string) &
"Library:ScriptingAdditions:Error Reporting.scpt"))
-- we only report all errors at the end

tell errorLib
  delayReportErrors()
  set its defaultErrorFileName to "BibDeskScriptErrors"
end tell

repeat with thePub in thePubs
  try
tell thePub
  set curValue to value of field theFieldToSet

  set newValue to "{" & curValue & "}"
  if newValue is not "{}" then ¬
set value of field theFieldToSet to newValue
end tell

  on error errorMessage number errorNumber
tell errorLib to reportError(errorMessage, errorNumber)
  end try
end repeat
  end perform BibDesk action with publications
end using terms from

-- see if we had any errors
tell errorLib to checkForErrors()


%% TeX Preview template %
%% Requires biblatex %

Re: [Bibdesk-users] Script hook to protect Address field

2010-04-02 Thread Christiaan Hofman

On Apr 1, 2010, at 23:29, Peter Cowan wrote:

> On Thu, Apr 1, 2010 at 2:03 PM, Christiaan Hofman  wrote:
>> 
>> On Apr 1, 2010, at 22:15, Peter Cowan wrote:
>> 
>>> I'm using biblatex in the TeX preview window.  And, since I often
>>> import directly from ISI using the Web of Science Search function, I
>>> get regular errors related to commas in the address or institution
>>> field.  Perhaps there is a solution through biblatex to this problem,
>>> but I'm fine with either protecting or deleting the
>>> Address/Institution field on import.
>>> 
>>> Script hooks seem like the perfect solution to this problem, but I am
>>> not an applescript users.  I've tried to cobble something together
>>> based on the available example and got the following which doesn't
>>> appear to work, on import (from Web of Science) nothing happens no
>>> errors no braces.  Any nudges in the right direction are appreciated.
>>> 
>>> I apologize if this has been discussed on the list before, my searches
>>> did not reveal anything aside from confirmation of the biblatex TeX
>>> preview issue.
>>> 
>>> Cheers
>>> 
>>> Peter
>>> 
> [snip old code]
>> 
>> This won't work, because you call the external scripts outside the "perform 
>> BibDesk action..." handler. The script hook will only call that handler, so 
>> anything outside it (like defining the protectLib and errorLib) will be 
>> ignored. Therefore reference to those external scripts will fail. You'll 
>> have to move everything to inside the script hook handler.
> 
> Christiaan,
> 
> Thanks for the reply, I've moved the load script calls inside of the
> handler, but alas it still doesn't work.  The current version is
> below.
> 
> I apologize for being such an applescript newb, but is there a
> workflow you follow for developing this applescripts, e.g. debugging
> hints, setting "breakpoints" etc.
> 
> Cheers
> 
> Peter


[snip]

BTW, another possibility is that this actually works, but you expect it to do 
something different from what it actually does. What this most certainly does 
NOT do is to enclose the Address value in braces, and the check you added make 
me think that that's what you (wrongly) expect it to do. So perhaps you should 
also say what you expect it to do, and what you did exactly to make it do that, 
perhaps with explicit samples.

Christiaan


--
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Bibdesk-users mailing list
Bibdesk-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bibdesk-users


Re: [Bibdesk-users] Script hook to protect Address field

2010-04-02 Thread Fischlin Andreas
Dear Peter,

I suggest you use a structure closer to this and avoid crowding everything into 
the "using terms part".

using terms from application "BibDesk"
... 
my Routine1(argument1, argument2)
... 
end using terms from


on Routine1 (argument1, argument2) 
... here you do other stuff possibly calling other routines
end Routine1

on Routine2(argument)
...
end Routine2

etc.


Regards,
Andreas
 

ETH Zurich
Prof. Dr. Andreas Fischlin
Systems Ecology - Institute of Integrative Biology
CHN E 21.1
Universitaetstrasse 16
8092 Zurich
SWITZERLAND

andreas.fisch...@env.ethz.ch
www.sysecol.ethz.ch

+41 44 633-6090 phone
+41 44 633-1136 fax
+41 79 221-4657 mobile

 Make it as simple as possible, but distrust it!




On 01/Apr/2010, at 23:29 , Peter Cowan wrote:

> On Thu, Apr 1, 2010 at 2:03 PM, Christiaan Hofman  wrote:
>> 
>> On Apr 1, 2010, at 22:15, Peter Cowan wrote:
>> 
>>> I'm using biblatex in the TeX preview window.  And, since I often
>>> import directly from ISI using the Web of Science Search function, I
>>> get regular errors related to commas in the address or institution
>>> field.  Perhaps there is a solution through biblatex to this problem,
>>> but I'm fine with either protecting or deleting the
>>> Address/Institution field on import.
>>> 
>>> Script hooks seem like the perfect solution to this problem, but I am
>>> not an applescript users.  I've tried to cobble something together
>>> based on the available example and got the following which doesn't
>>> appear to work, on import (from Web of Science) nothing happens no
>>> errors no braces.  Any nudges in the right direction are appreciated.
>>> 
>>> I apologize if this has been discussed on the list before, my searches
>>> did not reveal anything aside from confirmation of the biblatex TeX
>>> preview issue.
>>> 
>>> Cheers
>>> 
>>> Peter
>>> 
> [snip old code]
>> 
>> This won't work, because you call the external scripts outside the "perform 
>> BibDesk action..." handler. The script hook will only call that handler, so 
>> anything outside it (like defining the protectLib and errorLib) will be 
>> ignored. Therefore reference to those external scripts will fail. You'll 
>> have to move everything to inside the script hook handler.
> 
> Christiaan,
> 
> Thanks for the reply, I've moved the load script calls inside of the
> handler, but alas it still doesn't work.  The current version is
> below.
> 
> I apologize for being such an applescript newb, but is there a
> workflow you follow for developing this applescripts, e.g. debugging
> hints, setting "breakpoints" etc.
> 
> Cheers
> 
> Peter
> 
> 
> property theFieldToSet : "Address"
> 
> using terms from application "BibDesk"
>   on perform BibDesk action with publications thePubs for script hook
> theScriptHook
>   
>   set protectLib to (load script file ¬
>   ((path to home folder as string) & "Library:Application
> Support:BibDesk:Scripts:Add Protect Strings.scpt"))
>   -- load the Error Reporting script library
>   set errorLib to (load script file ¬
>   ((path to home folder as string) &
> "Library:ScriptingAdditions:Error Reporting.scpt"))
>   -- we only report all errors at the end
>   
>   tell errorLib
>   delayReportErrors()
>   set its defaultErrorFileName to "BibDeskScriptErrors"
>   end tell
>   
>   -- here you could return depending on theName or theField
>   tell protectLib
>   -- protect chars between balanced {}
>   set its startProtectChar to "{"
>   set its endProtectChar to "}"
>   
>   repeat with thePub in thePubs
>   
>   try
>   tell thePub
>   set curValue to value of field 
> theFieldToSet
>   -- generate a new value for the 
> field
>   set theField to field 
> theFieldToSet
>   set newValue to 
> protectString(curValue)
>   if newValue is not "{}" then ¬
>   set value of theField 
> to newValue
>   end tell
>   
>   on error errorMessage number errorNumber
>   tell errorLib to 
> reportError(errorMessage, errorNumber)
>   
>   end try
>   
>