DEV Community

Cover image for Opening a PDF Without Leaving a Single Trace on macOS [Devlog #9]
hiyoyo
hiyoyo

Posted on

Opening a PDF Without Leaving a Single Trace on macOS [Devlog #9]

All tests run on an 8-year-old MacBook Air.

Open a PDF on macOS and the OS quietly logs it in at least five places:

  • Recent Documents (NSDocumentController)
  • Finder's recent items (LSSharedFileList)
  • App cache directory
  • QuickLook thumbnail cache
  • Rendering cache under ~/Library/Caches/

Sanctuary Viewer blocks all of them.


Blocking Recent Documents

macOS auto-registers opened files via NSDocumentController. Override it on the Swift side:

@implementation HiyokoSanctuaryDocument

- (void)addToRecentDocuments {
    // intentionally empty
}

+ (BOOL)autosavesInPlace {
    return NO;
}

@end
Enter fullscreen mode Exit fullscreen mode

No disk writes — memory only

pub struct SanctuaryViewer {
    page_cache: HashMap>,
    temp_files: Vec,
}

impl Drop for SanctuaryViewer {
    fn drop(&mut self) {
        // Delete any temp files on close
        for path in &self.temp_files {
            let _ = std::fs::remove_file(path);
        }
        // Zero out in-memory cache
        self.page_cache.clear();
    }
}
Enter fullscreen mode Exit fullscreen mode

Drop fires the moment the viewer closes. No manual cleanup required.


The tricky part: QuickLook

macOS runs QuickLook in the background and writes thumbnails to ~/Library/Caches/com.apple.QuickLook.thumbnailcache automatically.

The fix: never pass the file path to QuickLook. All rendering goes through Ghost Engine in memory — the file path never surfaces to any macOS API that would trigger caching.


Result

Open a PDF in Sanctuary Viewer, close it — the file was never opened, as far as macOS is concerned.


Hiyoko PDF Vault → https://hiyokoko.gumroad.com/l/HiyokoPDFVault
X → @hiyoyok

Top comments (0)