Hello
I'm a bit puzzled.
I ran this simple script :
tell application "Preview" activate end tell tell application "System Events" tell application process "Preview" title of every window --> {"soucoupe YK.png", "Sans titre"} properties of window 1 --> {minimum value:missing value, orientation:missing value, position:{971, 173}, class:window, role description:"fenêtre standard", accessibility description:missing value, focused:false, title:"soucoupe YK.png", size:{408, 279}, value:missing value, help:missing value, enabled:missing value, maximum value:missing value, role:"AXWindow", entire contents:{}, subrole:"AXStandardWindow", selected:missing value, name:"soucoupe YK.png", description:"fenêtre standard"} end tell end tell
I'm puzzled because I don't get the properties listed in System Events dictionary :
elements properties bounds (rectangle) : The bounding rectangle of the window. closeable (boolean, r/o) : Whether the window has a close box. document (document, r/o) : The document whose contents are being displayed in the window. floating (boolean, r/o) : Whether the window floats. id (integer, r/o) : The unique identifier of the window. index (integer) : The index of the window, ordered front to back. miniaturizable (boolean, r/o) : Whether the window can be miniaturized. miniaturized (boolean) : Whether the window is currently miniaturized. modal (boolean, r/o) : Whether the window is the application's current modal window. name (text) : The full title of the window. resizable (boolean, r/o) : Whether the window can be resized. titled (boolean, r/o) : Whether the window has a title bar. visible (boolean) : Whether the window is currently visible. zoomable (boolean, r/o) : Whether the window can be zoomed. zoomed (boolean) : Whether the window is currently zoomed.
In fact I'm able to get these properties only when I 'speak' to the application itself. Example : tell application "Numbers" properties of window 1 --> {zoomed:false, miniaturized:false, name:"Sans titre", floating:false, modal:false, document:document "Sans titre", miniaturizable:true, class:window, closeable:true, resizable:true, zoomable:true, visible:true, id:795, bounds:{1079, 632, 2279, 1479}, titled:true, index:1} end tell
But this piece of code apply only when the app is scriptable.
In other words, how may I get the path of a document which is open in a non scriptable application like Preview ?
Searching in old threads I found one which allowed me to write :
activate application "Preview" tell application "System Events" to tell application process "Preview" title of every window --> {"soucoupe YK.png", "Sans titre"} set theURL to value of attribute "AXDocument" of window 1 (* Leaves theURL undefined if the document was never saved before. If the doc was saved once, returns something like end tell try theURL (* scheme 1 with Satimage *) alias of (URL info for theURL) --> alias "Macintosh HD:Important:pour ebay:soucoupe YK.png" (* scheme 2 with Satimage *) unescapeURL theURL (POSIX file result) as alias --> alias "Macintosh HD:Important:pour ebay:soucoupe YK.png" on error "never saved" end try
Am'I really forced to trigger Satimage to unescape theURL ?
Yvan KOENIG (VALLAURIS, France) dimanche 12 février 2012 15:57:44
|