Run script on the fly

why is this not working?

global myScriptText
set myScriptText to "beep" & return & "beep"

script HelloWorld
	display notification "Hello World!"
	myScriptText -- I would expect here the computer to make a beep sound!
end script
tell HelloWorld to run

I basically what to “create” a script into a text string and then run it …
is that possible?

Thanks !


Since your script is text, you need to use the ‘run script’ command:

set myScriptText to "beep" & return & "beep"

run script myScriptText

Or less efficiently, but useful to some:

set myScriptText to "beep" & return & "beep"

do shell script ("osascript -e " & quoted form of myScriptText)

Thanks Nigel !!!