Reputation: 14153
Is it possible to copy the full directory of the current active window on Mac?
e.g. say I have example.txt open in Sublime Text, can I execute an Apple Script that will grab the full path of that file? (without going to Finder).
The result would be that /Users/Bob/Dropbox/example.txt would then be in my clipboard.
Upvotes: 2
Views: 304
Reputation: 27633
You could assign a shortcut to a script like this:
try
tell application (path to frontmost application as text)
set the clipboard to (path of document 1) as text
end tell
on error
try
tell application "System Events" to tell (process 1 where frontmost is true)
value of attribute "AXDocument" of window 1
end tell
do shell script "ruby -rcgi -e 'print CGI.unescape ARGV[0][16..-1]' " & quoted form of result
set the clipboard to result
end try
end try
The first method didn't work with Preview, TextMate 2, Sublime Text, or iChm, and the second method didn't work with Acorn.
Upvotes: 1