Skip to content

Instantly share code, notes, and snippets.

@OKsign
Created December 11, 2021 11:13
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 OKsign/cb49556162c286739a91499c90ed8680 to your computer and use it in GitHub Desktop.
Save OKsign/cb49556162c286739a91499c90ed8680 to your computer and use it in GitHub Desktop.
tell application "System Events"
set activeApp to (get name of first process where it is frontmost)
end tell
tell application "System Events"
tell process activeApp
set docPath1 to value of attribute "AXDocument" of window 1
end tell
end tell
if docPath1 is not missing value then
if docPath1 contains "%20" then
set prevTIDs to AppleScript's text item delimiters
set AppleScript's text item delimiters to the "%20"
set the item_list to every text item of docPath1
set AppleScript's text item delimiters to the " "
set docPath1 to the item_list as string
set AppleScript's text item delimiters to prevTIDs
end if
if docPath1 contains "%" then
set prevTIDs to AppleScript's text item delimiters
set AppleScript's text item delimiters to the "%25"
set the item_list to every text item of docPath1
set AppleScript's text item delimiters to the "%"
set docPath1 to the item_list as string
set AppleScript's text item delimiters to prevTIDs
end if
if docPath1 contains "localhost" then -- remove characters
set docPath2 to ((characters 17 thru -1 of docPath1) as string)
else
set docPath2 to ((characters 8 thru -1 of docPath1) as string)
end if
set activeDoc to POSIX file docPath2
end if
set the clipboard to activeDoc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment