auto-terminal-profile icon indicating copy to clipboard operation
auto-terminal-profile copied to clipboard

doesn’t work on macos sonoma

Open patrik-csak opened this issue 1 year ago • 2 comments

the applescript code that changes the terminal profile works when run in script editor, but when run via osascript it fails with this error:

execution error: Terminal got an error: AppleEvent handler failed. (-10000)

patrik-csak avatar Sep 04 '23 02:09 patrik-csak

/Users/spicicomic/Library/pnpm/global/5/.pnpm/[email protected]/node_modules/execa/lib/error.js:60
		error = new Error(message);
		        ^

Error: Command failed with exit code 1: osascript -e tell application "Terminal"
	set current settings of tabs of windows to settings set "Rose Pine Dawn"
end tell 
26:102: execution error: “Terminal”遇到一个错误:AppleEvent处理程序失败。 (-10000)
    at makeError (/Users/spicicomic/Library/pnpm/global/5/.pnpm/[email protected]/node_modules/execa/lib/error.js:60:11)
    at handlePromise (/Users/spicicomic/Library/pnpm/global/5/.pnpm/[email protected]/node_modules/execa/index.js:118:26)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async runAppleScript (file:///Users/spicicomic/Library/pnpm/global/5/.pnpm/[email protected]/node_modules/run-applescript/index.js:11:19)
    at async setTerminalProfile (file:///Users/spicicomic/Library/pnpm/global/5/.pnpm/[email protected]/node_modules/terminal-profile/index.js:8:2)
    at async Promise.all (index 0)
    at async Command.updateProfile (file:///Users/spicicomic/Library/pnpm/global/5/.pnpm/[email protected]/node_modules/auto-terminal-profile/actions/update-profile.js:17:2) {
  shortMessage: 'Command failed with exit code 1: osascript -e tell application "Terminal"\n' +
    '\tset current settings of tabs of windows to settings set "Rose Pine Dawn"\n' +
    'end tell ',
  command: 'osascript -e tell application "Terminal"\n' +
    '\tset current settings of tabs of windows to settings set "Rose Pine Dawn"\n' +
    'end tell ',
  escapedCommand: 'osascript -e "tell application \\"Terminal\\"\n' +
    '\tset current settings of tabs of windows to settings set \\"Rose Pine Dawn\\"\n' +
    'end tell" ',
  exitCode: 1,
  signal: undefined,
  signalDescription: undefined,
  stdout: '',
  stderr: '26:102: execution error: “Terminal”遇到一个错误:AppleEvent处理程序失败。 (-10000)',
  failed: true,
  timedOut: false,
  isCanceled: false,
  killed: false
}

Vikingama avatar Sep 19 '23 07:09 Vikingama

I found that the osascript version of the command works as long as you run it from outside Terminal.app - I used Alacritty for this. The first time I did so, I received a UI prompt to allow Alacritty to control Terminal, and then found that permission stored under Privacy and Security -> Automation.

When using the osascript command in Terminal.app, that UI prompt never appears, seemingly Terminal cannot directly control Terminal, which sounds like an OS bug to me.

What you can do however is invoke the other terminal app from Terminal.app, once you've given that other app the permission:

/Applications/Alacritty.app/Contents/MacOS/alacritty -e \
osascript -e "tell application \"Terminal\" to set current settings of tabs of windows to settings set \"PROFILE_NAME\""

So the trick to solving this is to presumably to figure out how to get either Terminal or the node script to request this needed Automation permission.

acmtd avatar Sep 26 '23 23:09 acmtd

fixed in f1789d6, which is published in v3.0.1

patrik-csak avatar Feb 20 '24 16:02 patrik-csak