Automatically scan for new photos quickly without scanning entire library

I wrote a small bash script to help me import my newest photos uploaded from my phone to my home server using the PhotoSync app for Android. The intention is to only sync the newest photos to bring them in to PhotoStructure quickly without having to sync my whole library. It was written for Photostructure for Node running on Windows in mind however it can easily be adapted to linux or docker/Unraid (using User Scripts plugin).

I store my photos with a YYYY/MM directory structure so my newest pictures will always be in a Current_Year/Current-Month folder with single digit months padded with a leading 0. PhotoSync supports this type of organization easily so my newest photos will always be in the Current Year YYYY, Current Month, MM directory. Obviously this script would need to be changed for different organization schemes and environments.

The script on Windows is as follows:

#!/bin/bash 

current_year=$(date +"%Y")
current_month=$(date +"%m")
cd /path/to/photostructure/photostructure-for-servers
./photostructure sync  /path/to/photos/$current_year/$current_month

On Windows I use task scheduler as follows to execute this script every 30 minutes.

These are my settings for Task Scheduler:



I keep my Photostructure install in c:\Photostructure\photostructure-for-servers and my script is called sync.sh and is located in c:\Photostructure


I also use Directory Opus which is an excellent highly customizable file manager with the ability to create custom buttons that can run any script or executable imaginable. These buttons can also exist on a toolbar that is always accessible like the Windows taskbar, it can float outside of the main program window and can function much like a highly customizable dock. I invoke mine with a simple keystroke. Using this I created a button that manually calls this script just using a simple batch file to execute the bash script silently. The command for that is:

@runmode:hide //an internal Directory Opus Command that prevents the Command Prompt window from appearing, not relevant when not used with Directory Opus
cd c:\photostructure
"C:\Program Files\Git\bin\sh.exe" -c /c/photostructure/sync.sh

On Unraid using the User Scripts plugin the script can be modified as such:

#!/bin/bash
current_year=$(date +"%Y")
current_month=$(date +"%m")
docker exec -u node PhotoStructure  ./photostructure sync /path/to/photos/$current_year/$current_month

Then it can be executed on a schedule using a cronjob. I haven’t fully tested this on Unraid so YMMV but it should work.