2

I'm running macOS 10.13.5, and I want the Mac to say something, such as the current time, with the at command for the specified time.

I have already loaded the atrun daemon, and the following command is working:

at now + 1 minute
echo "blah" > /tmp/test.txt

But when I use a say command with the at command, it does nothing:

at now + 1 minute
say 'hello'

I would like to know what happened. Is there a log or something I can do to find out?

Giacomo1968
  • 53,069
  • 19
  • 162
  • 212
Holmes Conan
  • 121
  • 2
  • I have become a tad more obsessed with this issue than I should be. Something about either `say` not working without direct interaction to standard output or the `at` command not working similarly. – Giacomo1968 Jul 15 '18 at 04:43
  • 2
    @JakeGould I think it's more likely to do with the `say` command not being part of the user's login session (specifically its Mach bootstrap context). The `atrun` daemon runs as root, and runs the command (e.g. `say`) under the appropriate user ID, but without switching context, and thus doesn't have access to the speakers. This is all quite badly documented, but there's some info [here](https://derflounder.wordpress.com/2016/03/25/running-processes-in-os-x-as-the-logged-in-user-from-outside-the-users-account/). – Gordon Davisson Jul 15 '18 at 08:33
  • @GordonDavisson I have tried with launchctl asuser $(id -u username) /usr/bin/say hello as the task to run, still not working. – Holmes Conan Jul 15 '18 at 12:00
  • I have tried to write a plist file which use WatchPaths to start. What I expected is when I write some text to /tmp/say.txt, the lauchd will run `say -f /tmp/say.txt`, but it failed. – Holmes Conan Jul 15 '18 at 13:17
  • What is strange that when run cron job, one can wrap `say` in a .sh file and everything works. But I tried this with `at` command, failed. – Holmes Conan Jul 15 '18 at 13:18
  • @holmescn As a cron job, the `say` command would still be running as your user. Where—as Gordon Davisson explains—the `atrun` command runs as `root`. – Giacomo1968 Jul 15 '18 at 14:59

0 Answers0