rsync errors, but only when run in launchd I have a script which runs rsync on my ~/Library/Preferences/ folder:

#!/bin/zsh -f

SOURCE="$HOME/Library/Preferences"

TARGET="$HOME/Dropbox/Backups/Preferences/$HOST"

LOG="$HOME/logs/$HOST/${NAME}.log"

[[ ! -d "$LOG:h" ]] &amp;&amp; mkdir -p "$LOG:h"

[[ ! -e "$LOG" ]] &amp;&amp; touch "$LOG"

/usr/bin/rsync \
    --8-bit-output \
    --human-readable \
    --itemize-changes \
    --progress \
    --safe-links \
    --links \
    --times \
    --delete \
    --recursive \
    --checksum \
    --verbose \
    --exclude='.DS_Store' \
    --log-file="$LOG" \
    "${SOURCE}/" \
    "${TARGET}/"

exit 0
#EOF



This script works with no errors from iTerm.

However, when I try to run it via launchd I consistently get errors about 3 files:


com.apple.homed.notbackedup.plist
com.apple.homed.plist
com.apple.mail-shared.plist


Here's an example:


building file list ...
511 files to consider
*deleting com.contextsformac.Contexts.plist.JkbicFf
.d..t.... ./
rsync: send_files failed to open "/Users/luomat/Library/Preferences/com.apple.homed.notbackedup.plist": Operation not permitted (1)
rsync: send_files failed to open "/Users/luomat/Library/Preferences/com.apple.homed.plist": Operation not permitted (1)
rsync: send_files failed to open "/Users/luomat/Library/Preferences/com.apple.mail-shared.plist": Operation not permitted (1)
&gt;fc.t.... com.contextsformac.Contexts.plist
       3.10K 100%    0.00kB/s    0:00:00 (xfer#4, to-check=249/511)
.f..t.... com.setapp.DesktopClient.plist
&gt;fcst.... test-ignore.txt
         203 100%  198.24kB/s    0:00:00 (xfer#5, to-check=75/511)

sent 31.63K bytes  received 142 bytes  63.55K bytes/sec
total size is 3.42M  speedup is 107.49
rsync error: some files could not be transferred (code 23) at /BuildRoot/Library/Caches/com.apple.xbs/Sources/rsync/rsync-52.200.1/rsync/main.c(996) [sender=2.6.9]



I assume this has something to do with Mojave's security because I have access to the files:


$ ls -l com.apple.homed.* com.apple.mail-shared.plist
-rw------- 1 luomat staff 184 Sep 12 00:43 com.apple.homed.notbackedup.plist
-rw------- 1 luomat staff 567 Sep 13 09:53 com.apple.homed.plist
-rw------- 1 luomat staff 225 Aug 18 23:44 com.apple.mail-shared.plist



What I have tried


I have given /usr/bin/rsync "Full Disk Access" in System Preferences
I have tried rsync from homebrew /usr/local/bin/rsync and given it "Full Disk Access"
I have given /sbin/launchd "Full Disk Access"


Now what?

Given that it does not give any errors when not in launchd what should I try now?
Your running in different contexts when you use launchd and iterm2. With iterm2 your profile gets run but your profile isn't run when you use launchd.

Some programmers invoke there profile from their launchd script. I do everything so it works without the need to run my profile.

I suggest you cd to whatever directory you ended up in iterm2.

I wrote a little function to display all my terminal settings.
Run this in iterm2 and launchd while sending output to a file and compare.

settings () 
{ 
    ( echo "---------- env ----------";
    env;
    echo "--------- set ----------";
    set;
    echo "--------- export ----------";
    export;
    echo "--------- export -f ----------";
    export -f;
    echo "--------- alias ----------";
    alias;
    echo "--------- set -o ----------";
    set -o;
    echo "--------- shopt ----------";
    shopt;
    echo "--------- enable -a ----------";
    enable -a ) | less
}


for terminal you can copy &amp; paste settings to terminal.

settings &gt;&gt;/Users/mac/xset
cat xset