If I run the script below I get an error telling me that the script can’t make the properties of finder window in to a string, is there a way round it?
I think it’s some sort of coercion problem.
Here’s the script:-
tell application "Finder"
set the window_count to the count of windows
display dialog window_count as text
repeat with i from 1 to window_count
display dialog name of window i as text
set props to get properties of window i as text
display dialog props
end repeat
end tell
I’ve tried this a few diifferent ways but I still get an error.
properties are normally a record, and a record cannot be coerced to a string.
But there is a amazing trick to do it however.
tell application "Finder"
set the window_count to the count of windows
display dialog window_count as text
repeat with i from 1 to window_count
display dialog name of window i as text
set props to get properties of window i
try
props as string
on error errorMessage
set {ASTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "Can't make "}
set rectext to item 2 of text items of errorMessage
set AppleScript's text item delimiters to " into type string."
set rectext to item 1 of text items of rectext
set AppleScript's text item delimiters to ASTID
end try
display dialog rectext
end repeat
end tell
You’re correct guessing a coerision issue. To my knowledge their is no “inline” way to may a record (which is the format properties generally take) into type string. If you really wanted that you would have to loop through the record items and build a string from that.
Remember though that you are basically parsing out an error message, since AppleScript knows what you mean but can’t do it. That’s clearly a hack, and may not survive system upgrades.
tell application "Finder"
set the window_count to the count of windows
display dialog window_count as text
repeat with i from 1 to window_count
display dialog name of window i as text
set props to properties of window i
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
end repeat
end tell
Note that this isn’t all the info you could gather either… Run the script then check the value of props… you can see there is more info I didn’t dig out.
Thanks for your reply and taking the time to script a solution.
Besides solving my query it has increased my knowledge of Applescript in one or two other ways.