Applescript in Finder: move to the next file

What I'm trying to do is:

set x to the current selection, then move the selection to the next file, and then delete x.

I do this because CMD-backspace clears the selection every time and it is annoying!

+3
source share
2 answers

I am a bit confused. When you say "next file", do you mean the next file in the list or the next file in the entire folder? I will give both of you.

The choice

tell application "Finder"
    set x to (get the selection) as list
    repeat with i from 1 to the count of x
        set this_item to item i of x
        delete this_item
    end repeat
end tell

Whole folder

tell application "Finder"
    set these_windows to (get every window) as list
    if these_windows is {} then --no windows are open, refer to the desktop
        set these_items to (get every item of desktop) as list
        repeat with i from 1 to the count of these_items
            set this_item to item i of these_items
            delete this_item
        end repeat
    else --a window is open 
        set this_folder to the target of window 1
        set these_items to the (entire contents of this_folder) as list
        repeat with i from 1 to the count of these_items
            set this_item to item i of these_items
            delete this_item
        end repeat
    end if
end tell
+1
source

You can tell system events about script keys, for example, press the down arrow and then delete with Command ⌘+delete

0
source

Source: https://habr.com/ru/post/1711885/


All Articles