Please can someone help me out with this small query.
I’ve trawled through a number of posts and tried a number of variations but still get the same error message “Can’t get properties of window.”
I’m trying to get the properties of a window whose name has just been selected from a list.
I’ve tried a number of variations:-
set props2 to properties of window whose id is xx
set props2 to properties of window whose name is xx
set props2 to properties of Finder window whose id is xx
set props2 to properties of Finder window whose name is xx
xx is the selection from the list.
Rather than looping through all the windows again, which I did to generate the list, I want to get the properties of the window using it’s name.
Thanks in advance,
Nick
Model: G5
Browser: Safari 312.3
Operating System: Mac OS X (10.4)
Just one further query, when I replace the relevant line I get a new error, which I think might be due to a coercion problem. The error is “Finder got an error: Can’t make some data into the expected type.”
Here’s the code, which needs a little tidying up:-
set window_list to {}
tell application "Finder"
set the window_count to the count of windows
repeat with i from 1 to window_count
set props to properties of window i
set window_list to window_list & (name of props)
end repeat
set xx to choose from list window_list
display dialog xx
set props2 to properties of some window whose id is xx as text
set this_props to (name of props2)
set yy to "bounds:{" & item 1 of bounds of this_props & ", " & ¬
item 2 of bounds of this_props & ", " & ¬
item 3 of bounds of this_props & ", " & ¬
item 4 of bounds of this_props & "}, "
display dialog yy
end tell
set winPropList to {}
set nameList to {}
tell application "Finder"
set the window_count to the count of windows
repeat with i from 1 to window_count
set end of winPropList to properties of window i
set nameList to nameList & name of item i of winPropList
end repeat
end tell
set winName to (choose from list nameList) as text
repeat with aProp in winPropList
if name of aProp is winName then set boundDisplay to ¬
"bounds:{" & item 1 of bounds of aProp & ", " & ¬
item 2 of bounds of aProp & ", " & ¬
item 3 of bounds of aProp & ", " & ¬
item 4 of bounds of aProp & "}"
end repeat
display dialog boundDisplay with title winName
tell application "Finder"
tell windows to set {winPropList, winName} to {properties, (item 1 of (choose from list (get name)))}
tell (get bounds of 1st window whose name is winName) to set boundDisplay to "bounds:{" & item 1 of it & ", " & item 2 of it & ", " & item 3 of it & ", " & item 4 of it & "}"
display dialog boundDisplay with title winName
end tell
Thanks for the other posts and the new solutions.
I did get version, that uses names, working and was going to post it but it looks like you’ve both beaten me to it. Second thoughts, here it is:-
set window_list to {}
tell application "Finder"
set the window_count to the count of windows
repeat with i from 1 to window_count
set props to properties of window i
set window_list to window_list & (name of props)
end repeat
set xx to choose from list window_list
set props to properties of some window whose name is xx
set propString to "{" & "id: " & id of props & ", " & ¬
"closeable: " & closeable of props & ", " & ¬
"floating: " & floating of props & ", " & ¬
"zoomable: " & zoomable of props & ", " & ¬
"bounds:{" & item 1 of bounds of props & ", " & ¬
item 2 of bounds of props & ", " & ¬
item 3 of bounds of props & ", " & ¬
item 4 of bounds of props & "}, " & ¬
"class: " & class of props & ", " & ¬
"index: " & index of props & ", " & ¬
"modal: " & modal of props & ", " & ¬
"name: " & name of props & ", " & ¬
"position:{" & item 1 of position of props & ", " & ¬
item 2 of position of props & "}, " & ¬
"resizable: " & resizable of props & ", " & ¬
"titled: " & titled of props & ", " & ¬
"current view: " & current view of props & ", " & ¬
"visible: " & visible of props & ", " & ¬
"zoomed: " & zoomed of props & ", " & ¬
"sidebar width: " & sidebar width of props & ", " & ¬
"statusbar visible: " & statusbar visible of props & ", " & ¬
"toolbar visible: " & toolbar visible of props & ", " & ¬
"collapsed: " & collapsed of props & ", " & ¬
"column view options:{discloses preview pane: " & discloses preview pane of column view options of props & ¬
", shows icon: " & shows icon of column view options of props & ¬
", shows preview column: " & shows preview column of column view options of props & ¬
", text size: " & text size of column view options of props & "}"
display dialog propString
set bounds_string to item 1 of bounds of props & ", " & ¬
item 2 of bounds of props & ", " & ¬
item 3 of bounds of props & ", " & ¬
item 4 of bounds of props
display dialog bounds_string as text
set the clipboard to bounds_string as text
end tell
It looks pretty ungainly in comparison. The compactness of Stefan’s has given me food for thought.
Thanks once again for helping me out with this one.
a different approach is using a trick to coerce the property record to a string (with a forced error)
and put the result into two lists: nameList and valueList. Some names and values are “not human readable”
(e. g. displayed as «class xxyy») but maybe you can use it anyway
tell application "Finder" to set a to properties of window 1
set propList to coerce_record_to_string(a)
set {i, nameList, valueList} to {2, {}, {}}
set {TID, text item delimiters} to {text item delimiters, ":"}
set propList to text items of propList
try
set end of nameList to text 2 thru -1 of text item 1 of propList
set text item delimiters to ", "
repeat
set end of valueList to text items 1 thru -2 of item i of propList as text
set end of nameList to text item -1 of item i of propList
set i to i + 1
end repeat
end try
set end of valueList to text 1 thru -2 of text item -1 of propList
set text item delimiters to TID
on coerce_record_to_string(theRecord)
try
return theRecord as string
on error errorMessage
set {ASTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "Can't make "}
set theRecord to item 2 of text items of errorMessage
set AppleScript's text item delimiters to " into type string."
set theRecord to item 1 of text items of theRecord
set AppleScript's text item delimiters to ASTID
return theRecord
end try
end coerce_record_to_string
Thanks for your reply and for taking the time to show me a new method.
I have to confess, someone did show me a similar trick the other, your method is slightly different though.