Skip to content

Instantly share code, notes, and snippets.

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 ChristoferK/0fc32f59c491ed1a7a3f46fd4ca63b2a to your computer and use it in GitHub Desktop.
Save ChristoferK/0fc32f59c491ed1a7a3f46fd4ca63b2a to your computer and use it in GitHub Desktop.
[Front Document's Containing Folder] Retrieves, if available, the path to the frontmost application's active document, from which the parent folder is returned #AppleScript #document #path #file #folder #Accessibility #SystemEvents
tell application id "com.apple.systemevents" to tell (the first process ¬
where it is frontmost) to tell (a reference to the front window) ¬
to if it exists then tell its attribute "AXDocument"'s value to ¬
if it is not in [missing value, "file:///Irrelevent"] then ¬
return my (POSIXPathOfFolder for it)
false
on POSIXPathOfFolder for (fileURL as text)
local fileURL
set fp to "/tmp/rw" as «class furl»
close access (open for access fp)
set eof of fp to 0
write the fileURL to fp
read fp as «class furl»
POSIX path of (result & "::" as text)
end POSIXPathOfFolder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment