Last active
September 29, 2019 16:35
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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