Saturday, July 2, 2022

#1 2022-06-05 06:53:18 am

Stadler
Member
Registered: 2008-07-09
Posts: 13

separate images into folder horizontally and vertically?

Hi,
I've used this script before without issues (Prior to macOS Catalina), now I am getting " error "Can’t get dimensions of missing value." number -1728 from «class dmns» of missing value "
How can this be corrected?

Thanks for your time and experience


tell application "Finder"
    set theFolder to choose folder
    if not (exists folder "Portrait" in folder theFolder) then
        make new folder in folder theFolder with properties {name:"Portrait"}
    end if
    if not (exists folder "Landscape" in folder theFolder) then
        make new folder in folder theFolder with properties {name:"Landscape"}
    end if
    set fileList to document files of theFolder
end tell
tell application "Image Events"
    launch
   
    repeat with theFile in fileList
        set theImage to open theFile as alias
        copy the dimensions of theImage to {Horiz, Vert}
        close theImage
        if Horiz is greater than Vert then
            -- landscape
            tell application "Finder"
                move theFile to folder "Landscape" of folder theFolder
            end tell
        else
            -- portrait
            tell application "Finder"
                move theFile to folder "Portrait" of folder theFolder
            end tell
        end if
    end repeat
end tell

Offline

 

#2 2022-06-05 07:47:57 am

peavine
Member
From:: Prescott, Arizona
Registered: 2018-09-04
Posts: 1369

Re: separate images into folder horizontally and vertically?

I've included my suggestion below. I tested the script on Monterey and it worked as expected.

Applescript:

set theExtensions to {"png", "tiff"} -- edit as desired but digital photos may not sort correctly
set theFolder to (choose folder) as text
set landscapeFolder to (theFolder & "Landscape:")
set portraitFolder to (theFolder & "Portrait:")

tell application "Finder"
   if not (exists folder portraitFolder) then make new folder in folder theFolder with properties {name:"Portrait"}
   if not (exists folder landscapeFolder) then make new folder in folder theFolder with properties {name:"Landscape"}
   set fileList to (every file in folder theFolder whose name extension is in theExtensions) as alias list
end tell

tell application "Image Events"
   launch
   repeat with theFile in fileList
       set theImage to open theFile
       set {Horiz, Vert} to dimensions of theImage
       close theImage
       if Horiz is greater than Vert then
           my moveFile(theFile, landscapeFolder)
       else
           my moveFile(theFile, portraitFolder)
       end if
   end repeat
end tell

on moveFile(theFile, theFolder)
   try
       tell application "Finder" to move theFile to folder theFolder
   on error
       tell application "Finder" to set fileName to name of theFile
       display alert "A file already exists in the target folder" message fileName buttons {"Skip"}
   end try
end moveFile

Last edited by peavine (2022-06-06 10:06:57 am)


2018 Mac mini - macOS Monterey - Script Debugger 8

Offline

 

#3 2022-06-15 02:49:45 pm

Stadler
Member
Registered: 2008-07-09
Posts: 13

Re: separate images into folder horizontally and vertically?

SAAWEEET!  Thank you soooo much!!  You saved my hide!

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)