Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the path of a document open in Preview using AppleScript?

Tags:

applescript

I have tried this but it doesn't work:

tell application "Preview"
    set myfile to path of document 1 of window 1
end tell

I have verified that my Preview is scriptable (NSAppleScriptEnabled).

like image 220
Abhi Avatar asked Dec 28 '22 23:12

Abhi


1 Answers

I did a little research and found this

 tell application "System Events"
    tell process "Preview"
        set thefile to value of attribute "AXDocument" of window 1
    end tell
 end tell

-- macos comes with php installed you can decode this file name using php
return do shell script "php -r 'echo urldecode(\"" & thefile & "\");'"

which i found on macscripter

like image 107
mcgrailm Avatar answered Apr 27 '23 15:04

mcgrailm