Skip to content

Instantly share code, notes, and snippets.

@matthewmcvickar
Last active December 13, 2015 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewmcvickar/4964647 to your computer and use it in GitHub Desktop.
Save matthewmcvickar/4964647 to your computer and use it in GitHub Desktop.
Get the path of the frontmost Finder window. If it is within the user’s folder, replace the `/Users/USERNAME/` with `~/` so that the path can be shared with others.
tell application "Finder"
tell application "System Events" to set current_user to name of current user
set AppleScript's text item delimiters to "/Users/" & current_user
try
return "~" & text item 2 of POSIX path of (target of front Finder window as text)
on error
return POSIX path of (target of front Finder window as text)
end try
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment