I set up a launchd plist to run a shell script every morning at 8 AM

(see Is there an easy way to automatically schedule a move of files matching a certain pattern from a user directory to a USB drive? for context).

Yesterday, I created the plist, put it in /Library/LaunchDaemons, and did a did a launchctl load /Library/LaunchDaemons/sweep.plist (either sudo'd or in a sudo bash) once it was in place.

BUT IT DIDN'T WORK! It's called "sweep.plist," and it is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">

I'm absolutely certain that after I did the launchctl load yesterday, "sweep" showed up in a launchctl list, but my shell script didn't execute, and the daemon no longer shows up when I do a launchctl list.

New: I checked the system log, and sure enough, there was an error message. Not sure what to do about it: May 10 08:00:05 Europas-Mac-mini com.apple.xpc.launchd[1] (sweep[1299]): Program specified by service is not a Mach-O executable file.

Looking at the shell script with a ls -l, it shows permissions as -rwxr-xr-x@

Any idea what I could have done wrong, or where to look for the problem?

  • I believe the calendar intervals need to be in an array. See this answer for more details.
    – Allan
    May 10, 2023 at 21:44
  • Really? Then why would it say "Program . . . is not a Mach-0 executable file"? May 11, 2023 at 15:17
  • Dd you test out your script to ensure it works?
    – Allan
    May 11, 2023 at 15:26
  • Ran it from a SUDO BASH'd command line before I'd even attempted to make it run on a schedule. Before I'd even settled on launchd to schedule it. May 11, 2023 at 15:56

1 Answer 1


See: https://stackoverflow.com/a/39062525/3654526

It seems that a generic shebang (#!) is fine if you're calling the script from a command line, but not from launchd. It needs to specify a shell in the shebang, i.e., #!/bin/bash.

  • 1
    A "generic shebang" is not valid. Some things (like bash) may ignore it, but it's not something you should ever actually use. The purpose of a shebang line is to specify the interpreter to use on the file, and #! does not do that. May 12, 2023 at 5:33
  • Point taken. Although I'd always understood that it identifies the file as a shell script, albeit without, as you point out, saying anything about what shell to use. And launchd wouldn't already be in a shell, so . . . . May 12, 2023 at 15:32
  • 1
    It doesn't identify it as a shell script, but as a script of some kind -- could be shell, perl (#!/usr/bin/perl), awk (#!/usr/bin/awk -f), expect (#!/usr/bin/expect), etc. Some things (like bash) will assume it's a shell script, but they'll generally do the same thing if it doesn't have a shebang at all. May 12, 2023 at 16:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .