Skip to content

Commit 1e0ce92

Browse files
committed
fix: re-run applescript control prefs step, don't use applescript vo control when might not yet be enabled
1 parent 7f1696b commit 1e0ce92

4 files changed

Lines changed: 20 additions & 16 deletions

File tree

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@guidepup/setup",
3-
"version": "0.24.0-alpha.6",
3+
"version": "0.24.0-alpha.7",
44
"description": "CLI for configuring environments and install screen reader assets for Guidepup.",
55
"main": "lib/index.js",
66
"typings": "lib/index.d.ts",

‎src/commands/setup/macOS/ensureLocalPreferencesExist.ts‎

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { execFileSync, spawn } from "node:child_process";
1+
import { execFileSync, execSync } from "node:child_process";
22
import { existsSync } from "node:fs";
33
import { homedir } from "node:os";
44
import { join } from "node:path";
@@ -28,18 +28,19 @@ function getPreferencesDirectory(): string {
2828
return join(homedir(), "Library", "Preferences");
2929
}
3030

31-
function startVoiceOver(): void {
32-
spawn(
33-
"/System/Library/CoreServices/VoiceOver.app/Contents/MacOS/VoiceOverStarter",
34-
[],
35-
{ detached: true, stdio: "ignore" },
36-
).unref();
31+
async function startVoiceOver(): Promise<void> {
32+
execSync(
33+
"/System/Library/CoreServices/VoiceOver.app/Contents/MacOS/VoiceOverStarter &",
34+
{ stdio: "ignore", timeout: 2000 },
35+
);
36+
37+
await new Promise((resolve) => setTimeout(resolve, 1000));
3738
}
3839

3940
function isRunning(): boolean {
4041
try {
4142
return (
42-
execFileSync("pgrep", ["-f", "VoiceOver"], {
43+
execFileSync("pgrep", ["-f", "VoiceOver launchd -s"], {
4344
encoding: "utf8",
4445
timeout: 2000,
4546
}).length > 0
@@ -50,10 +51,8 @@ function isRunning(): boolean {
5051
}
5152

5253
const stopVoiceOverApplescript = `
53-
tell application "VoiceOver"
54-
with transaction
55-
quit
56-
end transaction
54+
tell application "System Events"
55+
key code 96 using {command down}
5756
end tell`;
5857

5958
async function stopVoiceOver(): Promise<void> {
@@ -63,6 +62,8 @@ async function stopVoiceOver(): Promise<void> {
6362
// Swallow
6463
}
6564

65+
await new Promise((resolve) => setTimeout(resolve, 1000));
66+
6667
try {
6768
execFileSync(
6869
"pkill",
@@ -76,6 +77,8 @@ async function stopVoiceOver(): Promise<void> {
7677
// Swallow
7778
}
7879

80+
await new Promise((resolve) => setTimeout(resolve, 1000));
81+
7982
if (isRunning()) {
8083
throw new Error(ERR_SETUP_MACOS_UNABLE_TO_STOP_VOICEOVER);
8184
}
@@ -99,7 +102,7 @@ export async function ensureLocalPreferencesExist(): Promise<void> {
99102
return;
100103
}
101104

102-
startVoiceOver();
105+
await startVoiceOver();
103106

104107
await retryOnError(
105108
() => {
@@ -115,5 +118,5 @@ export async function ensureLocalPreferencesExist(): Promise<void> {
115118
delay: 100,
116119
});
117120

118-
await retryOnError(() => stopVoiceOver(), { retries: 10, delay: 200 });
121+
await retryOnError(() => stopVoiceOver(), { retries: 10, delay: 100 });
119122
}

‎src/commands/setup/macOS/runAppleScript.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ end doWithTimeout
3737
[],
3838
{
3939
maxBuffer: DEFAULT_MAX_BUFFER,
40-
timeout: timeout + 2000,
4140
},
4241
(error, stdout) => {
4342
if (error) {

‎src/commands/setup/macOS/setup.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ export async function setup({
7070
enableAppleScriptControlSystemDefaults();
7171
disableSplashScreenSystemDefaults();
7272
disableDictationInputAutoEnable();
73+
7374
await ensureLocalPreferencesExist();
75+
enableAppleScriptControlSystemDefaults();
7476

7577
if (ci) {
7678
await enableDoNotDisturb();

0 commit comments

Comments
 (0)