Is it possible to add assertions for a terminal output in AppleScript?
do script “osascript -e 'tell application “Terminal”
reopen
activate
delay 1
./ccwrap -c 2” in window 1
on idle
end idle
end tell'
""")
Here is my code. I am entering a command and want to expect a certain output. I’ve seen that if statements would work for this but couldn’t quite figure out how to make it work.
The script is placed in an applescript document — could be script or text (ie with extension of ‘scpt’ or ‘applescript’). In this example, it runs a script saved on the desktop.
osascript ~/Desktop/get-selection.applescript
Using standard input
echo ‘Tell application “Finder”
get selection as text
end tell’ | osascript
Using the shell’s heredoc (which is actually an example of using ‘stdin’)
osascript <<‘END’
heredoc> tell application “Finder”
heredoc> get selection as text
heredoc> end tell
heredoc> END
Are you talking about some kind of test suite for AppleScript?
Perhaps if you could explain exactly what you are trying to do or where your example code came from it could be straightened out - as it is it won’t run, and looks like a Terminal command running a shell script to run an AppleScript that is trying to do something with Terminal, followed by what looks like remnants from Python or maybe Swift.
There is also an empty idle handler in there, which is used in stay-open applications - is this something that is being converted from a different script or scripting language?
FWIW, the following is the definition of the reopen command from the AppleScript Language Guide (here).
Many applications also support the reopen command, which reactivates a running application or launches it if it isn’t running. If the application is already running, this command has the same effect as double-clicking the application icon in the Finder. Each application determines how it will implement the reopen command—some may perform their usual startup procedures, such as opening a new window, while others perform no additional operations.