Last active
March 4, 2025 13:18
-
-
Save seozed/fcc74e8abc43a0fbbc71d836e4dea554 to your computer and use it in GitHub Desktop.
Auto Import Pictures Folder To Apple Photos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Author: zed | |
-- Refer from: https://apple.stackexchange.com/questions/312818/auto-sync-photos-app-with-local-folder | |
on adding folder items to thisFolder after receiving mediaFiles | |
do shell script "echo AppleScript triggered at $(date) >> /tmp/apple_script_debug.log" | |
set listOfMediaExtensions to {"jpeg", "jpg", "tiff", "tif", "png", "gif", "heic", "heif", "raw", "dng", "mov", "mp4", "mp4v", "m4v"} | |
set filteredFiles to {} | |
repeat with aFile in mediaFiles | |
set filePath to POSIX path of aFile | |
if filePath does not contain "Library.photoslibrary" then -- exclud Photos folder | |
try | |
set fileInfo to info for aFile | |
set fileExt to name extension of fileInfo | |
if fileExt is not missing value then | |
set fileExt to do shell script "echo " & quoted form of fileExt & " | tr '[:upper:]' '[:lower:]'" | |
if listOfMediaExtensions contains fileExt then | |
set end of filteredFiles to aFile | |
end if | |
end if | |
on error errMsg | |
do shell script "echo AppleScript error: " & quoted form of errMsg & " >> /tmp/apple_script_error.log" | |
end try | |
end if | |
end repeat | |
if (count of filteredFiles) > 0 then | |
tell application "Photos" | |
run | |
delay 2 | |
import filteredFiles | |
end tell | |
end if | |
end adding folder items to |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The script need to save to '/Library/Scripts/Folder Action Scripts'