cron script can't see files in Desktop

cron script can't see files in Desktop

It appears that my script, when run via cron, does not see the contents of my Desktop:

~/Code/scripts/problem.sh:

echo hello
cd ~/Desktop
echo $(pwd)
ls
echo hello2

Output when I run bash problem.sh from inside ~/Code/scripts:

hello
/Users/alfordsimon/Desktop
calendar.png
*more desktop files
hello2

crontab file:

* * * * * bash ~/Code/scripts/problem.sh >> ~/Code/scripts/problem.out

problem.out contents confirms that the script is running, but for some reason the Desktop files aren't showing:

hello
/Users/alfordsimon/Desktop
hello2

I haven't bothered trying to see if this issue is present for other directories. I'm trying to have a script automatically move my Screenshot files from Desktop to ~/Documents/screenshots every day (for testing purposes, the script currently runs every minute). What's going on? This is on my macbook—do I have to give my script permission to view Desktop files or something?

相关内容