I am trying to save the targets to the currently opened windows in the finder so that I can open them to the same spots later on in the script. I was trying to save it in a list to allow for any number of windows, but this does not work, it won’t assign the targets to items in the list
set ids_length to 1
set win_path to {}
tell application "Finder"
get index of every window
set ids to result
end tell
try
set ids_length to last text item of ids
set ids_lenght to ids_lenght + 1
on error
end try
display dialog ids_length
repeat with i from 1 to ids_length
tell application "Finder"
get target of window i
set item i of win_path to result
end tell
end repeat
set ids_length to last text item of ids
set ids_lenght to ids_lenght + 1
Where I think you’re trying to set the second line to:
set ids_length to ids_length + 1
but I might be wrong.
Secondly, in the part where you:
set item i of win_path to result
win_path is an empty list. You cannot set “item 1” of an empty list to any value. The item does not exist and this syntax does not add items to the list. Instead you need to append to the list:
copy result to end of win_path
That said, I think you’re going about this in a very long-winded way.
Following the script through, you first ‘get index of every window’, which simply returns a list like {1, 2, 3, 4} (depending on the number of windows you have open. You then find the value of the last item (where you could simply find the count of the list), then run a loop for that many times getting ‘target of window i’.
This whole script could be condensed into one line:
tell application "Finder" to set win_path to target of every window
You don’t need to count the windows and iterate through them.