Monday, January 22, 2018

#1 2014-08-09 10:46:10 pm

sskim
Member
Registered: 2011-03-21
Posts: 2

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

Offline

 

#2 2014-08-10 12:27:42 pm

kel1
Member
Registered: 2013-01-11
Posts: 2188

Re: remove portrait images in current folder in finder

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


Os 10.10.3
Mbp

Offline

 

#3 2014-08-10 03:32:41 pm

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 4488

Re: remove portrait images in current folder in finder

Hi sskim.

Welcome to MacScripter and thanks for posting your script!

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


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:

Applescript:

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:

Applescript:

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.  smile

Last edited by Nigel Garvey (2014-08-10 03:37:08 pm)


NG

Offline

 

#4 2014-08-13 06:38:19 pm

sskim
Member
Registered: 2011-03-21
Posts: 2

Re: remove portrait images in current folder in finder

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 ?

Applescript:


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


Filed under: applescript, image, landscape

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)