Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save thespacedoctor/e238a23dcdb82beb98de61e244ec2a60 to your computer and use it in GitHub Desktop.
Save thespacedoctor/e238a23dcdb82beb98de61e244ec2a60 to your computer and use it in GitHub Desktop.
[Get filepath of front window in any application] #filepath #applescript
property pstrApp : "Typora"
tell application "System Events"
-- GET CURRENT FILEPATH FROM APP
set lstProc to application processes where name contains pstrApp
if lstProc is not equal to {} then
try
set winThoughts to front window of item 1 of lstProc
on error
return
end try
set strURL to value of (attribute "AXDocument" of winThoughts)
set filepath to POSIX path of (POSIX file strURL as alias)
return filepath
end if
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment