I have a photos.sh file (osascript
set to JavaScript
):
#!/usr/bin/osascript -l JavaScript
function run(argv) {
return importFileIntoPhotos(argv[0])
};
// importFileIntoPhotos :: FilePath -> IO ()
const importFileIntoPhotos = fp => {
const
appPhotos = Application("Photos");
return appPhotos.import([Path(fp)])
};
and, the following test.sh file:
#!/bin/zsh
fp="$HOME/Documents/Samsung T5"
fpScript="$HOME/Library/CloudStorage/Dropbox/VSC Files/Automation/Manuel/photos.sh"
fswatch -0 -event-flags -r --exclude=".*\.DS_Store" "$fp" | xargs -0 -n1 -r -I {} "$fpScript" "{}"
I execute test.sh
in Terminal. With that process open, whenever I move a single photo into fp folder, the same photo is imported multiple times into Photos
app. Then, I have to kill the process.
How can I fix this issue, and import a single photo corresponding to a single move operation ?
Specs:
MacBook Air M1 with macOS Ventura
UPDATE:
Upon further testing, I have more clarity about the issue. Whenever the file is imported into Photos, a new event is sent (and captured) by fswatch
, so it gets triggered again.
UPDATE 2:
Now, the act of importing into Photos doesn't trigger an event that could be captured by fswatch
, and also doesn't trigger duplicated events. Not sure what happened.
UPDATE 3:
The issue persists. I tried opening the file in Preview app and the same is happening again. I get duplicated events. I am not sure why the act of opening that file in Preview is detected by fswatch
.