基于方向过滤图像 applescript 无法正确响应

Filter Images Based on Orientation applescript doesnt respond correctly

我正在做一个项目,我每天必须在 2 个文件夹(横向和纵向)中制作大量照片。我找到了这个 applescript

global logFolder, logFilename 
global landscapeFolderPath, portraitFolderPath 
global landscapeFolder, portraitFolder 
 
-- folder action entry 
on adding folder items to sourceFolder after receiving itemList 
 
    -- set log folder 
    set sourceFilename to my FilenameFromPath(sourceFolder) 
    set sourceBasename to my ExtensionFromFilename(sourceFilename) 
    set logFilename to (sourceBasename & ".log") as text 
    set logFolder to sourceFolder 
 
    -- calculate default destination folder paths 
    set sourceFolderPath to (the POSIX path of (sourceFolder)) as text 
    set landscapeFolderPath to (sourceFolderPath & "Landscape/") as text 
    set landscapeFolder to (POSIX file landscapeFolderPath) 
    set portraitFolderPath to (sourceFolderPath & "Portrait/") as text 
    set portraitFolder to (POSIX file portraitFolderPath) 
 
    -- create destination folders if needed 
    my MakeDirectory(landscapeFolderPath) 
    my MakeDirectory(portraitFolderPath) 
 
    -- process received folders 
    repeat with nextItem in itemList 
        my ProcessFile(nextItem) 
    end repeat 
end adding folder items to 
 
on ProcessFile(nextItem) 
    -- coerce to alias 
    set nextFile to nextItem as alias 
 
    -- get file name and type 
    tell application "Finder" 
        set nextFilename to (the name of nextFile) as text 
        set nextFiletype to (the kind of nextFile) as text 
    end tell 
 
    -- get POSIX path 
    set nextFilePath to (nextFile's POSIX path) as text 
 
    -- process only image files 
    if nextFiletype ends with "image" then 
 
        -- read image data 
        tell application "Image Events" 
            set imageData to open nextFile 
            set imageDimensions to dimensions of imageData 
            close imageData 
        end tell 
 
        -- get image dimensions 
        set imageWidth to item 1 of imageDimensions as integer 
        set imageHeight to item 2 of imageDimensions as integer 
 
        -- determine image orientation 
        if imageWidth is greater than imageHeight then 
 
            -- this image uses landscape orientation 
            my LogEntry("Moving " & the quoted form of nextFilename & " to: " & the quoted form of my FilenameFromPath(the POSIX path of landscapeFolder, false) as text) 
            tell application "Finder" to move nextFile to landscapeFolder 
        else 
 
            -- this image uses portrait orientation 
            my LogEntry("Moving " & the quoted form of nextFilename & " to: " & the quoted form of my FilenameFromPath(the POSIX path of portraitFolder, false) as text) 
            tell application "Finder" to move nextFile to portraitFolder 
        end if 
    end if 
end ProcessFile 
 
on MakeDirectory(directoryPath) 
    do shell script ("mkdir -p " & the quoted form of directoryPath as text) as text 
end MakeDirectory 
 
on ExtensionFromFilename(filename) 
    set saveDelims to AppleScript's text item delimiters 
    set AppleScript's text item delimiters to {"."} 
    set itemList to (every text item of filename) 
    set AppleScript's text item delimiters to saveDelims 
    set justTheExtension to itemList's last item 
end ExtensionFromFilename 
 
on FilenameFromPath(somePath) 
    set somePath to somePath as text 
    -- determine path type & delimiter 
    if somePath contains ":" then 
        set delim to ":" 
    else if somePath contains "/" then 
        set delim to "/" 
    else 
        return ("ERROR in FilenameFromPath - could not determine delimiter from " & somePath) as text 
    end if 
    -- split it 
    set oldDelimiters to AppleScript's text item delimiters 
    set AppleScript's text item delimiters to delim 
    set pathAsList to text items of (somePath as text) 
    if the last character of (somePath as text) is delim then 
        set idx to -2 
    else 
        set idx to -1 
    end if 
    set filename to item idx of pathAsList 
    set AppleScript's text item delimiters to oldDelimiters 
    return filename 
end FilenameFromPath 
 
on FormatDateTime(theDate) 
    set theDate to theDate as date 
    set dd to text -2 thru -1 of ("0" & theDate's day) 
    copy theDate to tempDate 
    set the month of tempDate to January 
    set mm to text -2 thru -1 of ¬ 
        ("0" & 1 + (theDate - tempDate + 1314864) div 2629728) 
    set yy to text -1 thru -4 of ((year of theDate) as text) 
    set tt to time string of theDate 
    return (yy & "-" & mm & "-" & dd & " " & tt as text) 
end FormatDateTime 
 
on LogEntry(someText) 
    global logFolder, logFilename 
    try 
        set logFile to (logFolder as text) & logFilename 
        set logRef to open for access (file logFile) with write permission 
        if logRef ≠ 0 then 
            write FormatDateTime(current date) & ": " & someText & return starting at eof to logRef 
            close access logRef 
        end if 
    on error errorMessage number errorNumber 
        tell application "System Events" to display alert "Could not add log entry" message "ERROR: " & errorMessage & " (" & errorNumber & ")" 
    end try 
end LogEntry 

从这里开始

https://www.quora.com/Can-I-create-an-automator-folder-action-that-move-images-to-two-different-folders-whether-theyre-in-landscape-or-portrait-size

我正面临这个问题

https://youtube.com/shorts/PrtIcOGM7w0

似乎脚本在复制结束之前就开始了。我不熟悉 applescript,所以欢迎任何帮助

尝试在监视文件夹之外创建目标文件夹。

感谢您的建议,但如果不涉及复制,问题已解决,只需移动到 watched 文件夹,已经创建的 Landscape 和 Portrait 文件夹效果很好