Skip to content

Instantly share code, notes, and snippets.

@corbindavenport
Created July 24, 2021 00:29
Show Gist options
  • Save corbindavenport/3da222dd6261b54d7ae3bd954a843eca to your computer and use it in GitHub Desktop.
Save corbindavenport/3da222dd6261b54d7ae3bd954a843eca to your computer and use it in GitHub Desktop.
Check for MacOS Rosetta compatibility layer in Dart
// Function to verify Rosetta compatibility layer is enabled on ARM macOS
void checkRosetta() async {
var cpu = await getCPUArchitecture();
var rosettaInstalled = await io.Directory(
'/Library/Apple/System/Library/LaunchDaemons/com.apple.oahd.plist')
.exists();
if (io.Platform.isMacOS && (cpu == 'arm64')) {
if (rosettaInstalled) {
print('[ OK ] Rosetta compatibility layer is already installed.');
} else {
io.stdout.write(
'[WARN] Apple Rosetta compatibility layer must be installed. Continue? [Y/N] ');
var input = io.stdin.readLineSync();
if (input?.toLowerCase() != 'y') {
print('[ .. ] Please wait while Rosetta is installed...');
await io.Process.run('/usr/sbin/softwareupdate',
['---install-rosetta', '--agree-to-license']);
} else {
io.exit(1);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment