@JimmyHartington..wow!!!!
this is the stuff dreams are made of lol
thx so much. in a related question then, can one use this to instead open a path rather move a selected file to one of the targets in that list you presented?
I see you're trying to change the directory of the front Finder window.
AppleScript makes that pretty easy.
----------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2019/01/09 16:27
# dMod: 2019/01/09 16:27
# Appl: Finder
# Task: Change the Target of the Front Finder Window
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Finder, @Change, @Target, @Front, @Window
----------------------------------------------------------------
set newTarget to path to downloads folder
tell application "Finder"
if window 1 exists then
tell window 1
if (its target as alias) ≠ newTarget then
set its target to newTarget
else
beep 2
end if
end tell
end if
end tell
----------------------------------------------------------------
Jimmy's “Open folder” macro could easily be repurposed to do this as well.
The good news is that I just tried it again, to verify the error message, and the darn thing worked. Have tried it twice more and it works. So I'm at a loss as to why it repeatedly failed before. I tried it at least 10 times before and it failed every time, no matter what folder I tried.
I find this AppleScript super useful, but realized that it throws an error if the finder is showing "Recents" ... probably because it's not really a real folder.
I updated the AppleScript to make it work ...
set newTarget to "Mac HD:Users:UserName:Downloads:"
tell application "Finder"
if window 1 exists then
tell window 1
if (its target as string) is equal to "" then --my additon to code
set its target to newTarget
else if (its target as alias) ≠ newTarget then --added an "else" to beginning
set its target to newTarget
else
beep 2
end if
end tell
end if
end tell
Here's a new and improved version of my script above.
-Chris
--------------------------------------------------------
# Auth: Christopher Stone <scriptmeister@thestoneforge.com>
# dCre: 2019/01/09 16:27
# dMod: 2021/01/25 14:18
# Appl: Finder
# Task: Change the Target of the Front Finder Window (Improved).
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Finder, @Change, @Target, @Front, @Window
# Vers: 2.0
--------------------------------------------------------
# Never use a hard-coded path unless you have to.
# They're fragile and break when you least want them to.
set newTargetAlias to path to downloads folder as text
tell application "Finder"
if exists of window 1 then
tell window 1
set windowTargetPathHFS to its target as text
if (windowTargetPathHFS = "") or (windowTargetPathHFS ≠ newTargetAlias as text) then
set its target to newTargetAlias as alias
else
display notification linefeed & (newTargetAlias as text) & linefeed ¬
with title "Front Window Location already set to:" sound name "Tink"
end if
end tell
else
set newFinderWindow to make new Finder window
tell newFinderWindow
set its target to newTargetAlias
set its bounds to {488, 23, 1432, 1196}
if toolbar visible = false then set toolbar visible to true
end tell
end if
end tell
--------------------------------------------------------
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
--------------------------------------------------------
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.
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
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.
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