2

是否可以在 Mac 上复制当前活动窗口的完整目录?

例如,假设我在 Sublime Text 中打开了 example.txt,我可以执行一个 Apple 脚本来获取该文件的完整路径吗?(不去 Finder)。

结果将是 /Users/Bob/Dropbox/example.txt 然后将在我的剪贴板中。

4

1 回答 1

1

您可以为这样的脚本分配快捷方式

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

第一种方法不适用于 Preview、TextMate 2、Sublime Text 或 iChm,第二种方法不适用于 Acorn。

于 2013-07-08T01:52:43.403 回答