from NSWorkspace.h
(void)setDefaultApplicationAtURL:(NSURL *)applicationURL toOpenContentTypeOfFileAtURL:(NSURL *)url completionHandler:(void (^_Nullable)(NSError *_Nullable error))completionHandler API_AVAILABLE(macos(12.0));
before macOS 12, use LSSetDefaultRoleHandlerForContentType from LSInfo.h in the LaunchServices framework.
No idea how to do this with AppleScript. You could use Automator to make a Folder Action for any file matching a pattern in a particular directory. You'd probably want to put a Set Application for Files action after a Filter Finder Items action.
Topic:
App & System Services
SubTopic:
Core OS
Tags: