Okay I’ve seen a lot of discussion in this general area but was not able to find an answer to my question.
I want to create a macro that takes the item or items currently selected in the finder and move them to a SPECIFIED folder.
It’s been frustrating because I’ve found screenshots here that seem to show a macro that does this task, but invariable in those cases the poster has not uploaded the actual macro. And also invariably I find I can’t recreate the macro from the screenshot.
Anyway, I’m sure this is an easy problem for a seasoned Keyboard Maestro wizard or Applescripter and I’d be very grateful for some help!
If you have seen posts, or screenshots and there is no macro just ask the poster for the macro. I'd be happy to send you the separate move actions that are all assigned to one keyboard shortcut (That I responded to you about in the other thread), or to even make specific ones you'd like.
In fact I will go out on a limb here and say that if you indicate what the name of the folder is and the path to that folder on your system, someone will likely whip it up and post it for you before you can blink an eye.
Personally, I prefer that people build their macros from screenshots because that means you learn how to build the macro, which is more important than the macro itself (with exceptions for really complex macros).
If you see an image of a macro and you cannot build it yourself, ask how to build it.
Absolutely. I am talking about general questions with simple answers.
And I am not in any way suggesting people should refrain from posting the kmactions/kmmacros file as well (especially since Share to Forum makes it so easy to do both). It’s more that I would strongly encourage readers to create simple three or four action macros themselves rather than import it, because that will benefit them more than just double clicking a file. It will also train people up on the small details that are important, regex/string searching for example, which would not necessarily be noticed if you don’t have to manually re-create the macro.
Hello! So it’s been awhile, but I figured I’d post in the same thread in case people are interested.
So, unfortunately these macros for moving selected files to specific folders didn’t function well. It seemed they usually worked, but items would often end up in the wrong folder. I couldn’t figure out the reason for sure, but it seems that if a file wasn’t finished being moved, it might follow the next file into the new folder. Again, I’m not sure if this is what happened, but things were definitely going to the wrong folders.
Is there perhaps an AppleScript that could be triggered and edited for different folders?
------------------------------------------------------------------------------
# This is a relative-alias
set destinationFolder to alias ((path to downloads folder as text) & "YourFolderName")
tell application "Finder"
set finderSelectionList to selection as alias list
if length of finderSelectionList = 0 then error "No files were selected in the Finder!"
move finderSelectionList to destinationFolder
end tell
------------------------------------------------------------------------------
Here's the same script with better error-checking:
------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2017/03/19 16:40
# dMod: 2017/03/19 16:43
# Appl: Finder
# Task: Move the selected items to a destination folder
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Finder @Move, @Selected, @Items, @Destination, @ccstone
------------------------------------------------------------------------------
try
# This is a relative-alias
set destinationFolder to alias ((path to downloads folder as text) & "YourFolderName")
tell application "Finder"
set finderSelectionList to selection as alias list
if length of finderSelectionList = 0 then error "No files were selected in the Finder!"
move finderSelectionList to destinationFolder
end tell
on error e number n
set e to e & return & return & "Num: " & n
if n ≠ -128 then
try
tell application (path to frontmost application as text) to set ddButton to button returned of ¬
(display dialog e with title "ERROR!" buttons {"Copy Error Message", "Cancel", "OK"} ¬
default button "OK" giving up after 30)
if ddButton = "Copy Error Message" then set the clipboard to e
end try
end if
end try
------------------------------------------------------------------------------
Could you please be specific about which macros are NOT working properly for you? Please post a link to the macro topic.
If there is a bug in the macro that affects you, then it will probably affect others as well.
So, we need to get the bugs fixed.
It will assemble this part of the code for you and places it on the Clipboard:
alias ((path to downloads folder as text) & "YourFolderName")
You can run that script from the Script Editor.app to see how it works.
Essentially it takes a known location (path to...) and converts the resulting alias to a string.
That string is an HFS path.
From that anchor-point the script appends the rest of the path (from the anchor) to the file or folder.
The “alias” in front of that turns the full HFS path into an AppleScript alias.
Once you've selected a few items in the Finder and run the script to see how the paths differ, place it into an Execute an AppleScript action in a Finder-specific Keyboard Maestro macro – give it a keyboard shortcut ⌃⌥⌘P (or whatever is mnemonic for you) – and go-to-town.
--> is representative of a result in AppleScript.
set hfsPathStr to ((path to downloads folder as text) & "Test Folder:")
--> "Mercury:Users:myUserName:Downloads:Test Folder:"
set destFldrAlias to alias hfsPathStr
--> alias "Mercury:Users:myUserName:Downloads:Test Folder:"
Most Mac-users are terribly confused by path strings when first exposed to them. Don't let it bother you if you're one of them.
You have to use them a bit, before they start to feel comfortable. It probably took a year before using them became second nature to me – and that was back in the days of only HFS paths. When OSX came around so did POSIX Paths and a whole new set of issues, and again it took me a while to get comfortable with them.
If you’re going to run an AppleScript in Keyboard Maestro TEST it FIRST in the Script Editor.app (or Script Debugger if you have it).
Open the Log History window in the Script Editor and see what the script does.
Don’t just run it from the black box of an Execute an AppleScript action in Keyboard Maestro.
If you’re unfamiliar with AppleScript this won’t mean a lot to you at first, but it will give you some feel for what is happening.
If you have a little understanding of what’s happening in the code, you can comment-out segments of code – so you can see what is happening at a certain point.
Script Debugger makes this sort of thing MUCH easier, because it has a real debugger and offers a live view of variables as they change.
But with a little understanding and effort you can discover quite a lot about AppleScript code using Apple’s Script Editor.app.
# This is a relative-alias
set destinationFolder to alias ((path to downloads folder as text) & "YourFolderName")
tell application "Finder"
set finderSelectionList to selection as alias list
if length of finderSelectionList = 0 then error "No files were selected in the Finder!"
move finderSelectionList to destinationFolder
end tell
...
```[/quote]
Unfortunately I got the following error message:
File alias MacHD:Users:aaronseeman:Downloads:/Volumes/Main External 1.5 TB/Test AppleScript Move wasn’t found.
Num: -43
This seems to take an item or items selected in the Finder and moves them to a specified folder.
I don't know why as I don't know what %path% means. Just poking around in the dark and found this. Hopefully I don't stumble across any sleeping bears or deep crevices...
Why does this work? Under what circumstances would it not work? If this solves the request, why are more complicated solutions being offered?
Does the drive (boot or non-boot) the selected item is in and the drive being moved to matter as it seemed to for Duckmandu's circumstance?