ccstone
January 25, 2021, 8:29pm
24
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
BernSh
January 25, 2021, 10:17pm
25
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:
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.
.
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.
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.
.
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.
BernSh
January 26, 2021, 12:58pm
27
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.
Getting Started
Straight filing files~
I can send cmd + c keystroke followed by cmd + delete and then I am stuck. There is a Move or Rename a File action and I suppose I have to put my copied file/s to some clipboard and pass that to it or is there a better way?
Thank you for any help.
Yes, it can, although using TextEdit as opposed to a plain text editor like BBEdit does complicate things a bit for the macro since it uses RTF for its default format. It is definitely possible, though. For formatting, each destination folder needs to be on its own line, and if you want the prompt to show something other than the folder path, like a custom name, you will need to follow @roosterboy 's advice and append the name to the file path with two underscores, like this:
~/Documents/Importā¦
As I just replied in your other post, see:
MACRO: Transfer Files Between Folders [Example]
~~~ VER: 2.0 2018-03-12 ~~~
DOWNLOAD:
Transfer Files Between Folders [Example].kmmacros (41 KB)
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.
Please feel free to post below with any questions/issues/suggestions.
This Macro Provides
Selection of Source and Destination Folders
Folders can have default selection based on selection in Finder
Prompt to Confirm continue of macro, showing folders
ā¦
Variations while Moving files~
Hey folks. I've got an idea for a macro I'd like to try, but haven't quite figured out how to pull it off. When I'm working on a project (in my case, I do film scoring, so each project is movie), I have the same folder hierarchy set up everytime, just with the current project name at the top. When I've finished my individual music cues in Digital Performer, I export those files to an Mixes folder that then gets sent to the places it needs to go.
For each movie it's always the same place, so Iā¦
I often find that I want to move the selected file(s)/folder(s) to their parent directory.
I wasn't sure how to best do this, so I did what I always do, I wrote a shell script that checks to make sure the same file(s)/folder(s) don't exist in the parent directory, and then moves them.
This is designed to be used in a group that is only active in Finder.app:
Download: Finder - Move to Parent Folder.kmmacros (38 KB)
[image]
OK folks, now I get to offer something constructive. Passing this on in case It helps. I wanted to know how to move a file using Finder. It turns out that you can use a keystroke which is far easier than writing a script.
I am working on a project which requires reviewing a large number of documents then moving relevant found documents to my project folder while I put together a final PDF for project output. To do this I need to figure a way to keep all my files where they are parked, then to pā¦
I havenāt used Keyboard Maestro for a while. Basically I just want to copy a file from my iMac to a Mac Mini that has been triggered by a hot key. The file exists in the new location so will I have to delete that first and then copy it over?
So let me start by declaring I'm a Keyboard Maestro newbie, and this is my first post. Hello all!
I'm trying to figure out how to take a currently selected file or folder and trigger a macro to ideally automate:
Creating a new folder in the same location as the selected file or folder.
Moving the selected file or folder inside the new folder.
Renaming this new folder with the originally selected file or folder name, leaving me with an ability to edit the new folder name before committing it.
ā¦
Use Case
Provide an easy way to search/filter the list of files in a folder
Allows user to use incremental search with autocomplete to search/filter a list of files in a selected folder
User will be Prompted to Select the Target Folder
Example Output
[Demo-My-Macro-Choose-File-AN]
Revised to exclude invisible files, and to sort files alphabetically
[image]
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 workfā¦
Parts involved with Moving Files~
Pathways-
Hey Folks,
Anyone working with shell scripts often needs to grab a Posix path or three from item(s) in the Finder. Here's a simple macro to do just that.
Finder-Selection { Get Paths ~:⦠If Possible }.kmmacros (4.0 KB)
[image]
Example Result:
[image]
It's good practice to use home-directory-anchored paths when possible, because they are more likely to survive a change in hard-drive-name, user-name, or a move to a different computer.
Many years ago I predominantly used hard-coded-paths, ā¦
Hey Folks,
Sometimes you need the POSIX Path of a document that's open in an application.
Sometimes that's available via the app's native sdef (AppleScript Dictionary), but unfortunately not all apps are natively AppleScriptable.
AppleScript, System Events, and UI-Scripting to the rescue ā the macro below will grab the POSIX Path of the frontmost document open in most applications.
-Chris
Acquire POSIX Path of File Associated with Front Window of Front Application.kmmacros (7.7 KB)
[imagā¦
In Keyboard Maestro, you work with the Finder Selection by using the For Each action to iterate over the selected files. From there, you can do whatever you would like with the files using the various file actions, or by processing with a script or other means. There is a smart action in the acton selector for For Each Path in the Finder Selection, which is simply a For Each action, preset to iterate through the Finder Selection collection. You can put whatever actions you like within that acā¦
I would like to get the path of a file selected in Finder.
I have seen the post . When I use it, it provides both the path and filename.
An internet produces some AppleScript such as:
tell application "Path Finder" to get POSIX path of (item 1 of (get selection))
But this also produces path and filename.
Is there a simple way to amend the AppleScript or the macro that Peter provided in his post to just get the filename alone?
I've used a Services extension to copy the path of the Finder selection for eons, so I never noticed it is not installed by default in OS X. I received a recent support question asking for this, so here is the resulting macro.
Select a file in the Finder, and then select Copy Path from the Keyboard Maestro status menu and the selection's POSIX path is copied tot he clipboard. If you select more than one, then they are copies as multiple lines (if its only one, there are no return characters), ā¦
I would like to get the path of a file selected in Finder.
I have seen the post . When I use it, it provides both the path and filename.
An internet produces some AppleScript such as:
tell application "Path Finder" to get POSIX path of (item 1 of (get selection))
But this also produces path and filename.
Is there a simple way to amend the AppleScript or the macro that Peter provided in his post to just get the filename alone?
I searched and cannot find an answer to this. The nearest I came was: [File Paths Not Working, Why? ](http://this post). That post was about writing out the file path apparently, not clicking on a file and creating the path with correct formatting (escaping the spaces).
I use an app regularly that has been having inconsistencies in dragged in file or folder paths. It may be fixed soon (or not). I am wondering how to set up a macro from either a right click or a keystroke where I can copy the filā¦
The Clipboard-
Continuing the discussion from Working with the Finder Selection :
Is there a way to copy a pdf at a file path into a Keyboard Maestro clipboard so I can paste it in to an email in Apple Mail? I command+c the file and command+p which of course work in the Finder and then Apple Mail. The file is the same
This post is so old - but I can't get this to work now? Same kind of idea except I want a new file added to a folder to be added to the clipboard, so I can paste it into Mail or Skype or Slack or wherever else. Any tips would be great - sorry for what must be a very simple question - I have lots of macros for things but just can't figure this one out!
Hey Folks,
Hereās how to put a reference to one or more files and/or folders onto the clipboard.
These files and/or folders may then be pasted anywhere the macOS will allow, such as in the Finder, Apple Mail, etc.
-Chris
----------------------------------------------------------------
# Auth: Christopher Stone { Heavy Lifting by Shane Stanley }
# dCre: 2018/04/10 16:57
# dMod: 2018/04/19 14:42
# Appl: AppleScriptObjC
# Task: Place a reference to one or more files and/or folders on the clipboā¦
Dialogs-
I would like to create a macro that would let me press a key to set the current location of an open/save dialog screen to the frontmost Finder window. Bonus points for tips on a macro that can set the location of the open/save dialog to the second frontmost Finder window, and so on.
I realize that I can just drag the little folder icon of a given finder window into an open/save dialog, but that involves a LOT of clicking and dragging as you have to be able to see both the finder window and theā¦
Making Folders-
Use Case
As some of you may be aware, the Finder already offers a similar feature. While it works OK, this macro offers the following:
A prompt to enter the folder name, which you can cancel.
Tests for a folder already existing by the same name, and gives you an opportunity to cancel or overwrite.
So this macro may, or may not, be a benefit to you over the Finder feature. You can choose.
MACRO: Create New FOLDER in Current @Finder Folder
--- VER: 1.2.1 2022/02/18 ---
DOWNLOAD:
Crā¦
Group to Folder
by Ian Kirkland
Description
Of all the actions I've created, this is probably among my most-used and ā truth be told ā favorites. The action groups selected Finder items into a new folder with the name defined in the action's field.
You're probably wondering, "Why not use the grouping functionality already built into Finder's menu?" Good question! Here's why: If you use a project-based organizational scheme or even a mildly-OCD-driven folder hierarchy, you've likeā¦
Links-
What for?
Many text-handling programs allow you to drag (or paste) a file into their text field, in order to create a file URL that points to that file.
The problem with this is: Unlike Finder Aliases, file URLs are fragile. They behave like absolute symlinks, that is, they immediately break if you do one of the following:
Modify the file name
Move it to another folder
Modify the name of any of the fileās parent folders
Move any of the fileās parent folders
The macro facilitates you to creatā¦
I can confirm and quantify your results with my testing of moving 14 files:
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
BernSh
January 26, 2021, 9:25pm
29
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