How to translate an AppleScript "target" to a Mac OS "path"

I appreciate greatly the assistance I have received on this forum. And I am learning slowly but surely how to take advantage of the power of Keyboard Maestro. Thank you to all of you who have helped me with all my previous questions. Now I have a new one that I hope will prove useful to many as well as to myself. I know just enough AppleScript to be a little dangerous, and one of the commands that I love is the GET TARGET command which yields the path to a given window in the Finder. However in FINDER language the syntax is different from what AppleScript produces

In AppleScript the path (target) looks like this:

folder "Windows Scripts" of folder "APPLESCRIPT" of folder "TECHNOLOGY" of folder "Documents" of folder "Polyvox" of folder "Users" of startup disk of application "Finder"

The same path in Mac OS Finder "language" looks like this:

Users/Polyvox/Documents/TECHNOLOGY/APPLESCRIPT/Windows Scripts

This is generally how I have my folders set up in the Finder, from general to specific. It would be lovely if I had a macro that could take any window and produce a written path in FINDER language (as opposed to APPESCRIPT) that could then be copied and pasted anywhere. That is to say, once I had this "translator" macro I pretty much know how I can expand its use in the future.

I suspect that the answer to all of this will involve variables. I am less confident using variables, but I am willing to learn. And the best way for me to learn, I suppose, is by jumping in.

And I may be missing something, of course. There is probably a very simple answer. And it may be that I don't need to use AppleScript at all to achieve my purpose. Maybe there is a way to get this path using only KM commands. If so, even better. I am only trying to proceed from what I already know to what I HOPE to know.

Thank you, anyone, in advance.

Use POSIX path like this:

tell application "Finder"
	set windowTarget to target of front window as text
	get POSIX path of windowTarget
end tell

It will do the translation for you.

It's been a while. Yes, this works fine. I have been using it with good success. Now I would like to get the result of the above AppleScript copied to the clipboard. As a way of confirming beforehand, though, can we first get a little pop-up window to say something like, " Here is the POSIX path you requested: [path]. Would you like to copy this to the clipboard? [yes,no]"

(I know the syntax is bad here. I'm just returning to AppleScript for a brief "go to" snippet.)

Anyway, that would make my life complete. For now.

Many thanks.

Hi, @Polyvox. Here's one method:

tell application "Finder"
	set windowTarget to target of front window as text
	set thePath to the POSIX path of windowTarget
	
	set dialogText to "Would you like to save the following path to the clipboard?" & return & return & thePath
	set dialogResult to display dialog dialogText buttons {"No", "Yes"} default button "No" with icon note
	
	if button returned of dialogResult is "Yes" then
		set the clipboard to thePath
	end if
end tell
1 Like