Dear Anil,
I am regularly, i.e. daily, syncing my pdf repository between two Macs. I have
first encountered some of these problems but there are for sure workarounds.
First, while you are trying to debug Python, I use in these cases following
AppleScript to inspect links:
______________ Begin of AppleScript "Inspect Linked Files"______________
(*
Name Inspect Linked Files
Purpose Display to user files linked to currently selected publications
and report on missing or broken links. There are two kinds of broken links
possible: symbolic links or Finder alias that no longer have an original.
Installation
Copy this script to folder '~/Library/Application
Support/BibDesk/Scripts/'
Usage Run this script by choosing corresponding menu command
from within BibDesk's Script menu
Remark Alternatively you can also run this script from anywhere on
your system without any installation.
Programmer Andreas Fischlin, [email protected]
http://www.sysecol.ethz.ch/staff/af/
History
af 01.Sep.2009 v 1.0: First implementation (works with
BibDesk Version 1.3.21 (1525)
under Leopard
OS X 10.5.8)
af 06.Jan.2010 v 1.1: Allows to properly abort the display
loop in case of multiple selection (works with BibDesk Version 1.4 (1701) under
Leopard OS X 10.5.8) and always displays a result of analysis, even in case if
selection exceeds noSelectedForReportOnlyMissing
af 22.Jan.2010 v 1.2: Bug fix/adapting to new BibDesk
behavior (>= nightly BibDesk-20100117): The boolean expression "if thePubs is
missing value then" replaced for "if (thePubs is missing value) or (thePubs is
{}) then"
af 13.Feb.2010 v 1.3: Bug fix/enhancement: Proper
distinction between symbolic links (s) and ordinary files (•)
af 08.Apr.2010 v 1.4: Enhancement: (i) Reports for each
broken link all retrievable information about original files to assist any
fixing by user. (ii) Adding logging to report on all missing/broken links in a
written form in case some detected.
*)
(* internally used global variables *)
property theMissingList : "" -- determined at run time
property logFile : "~/Library/Logs/BibDesk.log" -- used to log the autofiling
actions
(* preferences *)
property onlyPOSIXPFNs : false -- set this flag according to your preferences.
If true, only POSIX path information will be displayed. If false, both POSIX
path as well as HFS information will be shown.
property noSelectedForReportOnlyMissing : 3 -- for up to this number of
publications selected do report all linked files. Otherwise report only about
broken file links at the end of the processing by informing the user about all
cite keys for which some file links have been found to be broken or missing.
on run {}
tell application "BibDesk"
set theBibDeskDocu to first document
set thePDFRepositoryFolder to papers folder
set thePubs to selection of theBibDeskDocu
end tell
if not ((thePubs is missing value) or (thePubs is {})) then
startLogging("Script 'Inspect Linked Files' (tabulating only
broken file links):")
set theNoOfPubsSelected to (count of thePubs)
set reportOnlyMissing to (theNoOfPubsSelected >
noSelectedForReportOnlyMissing)
set theMissingList to ""
set theNoOfMissingFiles to 0
repeat with thePub in thePubs
tell application "BibDesk"
tell thePub
set allLinkedFiles to (get POSIX path
of linked files)
if not onlyPOSIXPFNs then
set allLinkedHFSFiles to (get
linked files)
set allLinkedFileURLs to (get
URL of linked files)
end if
set theCiteKey to get cite key
end tell
end tell
set nameList to ""
set someMissing to false
set noOfLinkedFiles to (count of allLinkedFiles)
set kindList to "Kind: "
repeat with i from 1 to noOfLinkedFiles
set theLinkedFile to item i of allLinkedFiles
if onlyPOSIXPFNs then
set nameList to nameList & return &
return & i & ") " & theLinkedFile
else
set theLinkedHFSFile to item i of
allLinkedHFSFiles
set nameList to nameList & return &
return & i & ") " & theLinkedFile & return & " " & theLinkedHFSFile
end if
if (theLinkedFile as string) is "missing value"
then
set someMissing to true
set theNoOfMissingFiles to
theNoOfMissingFiles + 1
set kindList to kindList & "-"
else
try
set theOrigFile to ""
set theLinkedHFSFile to item i
of allLinkedHFSFiles
set theFileInfo to (get info
for file theLinkedHFSFile)
set isAlias to alias of
theFileInfo
if isAlias then
try
tell
application "Finder"
set
theOrigFile to ((original item of file theLinkedHFSFile) as string)
set
kindList to kindList & "A"
if
theOrigFile is not "" then
set theOrigFileInfo to "A: -> " & theOrigFile
set nameList to nameList & return & return & theOrigFileInfo
end if
end tell
on error errText number
errNum
if errNum is
-1700 then
-- is
Finder alias with missing original
set
someMissing to true
set
theNoOfMissingFiles to theNoOfMissingFiles + 1
set
kindList to kindList & "-"
set
theOrigFile to getOrigOfAlias(theLinkedHFSFile)
if
theOrigFile is not "" then
set theOrigFileInfo to "- (broken A): " & theOrigFile
set nameList to nameList & return & return & theOrigFileInfo
doLogging(theCiteKey & ": " & theOrigFileInfo)
end if
end if
end try
else
-- try to distinguish
symbolic links from ordinary linked files
set theShellScript to
"test -h " & quoted form of theLinkedFile
try
do shell script
theShellScript
set kindList to
kindList & "s"
on error errText number
errNum
set kindList to
kindList & "•"
end try
end if
on error errText number errNum
if errNum is -43 then
-- is symbolic link
with missing original
set someMissing to true
set theNoOfMissingFiles
to theNoOfMissingFiles + 1
set kindList to
kindList & "-"
set theOrigFile to
getOrigOfSymLink(theLinkedHFSFile)
if theOrigFile is not
"" then
set
theOrigFileInfo to "- (broken s): " & theOrigFile
set nameList to
nameList & return & return & theOrigFileInfo
doLogging(theCiteKey & ": " & theOrigFileInfo)
end if
else
tell me to display
dialog "Error " & errNum & ": " & errText & ¬
" (get info for
linked file " & i & " of " & theCiteKey & ")." buttons {"OK"} default button
{"OK"} with icon caution
end if
end try
end if
if i < noOfLinkedFiles then
set nameList to nameList & return
end if
end repeat
if not reportOnlyMissing then
if noOfLinkedFiles > 1 then
set pluralS to "s"
else
set pluralS to ""
end if
try
set theMsg to theCiteKey & " links to "
& noOfLinkedFiles & " file" & pluralS & ": " & nameList & return & return &
kindList & " (• file; A Alias; s symlink; - broken link)"
display dialog theMsg buttons
{"Cancel", "OK"} default button {"OK"}
on error errText number errNum
if errNum is -128 then
-- User cancelling of multiple
selection loop
exit repeat
else
tell me to display dialog
"Error " & errNum & ": " & errText & ¬
" (Display result for "
& theCiteKey & ")." buttons {"OK"} default button {"OK"} with icon caution
end if
end try
end if
if someMissing then
recordBrokenFileLink(theCiteKey)
end if
end repeat
if (theMissingList is not "") then
if theNoOfMissingFiles > 1 then
set pluralS to "s"
else
set pluralS to ""
end if
set theMsg to (theNoOfMissingFiles as string) & "
broken file link" & pluralS & " detected for: " & theMissingList & " (checked "
& theNoOfPubsSelected & " publication"
if theNoOfPubsSelected > 1 then
set theMsg to theMsg & "s"
end if
set theMsg to theMsg & ")"
else
set theMsg to "In " & theNoOfPubsSelected & " selected
publications no broken file links detected."
end if
display dialog theMsg buttons {"OK"} default button "OK" giving
up after 40 with icon note
doLogging("Legend: • file; A Alias; s symlink; - broken link")
doLogging("Script 'Inspect Linked Files' at end: " & theMsg)
else
beep
end if
end run
on getOrigOfAlias(theFile)
try
do shell script "/usr/bin/strings " & quoted form of ((POSIX
path of theFile) & "/rsrc") & " | /usr/bin/grep ':' | /usr/bin/colrm 1 1"
set theOrigPFN to (first paragraph of result) as alias
set theAliasFileName to do shell script "basename " & quoted
form of (POSIX path of theFile)
return "Alias " & theAliasFileName & "'s original: " &
theOrigPFN
on error errMsg number errNum
if errNum is -43 then
set theAliasFileName to do shell script "basename " &
quoted form of (POSIX path of theFile)
return theAliasFileName & " without original: " & errMsg
else
display dialog "Error " & errNum & ":" & return &
return & errMsg buttons {"OK"} default button 1 with icon caution
return ""
end if
end try
end getOrigOfAlias
on getOrigOfSymLink(theFile)
try
set theOrigPFN to do shell script "ls -l " & quoted form of
(POSIX path of theFile) & " | sed -e \"s|.* -> ||\" "
set theSymLinkFileName to do shell script "basename " & quoted
form of (POSIX path of theFile)
return theSymLinkFileName & " -> " & theOrigPFN
on error errMsg number errNum
display dialog "Error " & errNum & ":" & return & return &
errMsg buttons {"OK"} default button 1 with icon caution
return ""
end try
end getOrigOfSymLink
on recordBrokenFileLink(theCiteKey)
if theMissingList is "" then
set theMissingList to theCiteKey
else
set theMissingList to theMissingList & ", " & theCiteKey
end if
end recordBrokenFileLink
on startLogging(theEntry)
try
do shell script "echo ' ' >> " & logFile
do shell script "date >> " & logFile
set theEntry to (theEntry as string)
-- logging may not work if theEntry contains special characters
such as ', ", or ( ) unless you use 'quoted form of'
do shell script "echo " & quoted form of theEntry & return & "
| cat >> " & logFile
end try
end startLogging
on doLogging(theEntry)
try
set theEntry to (theEntry as string)
-- logging may not work if theEntry contains special characters
such as ', ", or ( ) unless you use 'quoted form of'
do shell script "echo " & quoted form of theEntry & return & "
| cat >> " & logFile
end try
end doLogging
______________ End of AppleScript "Inspect Linked Files"______________
Maybe this helps a bit, albeit I am fully aware that this script can not
decipher the coding of broken links into a human readable form such as
'../MyGreatPdfRepository/Subdir/MyGreatArticle.pdf'. AFAIK the python script
would.
Perhaps, Christiaan, is there not the possibility to make the decoding of a
broken link available via AppleScript? Extra command?
Then I wrote an AppleScript to fix broken pdf links in cases where repairing
was the only remedy. It works fine, but may require hours for fixing 1500
records. Moreover, the script certainly would require some adaptation for your
case, since it relies on pdf files having been named according to strict naming
rules that are known to the algorithm.
Regards,
Andreas
ETH Zurich
Prof. Dr. Andreas Fischlin
Systems Ecology - Institute of Integrative Biology
CHN E 21.1
Universitaetstrasse 16
8092 Zurich
SWITZERLAND
[email protected]
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 14/Jul/2010, at 12:53 , Anil N. Hirani wrote:
> I'd like to find out how to debug the problem I am seeing. To
> summarize : I have two identical Macs with identical set up of the bib
> file and the PDF files it refers to. The links work on one Mac but not
> the other.
>
> Details :
>
> I have two identical Macs, each with a working copy of my SVN
> respoitory. The bib file and the PDF files it links to are all in the
> repository. The relative and absolute locations of the bib file and
> the PDF files are IDENTICAL on the 2 Macs. Because the papers
> directory is very large, and one of the Macs is on a slower internet
> connection, I made a tarball of the papers from one and brought it on
> a USB disk to the other Mac. Then I untarred it on the location where
> SVN would have put it. Now an svn update shows that the working copy
> is up to date and identical to the repository hence to the other Mac.
> The bib file is literally identical on both Macs since it is
> downloaded from the SVN repository and to make sure, I have checked
> with diff. The PDF files directory is literally identical because it
> is a tar copy of the other. The permissions, even the change dates of
> the PDF files are identical. For the last 5 years, before I had to
> redo the working copies, the links used to work on both Macs. At that
> time the PDF files had been downloaded from SVN directly even on the
> slower internet Mac.
>
> Why do the links now work on one Mac and not on the other ?
>
> There are 1500 entries so I can't repair those by hand. In any case I
> don't want to then break the links on the other Mac. The PDF files
> have grown in number over the years and I can't download from the
> repository on the slow internet Mac -- it would just take too long.
>
> I would like to find out how to debug this strange problem. Is there a
> debug mode in Bibdesk that I can turn on ? Otherwise, knowing more
> about how the linking in Bibdesk works may help me figure this out.
>
> Thanks
> Anil
>
>
>
> On Jul 5, 2010, at 10:12 AM, Christiaan Hofman wrote:
>>
>> This can be a problem if you've moved the PDF repository to the
>> trash while BibDesk was running and then saved the .bib, because
>> then all links will point to your papers folder in the trash (and
>> the original location will be lost).
>>
>> The way you should have done this is to first make sure you close
>> the .bib file, then replace the the whole papers folder so that all
>> (relative and absolute) paths of the linked files remain the same,
>> then open the .bib file in BibDesk, inspect the links, and save
>> the .bib file.
>>
>> If you did not do this, and you've saved the .bib file in the mean
>> time (with broken links), you may have a problem. In that case you
>> should better use a backup of your .bib file and proceed as above.
>> If you don't have a backup, well, then you've learned the hard truth
>> that you should always save backups of your important files.
>>
>> As a last resort, you may want to move your new papers folder to the
>> location where your paper folder was when you saved your .bib file
>> (which may be the trash), and if the links then work save the .bib
>> file, move the papers folder back to where you want it, and save
>> the .bib file again.
>>
>> BibDesk will look for linked files first by relative path (relative
>> to the .bib file). If it doesn't find a file, it will look for the
>> file by full path. If it still doesn't find the file, it will look
>> for the file object (that may have been moved) by file identifier.
>> When you save a .bib file, the links will be updated with the
>> current link.
>>
>> Christiaan
>>>
>>
>> On 05/Jul/2010, at 14:37 , Anil N. Hirani wrote:
>>
>>> In BibDesk I had links to all my PDF papers. I recently had to get a
>>> fresh copy of the directory containing all the papers (deleted the
>>> old
>>> directory, got a copy of an identical directory from another computer
>>> -- due to change in subversion server where all the papers were).
>>>
>>> Now all the links to the papers are broken. Will I have to redo the
>>> links to files for all my 1500 entries or is there another way ?
>>>
>>> Regards
>>> Anil
>>>
>>> Bibdesk-users mailing list
>>> [email protected]
>>> https://lists.sourceforge.net/lists/listinfo/bibdesk-users
>>
>>>
>> _______________________________________________
>> Bibdesk-users mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/bibdesk-users
>
>
> ------------------------------------------------------------------------------
> This SF.net email is sponsored by Sprint
> What will you do first with EVO, the first 4G phone?
> Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
> _______________________________________________
> Bibdesk-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/bibdesk-users
------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Bibdesk-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-users