不创建应用程序,您需要将终端输出写入.txt或日志文件,然后读取它。
因此,定义txt文件:
set temp_file to quoted form of (POSIX path of (path to temporary items from user domain) & "logger.txt")
然后创建文本文件,并写入端子输出:
try
do shell script "rm -f " & temp_file
end try
do shell script "touch " & temp_file
do shell script "do something " & " | tee " & temp_file
得到的AppleScript来读取文件,把每行到一个列表项:
set the_output to my get_lines()
on get_lines()
set temp_file to (POSIX path of (path to temporary items from user domain) & "logger.txt")
set logs to paragraphs of (read temp_file)
set line_count to count of logs
set line_items to {}
repeat with i from 1 to line_count by 1
if (i + 0) is not greater than line_count then
set end of line_items to items i thru (i + 0) of logs
else
set end of line_items to items i thru line_count of logs
end if
end repeat
return line_items
end get_lines
找到你的“确定输出”并拉动触发器...
repeat with n from 1 to (count of the_output)
set str to text of (item n of the_output) as string
if str starts with "TEXT TO LOOK FOR" then
do something
end if
end repeat
你是如何运行脚本的? –
目前通过Apple脚本编辑器启动它。整个过程在远程服务器上运行,理论上运行脚本可以每5分钟检查一次终端的状态并在需要时运行脚本。 – user3414803