RhetTbull / osxphotos

Python app to work with pictures and associated metadata from Apple Photos on macOS. Also includes a package to provide programmatic access to the Photos library, pictures, and metadata.
MIT License
2.18k stars 100 forks source link

Run on a Schedule #1084

Closed pablosed closed 1 year ago

pablosed commented 1 year ago

Is your feature request related to a problem? Please describe. Hi - I am attempting to backup my icloud photos to a local drive on a regular schedule. I have searched through your documentation but don't see any indication that there is an "official" way to do this. Describe the solution you'd like Add some mechanism to schedule this on a regular basis (either in time increments or at a given time)

Describe alternatives you've considered I have been attempting to get this configured using my limited understanding of shell scripts and cron. However I keep running up against permission errors. I think the issue is that when I try to run the "osxphotos" command in a bash script via a crontab it cant find it (despite my ensuring that the script is being run as the local user / testing running it with root.

here is a sanitised version of my script - which when run locally in terminal works perfectly (mounting an SMB share to copy the photos to):

#!/bin/bash

open 'smb://user:password@192.168.1.2/photobackup'

sleep 10

osxphotos export --export-by-date --update --download-missing --from-date "2023-01-01" /Volumes/photobackup

When I run it in with cron i get the following error:

/Users/photobackup/Documents/exportpics.sh: line 7: osxphotos: command not found

To me it is clear that is has something to do with osxphotos being python based and cron not having access to the libraries, but I am not clear on how to rectify. Or maybe there is another way entirely to get the desired result (running the command regularly to backup photos without interaction) - I have had similar issues with launchd btw.

Additional context I am fully aware that this request is not directly related to osxphotos. I am posting here instead of Stackexchange (which I might still do) etc because I am sure Im not the only one what would like to get this to run on a schedule and this might prove helpful for others if you have any ideas! thanks in advance.

RhetTbull commented 1 year ago

I've thought about having a feature for osxphotos to automatically create a launchd script to schedule an export. With macOS permissions, security & privacy settings, and each user's use case being different, this is not trivial to do.

See the thread at #1080 for instructions on how to do this with launchd which may work better for you. There's also an example of a working cron setup in that thread.

RhetTbull commented 1 year ago

Also, in general I recommend using full paths in scripts. For me, as I install osxphotos with pipx, osxphotos is in /Users/username/.local/bin/osxphotos

pablosed commented 1 year ago

amazing, thanks for your response and apologies for not being more thorough here - i didn't think to look in the discussions section for a solution. I will take a close look at the thread you mentioned! thanks again for the amazing piece of software and for your time - have been banging my head against the wall ever since I enabled Advanced Data Protection as the docker container I used to use stopped working - osxphotos has been a lifesaver!

RhetTbull commented 1 year ago

No apologies needed! When I have the time I'll work on a section for the docs that incorporates the lessons from that thread. I would like to make it as easy for the user to run osxphotos.