Cobook borró todas las líneas en blanco en las notas de los Contactos

0

Cobook , un Mac relativamente nuevo y amp; Reemplazo de contactos / libreta de direcciones de iPhone, recientemente eliminé mi libreta de direcciones Específicamente, la aplicación del iPhone eliminó cada línea en blanco en cada nota de cada contacto. El problema se mencionó de pasada como corregido en la versión 1.1.1 , pero no fue así t reparar mi libreta de direcciones Es muy difícil leer notas sin separación de párrafos.

¿Cómo puedo recuperar las líneas en blanco? No noté el problema de inmediato, así que mientras pueda restaurar desde una copia de seguridad, perderé algunos datos recientes.

    
pregunta duozmo 09.06.2013 - 19:35

1 respuesta

1

Escribí un AppleScript para volver a crear las líneas en blanco que se eliminaron. Es solo aproximado: tiene que hacer ciertas suposiciones imperfectas sobre cuándo insertar una línea, pero es mejor que nada.

-- 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.

Hay una sección larga en el centro que maneja los bloques PGP que pueden aparecer en su libreta de direcciones. Puede parecer una exageración, pero esos bloques son muy sensibles a tener una ubicación de nueva línea correcta. Si no tiene las nuevas líneas adecuadas, GPGTools (en su estado actual) simplemente fallará cuando intente descifrarlas y no dará ningún error útil que indique el problema.

Para ejecutar esto, simplemente péguelo en el Editor de AppleScript y haga clic en Ejecutar. Advertencia pro forma: haga una copia de seguridad de sus contactos de antemano.

    
respondido por el duozmo 09.06.2013 - 19:35

Lea otras preguntas en las etiquetas