Created
April 28, 2022 09:49
-
-
Save nomagick/8a91ebc255bd6840b9d35d3909caf58f to your computer and use it in GitHub Desktop.
Jxa sudo for electron
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { run } from '@jxa/run'; | |
declare const Application: any; | |
export async function jxaRun<T>(func: Function, ...args: any[]) { | |
func.toString = () => { | |
return Function.prototype.toString.call(func).replace(/^\((.*?)\)\s*=>/g, 'function ($1)'); | |
}; | |
return run<T>(func as any, ...args); | |
} | |
export async function jxaSudo(command: string, prompt?: string) { | |
return jxaRun((command: string, prompt: string) => { | |
const app = Application.currentApplication(); | |
app.includeStandardAdditions = true; | |
return app.doShellScript(command, { | |
administratorPrivileges: true, | |
withPrompt: prompt || '执行一次性命令' | |
}); | |
}, command, prompt); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment