On Feb 9, 2010, at 10:58, Fischlin Andreas wrote:

> Dear all,
> 
> I frequently reimport records into my bib files and wish to "update" records 
> by replacing existing ones with new versions. All works fine with BD and my 
> set of AppleScripts except that any belonging to static groups gets lost when 
> I delete the old record in favor of the new one. Thus I would like to 
> retrieve the set of static groups the old record belongs to before deleting 
> it and then adding the new record to all those groups.
> 
> It seems I can't do that. Although BD dictionary tells me that group is a 
> property of a publication,

That's "group" as in singular, is the (main) container of the publication, 
which is only relevant for external groups, because normal publications are 
contained in the document (though it could make sense to return the library 
group for normal publications).

> it seems static groups can't be retrieved. Am I right? Therefore the 
> following, albeit compilable, fails at run time:
> 
> tell application "BibDesk"
>       tell first document
>               set thePubs to selection
>               repeat with thePub in thePubs
>                       tell thePub
>                               set pGroups to (get static groups of thePub)
>                               display dialog "publication contained in " & 
> (count of pGroups) & " group(s) " & (name of first item of pGroups)
>                       ...
>                       end tell
>               end repeat
>       end tell
> end tell
> 
> Leaving out the "static" is of course fine but only allows to retrieve an 
> external group. AFAIK this is all consistent with the cryptic dictionary of 
> BD. Retrieving groups from the document is easy but it seems to be very 
> inefficient to use then a loop over all static groups and all their members 
> to find out whether thePub belongs to it or not. The following AppleScript 
> code
> 
> tell application "BibDesk"
>       tell first document
> 
>               set allGroups to (get static groups)
>               set allGroupKeys to {}
>               set allGroupNames to {}
>               repeat with aGroup in allGroups
>                       set theGroupPubs to (get publications of aGroup)
>                       set groupKeys to {}
>                       repeat with gPub in theGroupPubs
>                               copy (get cite key of gPub) to the end of 
> groupKeys
>                       end repeat
>                       copy groupKeys to the end of allGroupKeys
>                       copy (name of aGroup) to the end of allGroupNames
>               end repeat
>               
>               set thePubs to selection
>               repeat with thePub in thePubs
>                       set theCiteKey to (get cite key of thePub)
>                       set i to 0
>                       repeat with aGroupsKeys in allGroupKeys
>                               set i to i + 1
>                               if theCiteKey is in aGroupsKeys then
>                                       display dialog "Publication '" & 
> theCiteKey & "' is in static group '" & (item i of allGroupNames) & "'"
>                               end if
>                       end repeat
>               end repeat
> 
>       end tell
> end tell
> 
> does what I want but is quite slow, I'd say intolerably slow. Leaving out the 
> handling of the names, which is of course not necessary for a final 
> implementation, doesn't make a significant difference in speed. Any advice 
> anyone can offer? More elegant solutions? Calls for improving BD's 
> AppleScript capabilities by supporting the first script? Or have I completely 
> overlooked something?
> 
> Thanks a lot.
> 
> Cheers,
> Andreas

You can use AppleScript's conditional expressions, as in:

static groups whose publications contain thePub

Christiaan

------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
Bibdesk-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-users

Reply via email to