How do I get the first item from a list into a variable?
I'm trying to get the first window of an application's windows.
I tried
tell application "System Events"
repeat with theProcess in processes
if not background only of theProcess then
if processName is "Xcode" then
set theWindow to first window of windows
end if
end if
end repeat
end tell
but it throws this error:
Can't get window of every window.
Best Answer
Unless you have an explicit need for going about it in the manner shown in your question, I'd keep it much more simple and use:
Otherwise, modifying your existing code block in the following manner will get that same result as the two lines of code above:
If you want to use the first two line of code in my answer in a more tokenized manned, as an example, use:
Then all you need to do is set
appName
to the target app in the first line of code and the two lines of code following it stand as is and do not need to be edited for use with other app names.