Script to Change the Default Application for All .indd Files?

I’m looking for a way to programmatically change the default application for all .indd files on macOS.

Our environment has both Adobe InDesign 2026 and InDesign 2024 installed. I already have a script that can disable InDesign 2026, but if the user doesn’t first use Finder’s Get Info → Open with → Change All… option to associate .indd files with InDesign 2024, the default application ends up becoming InDesign Helper after 2026 is disabled.

To prevent that, I’d like to incorporate a step into my script that automatically changes the default application for all .indd files to InDesign 2024, effectively performing the equivalent of Finder’s Change All… action.

Has anyone done this before or know of a reliable AppleScript, shell command, or other macOS API that can change the default application for a file extension system-wide (or per user)?

Thanks,
-Jeff

Try this:

use framework "Foundation"
use framework "AppKit"
use scripting additions

-- make reference to the 2 versions of InDesign 
set indy2024 to (current application's NSURL's fileURLWithPath:"/Applications/Adobe InDesign 2024/Adobe InDesign 2024.app")
set indy2026 to (current application's NSURL's fileURLWithPath:"/Applications/Adobe InDesign 2026/Adobe InDesign 2026.app")

-- get content type for InDesign document
set thePath to current application's NSTemporaryDirectory()'s stringByAppendingString:("temp.indd")
current application's NSFileManager's defaultManager()'s createFileAtPath:thePath |contents|:(missing value) attributes:(missing value)
set theURL to current application's NSURL's fileURLWithPath:thePath
set {hasResult, theUTType} to theURL's getResourceValue:(reference) forKey:"NSURLContentTypeKey" |error|:(missing value)

-- toggle the default app
set theWorkspace to current application's NSWorkspace's sharedWorkspace()
set indyKey to theWorkspace's URLForApplicationToOpenContentType:theUTType
if indyKey's isEqualTo:indy2024 then set appURL to indy2026
if indyKey's isEqualTo:indy2026 then set appURL to indy2024
theWorkspace's setDefaultApplicationAtURL:appURL toOpenContentType:theUTType completionHandler:(missing value)

-- verification
delay 1
return theWorkspace's URLForApplicationToOpenURL:theURL