Help please - Need a simple "Move to Folder" macro

Hey Chris,

Yes.

When you move a file with a script or with Keyboard Maestro the selection is destroyed, and the system isn't smart enough to fix it.

This AppleScript will move the selected items (one or more) to the designated destination folder, and it will select the next available item in the working folder.

It's fast - even in a folder with a thousand items.

------------------------------------------------------------------------------
# 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:

#### 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

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

If you don't know how to create a proper alias for your destination folder then look at this:

Putting File Aliases On The Clipboard

Remember to use the Script Editor.app when testing AppleScripts before placing them in an Execute an AppleScript action.

-Chris