• 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: Interacting with external shell scripts
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Interacting with external shell scripts


  • Subject: Re: Interacting with external shell scripts
  • From: Skeeve <email@hidden>
  • Date: Sun, 24 May 2009 12:10:16 +0200

Anthony Adachi schrieb:
I'm sorry, I wasn't clear in my initial post but to clarify, I'm
wondering about interaction possibilities with a external shell script
from within a AppleScript Applet beyond simply invoking the whole shell
script via "do shell script" and getting it's last result.
As I already said in my first reply: You can do it with the Terminal Application.

As no one else took the ball, I just wrote a simple, none fool-proof proof of concept.

It will create some testfiles in /tmp/testdirectory and will then interactively (rm -i) remove them.

on run
-- first create some testfiles
do shell script "mkdir /tmp/testdirectory ; for n in a b c d e f ; do touch /tmp/testdirectory/$n; done"
-- start an interactive script
tell application "Terminal"
set the_tab to do script "echo start\\!;cd /tmp/testdirectory ; rm -i *; cd .. ; rmdir /tmp/testdirectory ; echo done\\!"
-- search for the starttoken of the script
set token to "start!"
repeat
repeat
-- get the history text
set h to (history of the_tab) as text
-- search the token
set lpos to offset of token in h
if lpos > 0 then exit repeat
-- wait and reatry if not found
delay 0.5
end repeat
-- if found get text behind token
set h to texts (lpos + (length of token)) thru -1 of h
-- search for the question
set npos to offset of "remove" in h
if npos > 0 then
-- if found, send the reply
do script "y" in the_tab
-- and get a new toke (i.e. the question)
set token to texts npos thru (npos + 8) of h
else if h contains "done!" then
-- if endtoken found, quit
exit repeat
end if
end repeat
end tell
end run


_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden
References: 
 >Re: Interacting with external shell scripts (From: "Anthony Adachi" <email@hidden>)

  • Prev by Date: Re: changing the "open with application" value for a file
  • Next by Date: Swap foreground and background windows
  • Previous by thread: Re: Interacting with external shell scripts
  • Next by thread: Xcode and applescript
  • Index(es):
    • Date
    • Thread