Change Directory in the Finder

Hey Bern,

Unfortunately that's pretty poor AppleScript. There's unused and unnecessary code.

Here it is all cleaned up:

--------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2021/01/25 14:26
# dMod: 2021/01/25 23:27
# Appl: Finder
# Task: Move Selected Items in the Finder to a Folder Chosen by the User.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Finder, @Move, @Selected, @Items
--------------------------------------------------------

tell application "Finder"
   set selectedItemList to the selection as alias list
   set destFolder to choose folder
   move selectedItemList to destFolder
end tell

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

-Chris

Hey Chris,

It's funny in that I have gone through probably at least six different versions of different scripts to do just this file selected Finder thing. There are several scattered around this forum. Most of them are way longer than this version that I found, and I was quite proud for having found it.

Now you come along and turn it into Applescript Haiku. And it works even faster than the version I had. Amazing, Artistry, Thank You!

@BernSh, I am surprised that you did not find a very simple KM Macro to do this, that does NOT require any scripting.
I think it should be just as fast as Chris' script, but let us know how it works for you.

Below is just an example written in response to your request. You will need to use as an example and/or change to meet your workflow automation needs.

Please let us know if it meets your needs.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

MACRO:   Move Files in Finder Selection to Chosen Folder [Example]

-~~~ VER: 1.0    2021-01-25 ~~~
Requires: KM 8.2.4+   macOS 10.11 (El Capitan)+
(Macro was written & tested using KM 9.0+ on macOS 10.14.5 (Mojave))

DOWNLOAD Macro File:

Move Files in Finder Selection to Chosen Folder [Example].kmmacros
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.


ReleaseNotes

Author.@JMichaelTX

PURPOSE:

  • Move Files in Finder Selection to Chosen Folder [Example]

NOTICE: This macro/script is just an Example

  • It is provided only for educational purposes, and may not be suitable for any specific purpose.
  • It has had very limited testing.
  • You need to test further before using in a production environment.
  • It does not have extensive error checking/handling.
  • It may not be complete. It is provided as an example to show you one approach to solving a problem.

REQUIRES:

  1. KM 8.0.2+
  • But it can be written in KM 7.3.1+
  • It is KM8 specific just because some of the Actions have changed to make things simpler, but equivalent Actions are available in KM 7.3.1.
    .
  1. macOS 10.11.6 (El Capitan)
  • KM 8 Requires Yosemite or later, so this macro will probably run on Yosemite, but I make no guarantees. :wink:

MACRO SETUP

  • Carefully review the Release Notes and the Macro Actions
    • Make sure you understand what the Macro will do.
    • You are responsible for running the Macro, not me. :wink:
      .
  • Assign a Trigger to this maro.
  • Move this macro to a Macro Group that is only Active when you need this Macro.
  • ENABLE this Macro.

USE AT YOUR OWN RISK

  • While I have given this limited testing, and to the best of my knowledge it will do no harm, I cannot guarantee it.
  • If you have any doubts or questions:
    • Ask first
    • Turn on the KM Debugger from the KM Status Menu, and step through the macro, making sure you understand what it is doing with each Action.

It's interesting. Yours opens a dialog a bit faster than the AS Chris wrote and is MUCH slower to execute the the actual move which is very fast using the AS.

Also, the AS opens a dialog with an add folder button present and I know you could modify your macro to provide the same.

Good stuff and thank you for providing it and all the structure around it!

Relatedly, I've come across several takes on filing actions. It seems that Filing/Moving files could be a section or topic onto itself within the Forum and might serve as an initial way of organizing Forum materials to present an inroad for learning KM. A bit of continuing Making KM More Accessible for Non-Geeks - #43 by peternlewis

Following are only some pieces that could be included in this topic. This is just a sketch from a beginner's view of this idea and is undoubtedly off in many ways, including putting in this article. :wink:

Getting Started

Straight filing files~

Variations while Moving files~

Parts involved with Moving Files~

Pathways-

The Clipboard-

Dialogs-

Making Folders-

Links-

I can confirm and quantify your results with my testing of moving 14 files:

image

image

Here is my test AppleScript:

use scripting additions
use framework "Foundation"


tell application "Finder"
  set selectedItemList to the selection as alias list
  set destFolder to choose folder
  
  set gTimerStartDate to current application's NSDate's |date|()
  
  move selectedItemList to destFolder
  
  set elapTime to (round (-(gTimerStartDate's timeIntervalSinceNow())) * 1000) / 1000.0
  
end tell

return elapTime

It's cool to get to hang out with people who know what they're doing!

Thank you for always moving the ball forward!!

2 Likes