I wrote a small script to sync one folder to another as a Javascript for Automation script.

If I run it directly from terminal:

$ osascript -l JavaScript myscript.js

then it works as supposed - the referenced shell script is run, and then a dialog popup with the output of the shell script is shown, and then the notification is shown in the top right corner.

Now, I need this script to have full disk access to run it via launchd. For that, I compile the script into an application:

osacompile -l JavaScript -o myapp.app myscript.js

Now, if I run the resultant app:

open myapp.app

everything works (the app requests access to external volume, as should be), but unfortunately, the notification is not shown in the top right corner. It seems like macOS does not register the app for shown notifications (it does not appear in the notifications pane in System preferences).

How can I solve this bug with notifications? Thank you!

The myscript.js content:

const app = Application.currentApplication();
app.includeStandardAdditions = true;

console.log("Start sync-archive");
const home = app.systemAttribute("HOME");
const script = home + "/.launchd/sync-archive/sync-archive.sh";
const res = app.doShellScript("zsh " + script);

if (res.includes("success")) {
  app.displayNotification("completed successfully", {
    withTitle: "sync-archive",
  console.log("Finish sync-archive: success");
} else {
  app.displayAlert("sync-archive failed", {
    message: "Please see " + script + " and logfiles",
    as: "warning",
  console.log("Finish sync-archive: failure");
  • I'm fairly sure you don't need to compile it into an .app. launchd should be able to execute it by way of osascript, and you can give osascript full disk access if it needs it. But seeing as the only thing your .js. script does is execute a shell script, a better option would be to have launchd execute that instead, after which the result can be displayed however you wish, either by way of a shell script, a JXA script, or an inline call to osascript.
    – CJK
    Dec 10, 2022 at 10:41
  • @CJK, the problem is, if I start a shell script directly under launchd, it does not have "Full Disk Access", that is, cannot read external volumes. Giving the access to zsh is considered a security risk. It was an unpleasant surprise for me, as I thought before that launchd is simply like cron. However, it is not. And only by compiling an app and giving the app the access, I can run the task successfully. Dec 13, 2022 at 21:37


You must log in to answer this question.