Cobook ha eliminato tutte le righe vuote nelle note di Contatti

0

Cobook , un Mac relativamente recente & Contatti iPhone / sostituzione rubrica, recentemente cestinato la mia rubrica. Nello specifico, l'app per iPhone ha cancellato ogni riga vuota in ogni nota di ogni contatto. Il problema è stato menzionato passando come risolto nella versione 1.1.1 , ma ciò non ha t ripara la mia rubrica. È molto difficile leggere le note senza separazione dei paragrafi.

Come posso recuperare le righe vuote? Non ho notato il problema subito, quindi mentre potrei ripristinare dal backup, perderò alcuni dati recenti.

    
posta duozmo 09.06.2013 - 19:35
fonte

1 risposta

1

Ho scritto un AppleScript per ricreare le righe vuote che sono state cancellate. È solo approssimativo - deve fare alcune ipotesi imperfette su quando inserire una linea, ma è meglio di niente.

-- Contacts newline reflow
-- Reintroduces paragraph separation into contacts' notes
-- after a bug in Cobook deleted all blank lines.
-- (Fixed in Cobook v. 1.1.1: http://blog.cobook.co/post/43633583273/cobook-with-google-maps)

-- Based on Nigel Garvey's work at MacScripter
-- http://macscripter.net/viewtopic.php?pid=153540#p153540

-- Get all the people IDs and notes in one go, for efficiency.
tell application "Contacts" to set {theIDs, theFirstNames, theLastNames, theCompanies, theOrgs, theNotes} to {id, first name, last name, company, organization, note} of people

-- Store the current text item delimiter(s) and set the delimiter to linefeed.
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to linefeed -- this may now be unnecessary

try
    -- Work through the parallel lists of IDs and notes obtained above.
    repeat with i from 1 to (count theIDs)
        -- Get the next value from the note list.
        set thisNote to item i of theNotes
        -- If it's not 'missing value', there IS a note for this person.

        if (item i of theCompanies is false) then
            set theName to (item i of theFirstNames) & " " & (item i of theLastNames)
        else
            set theName to (item i of theOrgs)
        end if

        if (thisNote is not missing value) then
            -- Split the note text into paragraphs.
            set theParagraphs to thisNote's paragraphs
            set newParagraphs to {}

            -- PGP block state machine:
            -- 0 not in PGP block
            -- 1 First line of PGP block (always "-----BEGIN PGP MESSAGE-----")
            -- 2 In PGP block header, not first line
            -- 3 In PGP block body, first line
            -- 4 In PGP block body, not first line
            -- 5 Last line of PGP block (always "-----END PGP MESSAGE-----")

            set pgpBlockState to 0

            repeat with k from 1 to (count theParagraphs)
                set thisParagraph to (item k of theParagraphs)
                set appendEmptyParagraph to true

                if pgpBlockState is 0 then
                    if (thisParagraph contains "BEGIN PGP MESSAGE") then
                        set pgpBlockState to 1
                    end if
                else if pgpBlockState is 1 then
                    if thisParagraph contains ":" then
                        set pgpBlockState to 2
                    else
                        set pgpBlockState to 3
                    end if
                else if pgpBlockState is 2 then
                    if thisParagraph does not contain ":" then
                        set pgpBlockState to 3
                    end if
                else if pgpBlockState is 3 then
                    set pgpBlockState to 4
                else if pgpBlockState is 4 then
                    if (thisParagraph contains "END PGP MESSAGE") then set pgpBlockState to 5
                else if pgpBlockState is 5 then
                    set pgpBlockState to 0
                end if

                -- Alter output according to pgpBlockState
                if (pgpBlockState is not 0) then set appendEmptyParagraph to false
                if (pgpBlockState is 3) then set end of newParagraphs to "" -- this is a hack, not clean

                -- Conditions under which we don't want a newline
                if (length of thisParagraph < 30) then set appendEmptyParagraph to false
                if (length of thisParagraph > 1 and first character of thisParagraph = "-") then set appendEmptyParagraph to false
                if (length of thisParagraph > 1 and first character of thisParagraph = "•") then set appendEmptyParagraph to false

                if (thisParagraph is not equal to "") then set end of newParagraphs to thisParagraph -- delete any manual paragraph separation
                if (appendEmptyParagraph) then set end of newParagraphs to "" -- remember, newParagraphs is a list, not a string
            end repeat

            if (count of newParagraphs) > 0 then
                -- Get the number of the last "non-empty" one.
                repeat with j from (count newParagraphs) to 1 by -1
                    if ((count item j of newParagraphs) > 0) then exit repeat
                end repeat

                -- Coerce the paragraphs (up to the last non-empty one) to a single text, using the linefeed delimiter.
                set editedNote to (items 1 thru j of newParagraphs) as text

                tell application "Contacts" to set note of person id (item i of theIDs) to editedNote
                log "Updated entry for: " & theName
            else
                log "Skipping / no note for: " & theName -- handles Exchange-based notes, which don't equal "missing value" even when blank
            end if

        end if
    end repeat
on error msg
    display dialog msg buttons {"OK"} default button 1
end try

-- Restore the old delimiter value.
set AppleScript's text item delimiters to astid

-- Save the Contacts changes.
tell application "Contacts" to save
--> Returns 'missing value'. No known significance.

C'è una lunga sezione nel mezzo che gestisce i blocchi PGP che potrebbero apparire nella tua rubrica. Può sembrare eccessivo, ma quei blocchi sono super-sensibili per avere un posizionamento di nuova linea corretto. Se ti mancano le nuove righe appropriate, GPGTools (nel suo stato attuale) falliranno semplicemente quando proverai a decrittografarle e non fornirai alcun errore utile a indicare il problema.

Per eseguirlo, incollalo in AppleScript Editor e fai clic su Esegui. Avviso pro forma: esegui il backup dei contatti in anticipo.

    
risposta data 09.06.2013 - 19:35
fonte

Leggi altre domande sui tag