r/applescript • • Aug 19 '21

How to save command-result in variable?

Hey guys Im really new to AppleScript and wanted to use it to test my shell. So I tell AppleScript to start the shell and execute some commands. I want to test if the output of the commands is the desired one. How do I get the command output? This is the code:

osascript <<EOF
tell application "System Events"
  keystroke "cd /Users/uwe/documents/coding/c/pshell"
  delay 0.5
  keystroke return
  delay 0.5
  keystroke "make compile_and_run"
  delay 1
  keystroke return
  set resul to paragraphs of (read STDOUT)
end tell
EOF

Thanks for the help

3 Upvotes

6 comments sorted by

View all comments

Show parent comment

1

u/ssharky Aug 21 '21

ah, sorry, i read that but didn’t think through what it meant.

You could try something like running keystroke “make compile_and_run | pbcopy” and then set result to the clipboard to pass the output through the clipboard