Created
May 9, 2024 00:53
-
-
Save boraseoksoon/64897b17735552195e72992f97d647ad to your computer and use it in GitHub Desktop.
open safari
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
// openSafari.js; | |
/** | |
* Function to open Safari browser on macOS using AppleScript | |
*/ | |
async function openSafari() { | |
// Create the AppleScript command to activate Safari | |
const command = `osascript -e 'tell application "Safari" to activate'`; | |
// Run the command via bash in a subprocess | |
const process = Deno.run({ | |
cmd: ["bash", "-c", command], | |
stdout: "piped", | |
stderr: "piped", | |
}); | |
// Await the subprocess result | |
const { code } = await process.status(); | |
// If the subprocess succeeded | |
if (code === 0) { | |
const output = new TextDecoder().decode(await process.output()); | |
console.log("Safari opened successfully:", output); | |
} else { | |
const error = new TextDecoder().decode(await process.stderrOutput()); | |
console.error("Error opening Safari:", error); | |
} | |
// Close the process | |
process.close(); | |
} | |
// Export the openSafari function as the default export | |
export default openSafari; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment