0

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.

F. Zer
  • 1,081
  • 7
  • 9
  • If you're unable to get `fswatch` to work, you may be able to do this with a macOS [Folder Action](https://developer.apple.com/library/archive/documentation/AppleScript/Conceptual/AppleScriptLangGuide/reference/ASLR_folder_actions.html). – Gairfowl Jun 01 '23 at 04:20
  • Thank you, @Gairfowl. Unfortunately, macOS Folder Action doesn't observe subfolders. – F. Zer Jun 01 '23 at 12:08
  • Your updated testing note indicates that the Photos app may be altering the metadata of a file after importing it, thus triggering the new event. Possible workarounds: turn on 'delete after import' in Photos, or have your script move or rename the file to a location ignored by `fswatch` prior to importing it. – Gairfowl Jun 02 '23 at 07:50
  • Thank you, @Gairflow. I am not sure what happened, 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. – F. Zer Jun 02 '23 at 17:19
  • The issue persists. I have tried with Preview app and the same is happening again. I get duplicated events. – F. Zer Jun 05 '23 at 22:18
  • 1
    @Gairfowl, you were right. After all, I found the event captured by `fswatch`. Whenever I open a file in Preview, for example, one of the events captured is named `AttributeModified`. – F. Zer Jun 05 '23 at 23:07
  • In particular, "Date Last Opened" attribute. – F. Zer Jun 05 '23 at 23:09

0 Answers0