Announcement

Collapse
No announcement yet.

Tip - Make GEDCOM Readable using AppleScript

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Tip - Make GEDCOM Readable using AppleScript

    Over the past few days I’ve been reviewing GEDCOM files. As you can imagine this is very boring and GEDCOM files are difficult to read - ZZZzzzz.

    So I created this AppleScript to help make a GEDCOM somewhat more “readable”. This AppleScript indents a Level 1 (e.g., NAME, BIRT, RESI, etc.) by one indent, it indents a Level 2 (e.g., DATE, PLAC, etc.) by two indents, and it indents a Level 3 by three indents, etc.

    I would not suggest using the output file to import data into Reunion (or any other family tree-type application). It is purely used to make GEDCOM easier to read when reviewing a GEDCOM file. Indentation was added for readability only.

    The enclosed AppleScript requires the text editor TextWranger (free) or BBEdit (cost $) to be available in your Applications folder to operate.

    Code:
    --
    -- This AppleScript is to make a GEDCOM file somewhat more "readable".  
    --    It indents a Level 1 by one indent, it indents a Level 2 by two indents, it indents a Level 3 by three indents, etc.
    
    -- This is based on an sample found in The GEDCOM Standard Release 5.5 (released in January 1996)
    --    http://homepages.rootsweb.ancestry.com/~pmcbride/gedcom/55gcch2.htm
    --    The sample was located in Chapter 2 under the title "Sample Lineage-Linked GEDCOM Transmission"
    
    -- I would not suggest using the output file to import data into Reunion (or any other family tree-type application).
    --    It is purely used to make GEDCOM easier to read when reviewing a GEDCOM file.
    --    Indentation was added for readability only.
    --
    
    -- get GEDCOM file to operate on
    set GEDinFile to (choose file with prompt "Choose GEDCOM File" of type {"ged"})
    set file_to_copy to quoted form of POSIX path of GEDinFile
    set GEDoutFile to (GEDinFile & " (w indents).txt" as string)
    set target_file to quoted form of POSIX path of GEDoutFile
    
    -- copy original GEDCOM file to a new file
    try
    	do shell script "cp " & file_to_copy & space & target_file
    	
    on error errorMsg number errorNum -- Something bad happened
    	display dialog errorMsg & "
     Error Number = " & errorNum
    	return
    end try
    
    tell application "TextWrangler" --  or "BBEdit"
    	
    	open GEDoutFile -- open up the copy - we don't want to mess up the original!
    	
    	-- Level 0
    	--    Look for the beginning of a new record.  The beginning of a new record is indicated by a line whose level number is 0 (zero).
    	--    add a new line before a Level 0  - just to make it easier on the eye
    	--
    	replace "^(0 @[@A-Z]*)(.*$)" using "\\n&" searching in text of text document 1 options {search mode:grep, starting at top:false, wrap around:false, backwards:false, case sensitive:false, match words:false, extend selection:false}
    	
    	-- Level 1
    	--    Look for Level 1 information  
    	--    add a one tab before a Level 1  - just to make it easier on the eye
    	--
    	replace "^(1 [_A-Z][A-Z]*)(.*$)" using "\\t\\1\\t\\t\\2" searching in text of text document 1 options {search mode:grep, starting at top:false, wrap around:false, backwards:false, case sensitive:false, match words:false, extend selection:false}
    	
    	-- Level 2
    	--    Look for Level 2 information  
    	--    add two tabs before a Level 2
    	--
    	replace "^(2 [_A-Z][A-Z]*)(.*$)" using "\\t\\t\\1\\t\\t\\2" searching in text of text document 1 options {search mode:grep, starting at top:false, wrap around:false, backwards:false, case sensitive:false, match words:false, extend selection:false}
    	
    	-- Level 3
    	--    Look for Level 3 information  
    	--    add three tabs before a Level 3
    	--
    	replace "^(3 [_A-Z][A-Z]*)(.*$)" using "\\t\\t\\t\\1\\t\\t\\2" searching in text of text document 1 options {search mode:grep, starting at top:false, wrap around:false, backwards:false, case sensitive:false, match words:false, extend selection:false}
    	
    	-- Level 4
    	--    Look for Level 4 information  
    	--    add four tabs before a Level 4
    	--
    	replace "^(4 [_A-Z][A-Z]*)(.*$)" using "\\t\\t\\t\\t\\1\\t\\t\\2" searching in text of text document 1 options {search mode:grep, starting at top:false, wrap around:false, backwards:false, case sensitive:false, match words:false, extend selection:false}
    	
    	-- Level 5
    	--    Look for Level 5 information  
    	--    add five tabs before a Level 5
    	--
    	replace "^(5 [_A-Z][A-Z]*)(.*$)" using "\\t\\t\\t\\t\\t\\1\\t\\t\\2" searching in text of text document 1 options {search mode:grep, starting at top:false, wrap around:false, backwards:false, case sensitive:false, match words:false, extend selection:false}
    	
    	save (GEDoutFile as alias)
    	
    end tell

    Details:
    The idea for this came from “The GEDCOM Standard Release 5.5” (released in January 1996) at http://homepages.rootsweb.ancestry.c...om/55gcch2.htm
    The example found was located in Chapter 2 under the section titled "Sample Lineage-Linked GEDCOM Transmission"

    This AppleScript will indent up to 5 Levels (mostly CONC) since that is all I found when looking thru my Reunion & Ancestry.com GEDCOM files. The AppleScript can be easily modified to do additional Levels.

    You can download TextWrangler at http://www.barebones.com/products/textwrangler/
    Place TextWrangler or BBEdit in your Applications folder and then run this Applescript.

    A family tree with 1,400 individuals that produces a GEDCOM with 40,000 lines completes in about about 15 seconds.

    Hope this helps someone!
    Jon

    PS - a special shout-out to MacScripter at http://macscripter.net/index.php for their excellent AppleScript forums.
    Attached Files
    Last edited by jcmurphy; 20 August 2014, 11:33 AM. Reason: added a single line that includes a shout-out for assistance
    Jon

    iMac late-2015 (iMac 17,1) and macOS Sierra version 11.12.x
    Reunion 11.x & Safari 10.x

    #2
    Re: Tip - Make GEDCOM Readable using AppleScript

    Jon

    Thanks for the script. It does make reading a Gedcom much more readable.

    Comment


      #3
      Re: Tip - Make GEDCOM Readable using AppleScript

      [QUOTE=jcmurphy;41811]Over the past few days I

      Comment


        #4
        Re: Tip - Make GEDCOM Readable using AppleScript

        Originally posted by John Hill View Post
        This [script] seems to leave TextWrangler open. Is this unavoidable?
        I think this added at the end should do the job, but I haven't tested it.

        tell application "TextWrangler"
        quit
        end tell
        Dennis J. Cunniff
        Click here to email me

        Comment


          #5
          Re: Tip - Make GEDCOM Readable using AppleScript

          Originally posted by John Hill View Post

          But it seems to leave TextWrangler open. Is this unavoidable?
          I had left Textwrangler open so I could review the indented results. To quit Textwrangler add a "close documents" and a "quit" immediately after the save.

          Code:
          	save (GEDoutFile as alias)
          
          	close documents
          	quit
          	
          end tell
          Jon

          iMac late-2015 (iMac 17,1) and macOS Sierra version 11.12.x
          Reunion 11.x & Safari 10.x

          Comment


            #6
            Re: Tip - Make GEDCOM Readable using AppleScript

            Originally posted by jcmurphy View Post
            I had left Textwrangler open so I could review the indented results. To quit Textwrangler add a "close documents" and a "quit" immediately after the save.

            Code:
            	save (GEDoutFile as alias)
            
            	close documents
            	quit
            	
            end tell
            Fair enough. I have noted this but for the present will leave well alone.

            John.

            Comment


              #7
              Re: Tip - Make GEDCOM Readable using AppleScript

              Feel free to make any changes to the AppleScript!
              Jon

              iMac late-2015 (iMac 17,1) and macOS Sierra version 11.12.x
              Reunion 11.x & Safari 10.x

              Comment

              Working...
              X