Skip to content

Instantly share code, notes, and snippets.

@jeabraham
Last active October 6, 2020 23:45
Show Gist options
  • Save jeabraham/67a6653817d004b823a5735f6fb09eb5 to your computer and use it in GitHub Desktop.
Save jeabraham/67a6653817d004b823a5735f6fb09eb5 to your computer and use it in GitHub Desktop.
Applescript GUI Script to backup Family Tree Maker tree to a gedcome file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>ca.theabrahams.makegedcom</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/osascript</string>
<string>/Users/jabraham/Developer/GedcomBackup.scpt</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>3</integer>
<key>Minute</key>
<integer>42</integer>
<key>Weekday</key>
<integer>4</integer>
</dict>
</dict>
</plist>
set backup_location to "/Volumes/ExtraDisk/FamilyTreeMakerBackups"
backup_recent_tree("Abraham family tree 2018.ftm", backup_location)
backup_recent_tree("de Kat Family Tree_2017-05-13.ftm", backup_location)
on backup_recent_tree(tree_name, backup_location)
try
tell application "Family Tree Maker 2019"
activate
end tell
tell application "System Events"
tell process "Family Tree Maker 2019"
click menu item tree_name of menu "Open Recent" of menu item "Open Recent" of menu "File" of menu bar item "File" of menu bar 1
click menu item "Export…" of menu "File" of menu bar item "File" of menu bar 1
tell sheet 1 of window tree_name
tell pop up button 1
click
delay 0.2
click menu item "GEDCOM" of menu 1
end tell
click button "Export"
end tell
tell sheet 1 of window tree_name
#tell text field 1
# keystroke "/"
#end tell
# keystroke "/"
delay 2
keystroke "g" using {command down, shift down}
#repeat until exists sheet 1
delay 2
#end repeat
tell sheet 1
keystroke backup_location
keystroke "/"
keystroke tree_name
delay 1
click button "Go"
end tell
set value of text field 1 to "backup_" & my date_stamp()
#set value of text field 1 to backup_location & "/" & tree_name & "/" & "backup_" & my date_stamp()
click button "Save"
set confirm_button to a reference to (button "Replace" of sheet 1)
if confirm_button exists then
click confirm_button
end if
repeat 60 times
set ok_button to a reference to (button "OK")
if ok_button exists then
click ok_button
exit repeat
end if
delay 1
end repeat
end tell
# set text field "Save As:" of sheet 1 of window tree_name to "backup_" & my date_stamp() & ".ged"
end tell
end tell
return true
on error error_message
log error_message
return false
end try
log "Done"
return trueapp
end backup_recent_tree
on date_stamp()
set dateObj to (current date)
set theMonth to text -1 thru -2 of ("0" & (month of dateObj as number))
set theDay to text -1 thru -2 of ("0" & day of dateObj)
set theYear to year of dateObj
set dateStamp to "" & theYear & theMonth & theDay
return dateStamp
end date_stamp

How to backup your trees automatically in Family Tree Maker 2019 for Macintosh

UI script to control Family Tree Maker 2019 to create backups.

Open the ScriptEditor application on your mac.

File new and copy in the entire GedcomBackup.scpt I've provided.

Change the first line to the location of your backup folder (should be a big external drive)

Check the next lines to be the exact names of your trees in Family Tree Maker, and these trees have to be in the recent list in File -> Open Recent (If they aren't in the recent list, open them up manually in the Family Tree Maker Program). I was backing up two trees, if you only want to back up one you can delete one of the lines.

In your backup folder, make new folders that have the the exact same names of your trees. The backups are called backup_YYYYMMDD.ged, so you need the folder names to know what tree was backed up.

Save the script, then test it by pressing the run button. Make sure it works.

Note at some point you will be prompted to allow Script Editor to control your computer. You will have to do so in settings.

Automate the script to run every thursday morning at 3:42AM

Once you are happy that your script is running, the next step is to get it to run automatically on Thursday morning at 3:42 AM.

From Script Editor, File -> Export the working script to some folder such as your home folder.

Using a text editor, open the file above ca.theabrahams.makegedcom.plist. On line 10 you need to enter the place where you just exported the working script, e.g. if your username is fred, maybe you just exported it to /Users/fred/GedcomBackup.scpt.

Save the file into your LaunchAgents folder, which is /Users/fred/Library/LaunchAgents if your username is fred, but if your username isn't fred it it will be a little different of course.

Start the Terminal app.

Inside Terminal, type launchctl load /Users/fred/Library/LaunchAgents/ca.theabrahams.makegedcom.plist (of course again, if your username isn't fred, this will be a little different

Since I set RunAtLoad to True in the file, it should immediately create a GEDCom backup of your tree. Don't try to do anything else on your computer while it's running, as the scripting requires the Family Tree Maker 2019 windows to be in the front, and if you do something else another window might get in front and it might start typing stuff or pressing buttons into other applications.

Note at some point you will be prompted to allow osascript to control your computer. You will have to allow it. Then, you might have to unload and reload the agent to try again, which you do in the Terminal window by typing

launchctl unload /Users/fred/Library/LaunchAgents/ca.theabrahams.makegedcom.plist
launchctl load /Users/fred/Library/LaunchAgents/ca.theabrahams.makegedcom.plist

Once it's running with the launchctl load command, you can leave it until Thursday morning. Then, check to see if there's a new backup created.

It is critical that you back up your hard drive regularly (e.g. using TimeMachine), but it also critical to storing your tree off-site. If you have some big cloud storage, like Google Drive or Dropbox, you may be able to set your backup location to be in your Drive or Dropbox, so it gets synced to the cloud automatically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment