How can I add the variable i to the end of the name imgSrc variable?
repeat with i from 0 to 5
set imgSrc to execute javascript ""
end repeat
How can I add the variable i to the end of the name imgSrc variable?
repeat with i from 0 to 5
set imgSrc to execute javascript ""
end repeat
Just use the &
operator
set imgSrc to execute javascript "" & (i as text)
however the coercion to text of the integer can be inferred
set imgSrc to execute javascript ("" & i)
That doesn’t work. More info bellow:
I need this (imgSrc0 variable):
display dialog "Variable:" & imgSrc0 buttons {"OK"} default button 1
...
I understand, this is not possible. You cannot compose variable names at runtime.
This works perfectly:
Created by Perplexity.ai:
set imgSrcList to {}
repeat with i from 0 to 5
set imgSrcValue to execute javascript ""
set end of imgSrcList to imgSrcValue
end repeat
repeat with j from 1 to count of imgSrcList
display dialog "Variable " & (j - 1) & ": " & (item j of imgSrcList) buttons {"OK"} default button 1
end repeat
You have to write English well before program.
repeat with i from 0 to 10
set aScript to "set imgSrc" & (i as string) & " to " & (i as string) & "
display dialog \"Variable:\" & imgSrc" & (i as string) & " buttons {\"OK\"} default button 1"
tell application "Script Editor"
set aDoc to make new document
tell front document
set contents to aScript
compile
end tell
end tell
end repeat
Yes, but this doesn’t compose variable names at runtime. It puts values into a list.
And this is not what you asked in the question.