Swift AI GPS Backfill Tool for MacDive

General MacDive discussion, updates, etc.
Post Reply
Bollar
Posts: 55
Joined: Mon Nov 20, 2017 10:29 am
Dive Computer: Shearwater Perdix 2

Swift AI GPS Backfill Tool for MacDive

Post by Bollar »

I wrote a small utility that extracts GPS coordinates from the Shearwater Swift AI transmitter data already sitting in your MacDive database and backfills them into your dive sites.

If you dive with a Shearwater computer paired with a Swift AI GPS, your dive computer records entry and exit GPS on every dive. MacDive imports the raw data but doesn't extract the embedded coordinates — so those dives end up without map pins. This script fixes that.

What it does:
- Scans your MacDive database for Shearwater dives with raw data but no GPS
- Decompresses the dive computer memory and extracts entry/exit coordinates
- Creates dive sites with map pins at the entry location
- Reverse-geocodes to fill in country and region
- Appends both entry and exit coordinates to your dive notes
- Dry-run by default, automatic backup before any writes

Requirements: Python 3, no dependencies to install. Quit MacDive, run the script, reopen MacDive.

Code: Select all

python3 macdive_gps_backfill.py          # preview
python3 macdive_gps_backfill.py --apply  # write changes
https://github.com/rbollar/macdive-swiftai-gps

If this doesn't work for you, please let me know — I've only tested it on my own database.

I've tried the alternatives and I'm not ready to move on from MacDive yet. This will let me hang on while looking for an alternative, or perhaps writing one myself.

The GPS record format was identified from the https://www.libdivecomputer.org/ open-source library, which added Swift AI GPS support in its Shearwater parser. The decompression algorithm is also from libdivecomputer. Great project — worth knowing about if you're into dive computer data.
Screenshot 2026-02-26 at 5.47.57 AM.jpg
Screenshot 2026-02-26 at 5.48.11 AM.png
User avatar
nick
Site Admin
Posts: 4380
Joined: Sat Apr 12, 2008 8:33 am
Dive Computer: Shearwater Teric
Contact:

Re: Swift AI GPS Backfill Tool for MacDive

Post by nick »

Clever workaround.

I am picking up one of these this weekend, will likely do some dives with it in a month or so, and then do an update to support it.
shoule
Posts: 3
Joined: Mon Jan 12, 2026 9:48 am
Dive Computer: Shearwater Perdix 2

Re: Swift AI GPS Backfill Tool for MacDive

Post by shoule »

@nick I am going on a liveaboard in less than 2 weeks. As my buddy and I will be doing a lot of dives in a short time (with Swift GPS), we are willing to try a beta version if that is something possible.
tcherna
Posts: 7
Joined: Sun Apr 04, 2010 12:15 am
Dive Computer: VT3/Veo200

Re: Swift AI GPS Backfill Tool for MacDive

Post by tcherna »

Did you try editing the locations or only used the information that was populated by the tool? I find if I edit the locations then MacDive will crash.

Code: Select all

Date/Time:           2026-04-05 16:34:51.3357 +0800
Launch Time:         2026-04-05 16:34:50.8647 +0800
Hardware Model:      MacBookPro18,4
OS Version:          macOS 26.3.1 (25D771280a)
Release Type:        User

Crash Reporter Key:  A3DCED2D-DFE1-2770-660F-14616C1F736D
Incident Identifier: 2B28E6C6-1AB9-4614-9990-8D04294ADCA6

Sleep/Wake UUID:       60086C5C-ADE5-401C-9BD3-7551E63C7656

Time Awake Since Boot: 1800 seconds
Time Since Wake:       1305 seconds

System Integrity Protection: enabled

Triggered by Thread: 0, Dispatch Queue: com.apple.main-thread

Exception Type:    EXC_CRASH (SIGABRT)
Exception Codes:   0x0000000000000000, 0x0000000000000000
Exception Reason:  *** -[__NSDictionaryM setObject:forKeyedSubscript:]: key cannot be nil

Termination Reason:  Namespace SIGNAL, Code 6, Abort trap: 6
Terminating Process: MacDive [1702]


Application Specific Information:
abort() called


Last Exception Backtrace:
0   CoreFoundation                	       0x19b9438f0 __exceptionPreprocess + 164
1   libobjc.A.dylib               	       0x19b41a418 objc_exception_throw + 88
2   CoreFoundation                	       0x19ba703dc -[__NSDictionaryM setObject:forKeyedSubscript:] + 1184
3   MacDive                       	       0x1001367ec 0x10012c000 + 42988
4   MacDive                       	       0x100136394 0x10012c000 + 41876
5   MacDive                       	       0x100136178 0x10012c000 + 41336
6   AppKit                        	       0x1a0498a24 -[NSIBObjectData nibInstantiateWithOwner:options:topLevelObjects:] + 864
7   AppKit                        	       0x1a068310c -[NSNib _instantiateNibWithExternalNameTable:options:] + 332
8   AppKit                        	       0x1a06832a8 -[NSNib _instantiateWithOwner:options:topLevelObjects:] + 132
9   AppKit                        	       0x19fd34388 -[NSViewController loadView] + 296
10  AppKit                        	       0x1a036e990 __39-[NSViewController _loadViewIfRequired]_block_invoke + 60
11  AppKit                        	       0x19fd31a10 NSPerformVisuallyAtomicChange + 108
12  AppKit                        	       0x19fd34250 -[NSViewController _loadViewIfRequired] + 116
13  AppKit                        	       0x19fd34190 -[NSViewController view] + 24
14  MacDive                       	       0x10014eeac 0x10012c000 + 143020
15  MacDive                       	       0x10014b164 0x10012c000 + 127332
16  AppKit                        	       0x1a0498a24 -[NSIBObjectData nibInstantiateWithOwner:options:topLevelObjects:] + 864
17  AppKit                        	       0x19fcfcf88 loadNib + 340
18  AppKit                        	       0x1a069c944 +[NSBundle(NSNibLoading) _loadNibFile:nameTable:options:withZone:ownerBundle:] + 1064
19  AppKit                        	       0x19fdbaf68 -[NSWindowController loadWindow] + 300
20  AppKit                        	       0x19fdbad20 -[NSWindowController window] + 80
21  AppKit                        	       0x1a0d5eb6c -[NSWindowController showWindow:] + 44
22  MacDive                       	       0x100148000 0x10012c000 + 114688
23  CoreFoundation                	       0x19ba2875c -[NSSet makeObjectsPerformSelector:] + 176
24  AppKit                        	       0x1a0498a04 -[NSIBObjectData nibInstantiateWithOwner:options:topLevelObjects:] + 832
25  AppKit                        	       0x19fcfcf88 loadNib + 340
26  AppKit                        	       0x1a069c944 +[NSBundle(NSNibLoading) _loadNibFile:nameTable:options:withZone:ownerBundle:] + 1064
27  AppKit                        	       0x1a069cc64 -[NSBundle(NSNibLoading) loadNibNamed:owner:topLevelObjects:] + 180
28  AppKit                        	       0x1a069c3e0 +[NSBundle(NSNibLoading) loadNibNamed:owner:] + 300
29  AppKit                        	       0x19fcf455c NSApplicationMain + 496
30  dyld                          	       0x19b48dd54 start + 7184
tcherna
Posts: 7
Joined: Sun Apr 04, 2010 12:15 am
Dive Computer: VT3/Veo200

Re: Swift AI GPS Backfill Tool for MacDive

Post by tcherna »

The biggest test that something is wrong in the new site data is that even after populating the country/location/site name, the site name appears blank and does not appear as a drop down as normal. I'm still using the tool to log the gps coords so I can manually enter them.

I can share corrupted dbs to anyone who wants :). Also, thanks for making the script and having it do backups too :D
Bollar
Posts: 55
Joined: Mon Nov 20, 2017 10:29 am
Dive Computer: Shearwater Perdix 2

Re: Swift AI GPS Backfill Tool for MacDive

Post by Bollar »

Ah, I didn't add a name to the DB before geolocating the position. I have a replacement on GitHub now that should work. Please let me know either way.

Just in case it wasn't obvious, you do need to restore the backup and run on the original MacDive database.

https://github.com/rbollar/macdive-swiftai-gps
tcherna
Posts: 7
Joined: Sun Apr 04, 2010 12:15 am
Dive Computer: VT3/Veo200

Re: Swift AI GPS Backfill Tool for MacDive

Post by tcherna »

I'm not sure that's all it, as now MacDive will crash just after running the script. Any reason you aren't passing the mod time any more? Also I'm wondering if it needs real defaults other than None
tcherna
Posts: 7
Joined: Sun Apr 04, 2010 12:15 am
Dive Computer: VT3/Veo200

Re: Swift AI GPS Backfill Tool for MacDive

Post by tcherna »

Here's a version which seems to work. It matches the default strings when creating a site in macdive, adds the required uuid, and creates a site name that makes it easy to edit (by appending the dive number from the modified created sites)

Code: Select all

    # Create new ZDIVESITE
    site_pk = next_site_pk(db)
    site_uuid = str(uuid.uuid4()).upper()
    site_name = f"New Site {dive_num}"
    now = time.time() - 978307200  # Core Data epoch

    db.execute("""
        INSERT INTO ZDIVESITE
            (Z_PK, Z_ENT, Z_OPT, ZGPSLAT, ZGPSLON,
             ZCOUNTRY, ZLOCATION, ZBODYOFWATER, ZMODIFIED, ZNAME, ZUUID)
    VALUES (?, ?, 1, ?, ?, ?, ?, ?, ?, ?, ?)
    """, (site_pk, site_ent, entry_lat, entry_lon,
          (geo[0] if geo and geo[0] else "New Country"),
          (geo[1] if geo and geo[1] else "New Location"),
          (geo[2] if geo and geo[2] else None),
          now,
          site_name,
          site_uuid
          ))
Bollar
Posts: 55
Joined: Mon Nov 20, 2017 10:29 am
Dive Computer: Shearwater Perdix 2

Re: Swift AI GPS Backfill Tool for MacDive

Post by Bollar »

Great!

You did the hard work and the current version incorporates the solution you identified along with a guard to prevent running if a .bak exists. The other difference is that we geolocate the coordinates, if possible.
Post Reply