remove portrait images in current folder in finder

I use a only a landscape(not portrait) type images for wallpapers.
So, I need a detect & collect landscape images from image packages…

I made a applescript for my need…

property originalFolder : missing value

on landscape(f)
tell application “Image Events” to tell (open f)
tell (get dimensions) to if (count) is 2 then
set v to item 1 > item 2
else
set v to missing value
end if
close
v
end tell
end landscape

if originalFolder is missing value then Echo launch Finder"

set landscapeList to {}
set portraitList to {}

launch application “Image Events”

tell application “Finder”
set originalFolder to (target of front Finder window)

repeat with f in (get document files of originalFolder)
	tell my landscape(f as Unicode text) to if it is true then
		set landscapeList's end to f
	else if it is false then
		set portraitList's end to f
	end if
end repeat

move portraitList to trash

end tell

Hi sskim,

I don’t have an answer, but is what you’re saying that if the width is greater than the height, then it’s a landscape image? Actually, Im not sure what the question is also.

gl,
kel

Hi sskim.

Welcome to MacScripter and thanks for posting your script!

If there are a lot of files in the folder, the Finder will take quite a while to assemble the list of its references to them. It would be much faster if the Finder were to return them as aliases:

tell application "Finder" to set theFiles to document files of target of front Finder window as alias list -- List of aliases.

-- The Finder's not used in the repeat.
repeat with f in theFiles
	tell landscape(f) to if it is true then
		set landscapeList's end to f
	else if it is false then
		set portraitList's end to f
	end if
end repeat

tell application "Finder" to move portraitList to trash

-- tell app "Image Events" to quit

Or, faster still, as text paths:

set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to linefeed
tell application "Finder" to set thePaths to (document files of target of front Finder window as text)'s text items -- List of paths.
set AppleScript's text item delimiters to astid

repeat with f in thePaths
	tell landscape(f) to if it is true then
		set landscapeList's end to f
	else if it is false then
		set portraitList's end to f
	end if
end repeat

tell application "Finder" to move portraitList to trash

-- tell app "Image Events" to quit

When posting to MacScripter forums, you can wrap script code between [applescript] and [/applescript] tags to make it appear as above: in a box with a clickable link which will open it in people’s default script editors.

Since the purpose of your post is to share a useful, working script rather than to ask for help getting it to work, I’ll see if I can get one of the administrators to move this thread to the Code Exchange forum. :slight_smile:

Thanks a lot for your kind advice

At last, I have a more fast action script for my purpose.
Can you help me more ?

This applescript are “OK” on Spark application (Hotkey manager…)
But I can’t transpose this to Alfred workflow
Can you Let me know why do not act in Alfred ?


on landscape(f)
	tell application "Image Events" to tell (open f)
		tell (get dimensions) to if (count) is 2 then
			set v to item 1 > item 2
		else
			set v to missing value
		end if
		close
		v
	end tell
end landscape

# if originalFolder is missing value then Echo launch Finder"

set landscapeList to {}
set portraitList to {}

launch application "Image Events"

tell application "Finder" to set theFiles to document files of target of front Finder window as alias list -- List of aliases.

-- The Finder's not used in the repeat.
repeat with f in theFiles
	tell landscape(f) to if it is true then
		set landscapeList's end to f
	else if it is false then
		set portraitList's end to f
	end if
end repeat

tell application "Finder" to move portraitList to trash

tell application "Image Events" to quit