• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Restoring the Finder Selection After Moving an Item or Items.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Restoring the Finder Selection After Moving an Item or Items.


  • Subject: Restoring the Finder Selection After Moving an Item or Items.
  • From: Christopher Stone <email@hidden>
  • Date: Sun, 26 Feb 2017 22:51:48 -0600

Hey Folks,

One very irritating thing about the Finder is how readily it loses your place.

It took Apple a very long time to fix this relative to delete, and my bugging them about it regularly for years may or may not have contributed to the fix.

Unfortunately they didn't think to fix the problem relative to moving files when they corrected the selection-on-delete issue – or perhaps they consider this a layer of protecting users from themselves.

I've tried several times to work around the problem with AppleScript – the last time with System Events and GUI-Scripting.

A request came through on the Keyboard Maestro forum for a macro to perform this very chore, so I had another crack at it this evening – and by gum I got it working.  Its not pretty, but it's very quick.

------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2017/02/26 21:26
# dMod: 2017/02/26 22:10
# Appl: Finder
# Task: Move selected items to a designated folder and SELECT next available item if possible.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Finder, @Move, @Selected, @Items, @Designated, @Folder
------------------------------------------------------------------------------
(*
NOTES:

#### The target folder MUST be sorted by NAME for select-next-item to work properly. ####

*)
------------------------------------------------------------------------------

# Alias -- User Setting
set destinationFolder to alias ((path to home folder as text) & "test_directory:Destination_Directory:")

------------------------------------------------------------------------------
# HFS Path String
set destinationFolderPath to destinationFolder as text

tell application "Finder"
    set winTarget to insertion location as alias
    set finderSelectionList to selection as alias list

    

    if finderSelectionList = {} then
        beep
        return
    end if

    

    set winTargetItemNameList to list folder winTarget without invisibles
    set itemName to name of (last item of finderSelectionList)
    set AppleScript's text item delimiters to itemName
    move finderSelectionList to destinationFolder
    delay 0.05
    set AppleScript's text item delimiters to linefeed
    set winTargetItemNameList to winTargetItemNameList as text
    set AppleScript's text item delimiters to itemName
    set winTargetItemNameList to text items of winTargetItemNameList

    

    if length of winTargetItemNameList = 2 then

        

        try

            

            set winTargetItemNameList to item 2 of winTargetItemNameList
            repeat while character 1 of winTargetItemNameList is linefeed
                set winTargetItemNameList to text 2 thru -1 of winTargetItemNameList
            end repeat
            set itemName to paragraph 1 of winTargetItemNameList
            set selectItemPath to ((winTarget as text) & (paragraph 1 of winTargetItemNameList)) as alias
            tell front window to select selectItemPath

            

        end try

        

    end if

    

end tell

------------------------------------------------------------------------------

I don't want to hear any static about List Folder being a deprecated method.  It's very fast, and that's why I chose to use it.

If you can actually improve upon the script I'm quite interested.

If there are AppleScriptObjC methods that are superior I'm quite interested.

Enjoy.

--
Best Regards,
Chris

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Restoring the Finder Selection After Moving an Item or Items.
      • From: Shane Stanley <email@hidden>
  • Prev by Date: Re: Opening Scripts from the Web
  • Next by Date: Filter Out Files by Extension
  • Previous by thread: Re: Opening Scripts from the Web
  • Next by thread: Re: Restoring the Finder Selection After Moving an Item or Items.
  • Index(es):
    • Date
    • Thread