I need to get the name of the enclosing folder for a selected file in the Finder (so that I can go back into Premiere Pro and paste that folder name into the currently selected clip, which I think I can figure out...just can't figure out the part where KM gives me the Enclosing Folder's name in the Finder).
Wow, thank you so much! It would have taken me a decade to have figured that out!
The only thing I don't think I need is the last step where the System Clipboard is set to a variable, only because I am immediately pasting the name into the clip (in Premiere Pro). I just told it to output to the System Clipboard, but otherwise this is perfect (your quick reply greatly appreciated).
I will say here this level of complexity can make KM somewhat inaccessible. It would be great to just have some constants like "Parent_Folder" and so on, rather than parsing using regular expressions. KM does this for many aspects already so it's not like it couldn't be done.
I seem to remember having seen somewhere in KM to be able to get to path segments easier.
But could not find it right away, so I choose the regex way.
And I always forget that many actions have an option to output to other than source. So output to clipboard from the search and replace is a good idea.
For example, you can cycle through the selected item(s) in Finder using a For Each Action and grab the desired attribute (such as the parent path) like this:
Interesting. I need just the name of the Enclosing Folder of the selected file. Your example gives me the entire path.
I'll look at your two suggestions, though...thanks.
You can be that terse if your workflow allows it, or you can build in some error-handling:
--------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2021/11/19 15:55
# dMod: 2021/11/19 15:55
# Appl: Finder
# Task: Return the Name of the Selected Item (one item) in the Finder.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Finder, @Name, @Selected, @Item
--------------------------------------------------------
property LF : linefeed
--------------------------------------------------------
try
tell application "Finder"
set finderSelectionList to selection as alias list
set numberOfSelectedItems to length of finderSelectionList
if numberOfSelectedItems = 1 then
return name of parent of item 1 of finderSelectionList
else
error "Error:" & LF & LF & "The Number of Selected Items is: " & numberOfSelectedItems
end if
end tell
on error errMsg number errNum
set errMsg to errMsg & linefeed & linefeed & "Num: " & errNum
if errNum ≠ -128 then
try
tell application (path to frontmost application as text) ¬
to set ddButton to button returned of ¬
(display dialog errMsg 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 errMsg
end try
end if
end try
--------------------------------------------------------
That's cool. If I understand the program logic of your script, there's error checking to determine if less than or more than 1 item is selected. My macro gets started up inside of Premiere Pro with the command "Show clip in Finder" so it can only have one selection (assuming the macro is running properly). But, hey, error checking's good!