Skip to content

Commit

Permalink
feat: separate permission checks for system defaults vs sandboxed def…
Browse files Browse the repository at this point in the history
…aults
  • Loading branch information
jlp-craigmorten committed Dec 31, 2024
1 parent d3175be commit 8d07788
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 16 deletions.
2 changes: 2 additions & 0 deletions src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export const ERR_MACOS_UNSUPPORTED_VERSION =
"Require macOS version 11 or later";
export const ERR_MACOS_UNABLE_UPDATE_SYSTEM_DEFAULTS =
"Unable to update system defaults";
export const ERR_MACOS_UNABLE_UPDATE_VOICE_OVER_SANDBOXED_DEFAULTS =
"Unable to update VoiceOver sandboxed defaults - SIP might not be disabled";
export const ERR_MACOS_UNABLE_TO_VERIFY_SIP =
"Unable to verify macOS SIP status";
export const ERR_MACOS_UNABLE_TO_WRITE_DATABASE_FILE =
Expand Down
26 changes: 26 additions & 0 deletions src/macOS/enableAppleScriptControlSandboxedDefaults.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { execSync } from "child_process";
import { getPlatformVersionMajor } from "./getPlatformVersionMajor";
import { ERR_MACOS_UNABLE_UPDATE_VOICE_OVER_SANDBOXED_DEFAULTS } from "../errors";

const VOICE_OVER_APPLESCRIPT_ENABLED_PLUTIL =
"plutil -replace SCREnableAppleScript -bool true ~/Library/Group\\ Containers/group.com.apple.VoiceOver/Library/Preferences/com.apple.VoiceOver4/default.plist";

export function enableAppleScriptControlSandboxedDefaults(): void {
const platformMajor = getPlatformVersionMajor();

// For MacOS 14 Sonoma (Darwin 23) and earlier VoiceOver preferences are set via system defaults.
if (platformMajor < 24) {
return;
}

// From MacOS 15 Sequoia (Darwin 24) VoiceOver preferences are sandboxed.
try {
execSync(VOICE_OVER_APPLESCRIPT_ENABLED_PLUTIL, { encoding: "utf8" });

return;
} catch (e) {
throw new Error(
`${ERR_MACOS_UNABLE_UPDATE_VOICE_OVER_SANDBOXED_DEFAULTS}\n\n${e.message}`
);
}
}
21 changes: 5 additions & 16 deletions src/macOS/enableAppleScriptControlSystemDefaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,17 @@ import { ERR_MACOS_UNABLE_UPDATE_SYSTEM_DEFAULTS } from "../errors";
const VOICE_OVER_APPLESCRIPT_ENABLED_DEFAULTS =
"defaults write com.apple.VoiceOver4/default SCREnableAppleScript -bool true";

const VOICE_OVER_APPLESCRIPT_ENABLED_PLUTIL =
"plutil -replace SCREnableAppleScript -bool true ~/Library/Group\\ Containers/group.com.apple.VoiceOver/Library/Preferences/com.apple.VoiceOver4/default.plist";

export function enableAppleScriptControlSystemDefaults(): void {
const platformMajor = getPlatformVersionMajor();

// For MacOS 14 Sonoma (Darwin 23) and earlier VoiceOver preferences are set via system defaults.
if (platformMajor < 24) {
try {
execSync(VOICE_OVER_APPLESCRIPT_ENABLED_DEFAULTS, { encoding: "utf8" });

return;
} catch (e) {
throw new Error(
`${ERR_MACOS_UNABLE_UPDATE_SYSTEM_DEFAULTS}\n\n${e.message}`
);
}
// From MacOS 15 Sequoia (Darwin 24) VoiceOver preferences are sandboxed.
if (platformMajor >= 24) {
return;
}

// From MacOS 15 Sequoia (Darwin 24) VoiceOver preferences are sandboxed.
// For MacOS 14 Sonoma (Darwin 23) and earlier VoiceOver preferences are set via system defaults.
try {
execSync(VOICE_OVER_APPLESCRIPT_ENABLED_PLUTIL, { encoding: "utf8" });
execSync(VOICE_OVER_APPLESCRIPT_ENABLED_DEFAULTS, { encoding: "utf8" });

return;
} catch (e) {
Expand Down
2 changes: 2 additions & 0 deletions src/macOS/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { macOSRecord } from "@guidepup/record";
import chalk from "chalk";
import { checkVersion } from "./checkVersion";
import { enableAppleScriptControlSystemDefaults } from "./enableAppleScriptControlSystemDefaults";
import { enableAppleScriptControlSandboxedDefaults } from "./enableAppleScriptControlSandboxedDefaults";
import { disableSplashScreenSystemDefaults } from "./disableSplashScreenSystemDefaults";
import { disableDictationInputAutoEnable } from "./disableDictationInputAutoEnable";
import { isSipEnabled } from "./isSipEnabled";
Expand Down Expand Up @@ -61,6 +62,7 @@ export async function setup(): Promise<void> {

if (!isSipEnabled() && !(await enabledDbFile())) {
writeDatabaseFile();
enableAppleScriptControlSandboxedDefaults();

return;
}
Expand Down

0 comments on commit 8d07788

Please sign in to comment.