不創建應用程序,您需要將終端輸出寫入.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