Skip to content

Instantly share code, notes, and snippets.

Created February 8, 2017 09:27
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
pwdf - prints the path to the frontmost Finder window
on run arguments
tell application "Finder"
-- no argument: get frontmost window or desktop
if (count of arguments) is 0 then
if (count of windows) is 0 then
set dir to (desktop as alias)
set dir to ((target of Finder window 1) as alias)
end if
if first item of arguments is in {"all", "-a", "-all", "--all"} then
-- list all Finder windows
copy target of every Finder window to theList
repeat with w in theList
log POSIX path of (w as alias)
end repeat
end if
-- see if there is a window matching the name
set t to arguments as text
set wins to every Finder window where name contains t
if (count of wins) > 0 then
set dir to ((target of item 1 of wins) as alias)
end if
end if
return POSIX path of dir
end tell
end run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment