• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: echoing multi-lines output from "do shell script"
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: echoing multi-lines output from "do shell script"


  • Subject: Re: echoing multi-lines output from "do shell script"
  • From: Jocelyn Granger <email@hidden>
  • Date: Mon, 31 May 2004 06:17:12 -0700

Richard, does this script help you? Save it as an application, and request the "Stay Open" option.
When text is added to the Terminal window, the script displays the text that was added.
Also, you wanted the AppleScript to indicate when the shell script was done. This script checks for
the text "Script done". You can change the AppleScript to check for whatever message the shell script
actually echoes when it's done.

Is this what you needed?

Jocelyn Granger

Here's the script:

(* Before you run this script, make sure that, in the last line of the Terminal window, characters were not
added and then subsequently deleted. If you add and then delete characters to the last line of the
Terminal window, that could mess up the count of the number of characters in the window. *)

property old_text : " "
property new_text : " "

-- Initialize new_text
tell application "Terminal"
set new_text to contents of window 1
end tell

on idle

-- Save the old terminal text, and set the new text to the current value
set old_text to new_text
tell application "Terminal"
set new_text to contents of window 1
end tell

(* There are extra characters at the end of the Terminal window. These characters
mess up the count of the number of characters in the window. Therefore
we'll set each length to the position of the last character of the last word. *)

set length_old to length of old_text -- Initialize to the total length, including the extra chars at the end
repeat until character length_old of old_text is last character of last word of old_text
set length_old to length_old - 1
end repeat

set length_new to length of new_text -- Initialize to the total length, including the extra chars at the end
repeat until character length_new of new_text is last character of last word of new_text
set length_new to length_new - 1
end repeat

-- If text has been added to the Terminal window, output the text that was just added
if length_new > length_old then
set added_text to characters (length_old + 1) thru length_new of new_text
activate
display dialog "The following text has been added:" & return & return & added_text
end if

-- If the script echoes a message that indicates that it has finished
if new_text contains "Script done" then
activate
display dialog "The script is done."
end if

return 3

end idle
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.


  • Prev by Date: Need help in gui scripting
  • Next by Date: Re: echoing multi-lines output from "do shell script"
  • Previous by thread: Re: echoing multi-lines output from "do shell script"
  • Next by thread: Re: echoing multi-lines output from "do shell script"
  • Index(es):
    • Date
    • Thread