Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Make apple script wait for UNIX process to complete

Make apple script wait for UNIX process to complete
Thread Tools
Fresh-Faced Recruit
Join Date: Feb 1999
Location: London, UK
Status: Offline
Reply With Quote
Nov 30, 2002, 09:40 AM
 
I'm working on a little script to scp my calendar ICS files to a remote web server when I log in each morning.

Unfortunately, I'm finding the AppleScript syntax a little confusing, so what's below is as far as I've made it.

Any tips on how to do the following:

1. Set it only prompt me the first time I logic each day
2. Make it wait to quit the Terminal until it's finished scp'ing the calendars

would be much appreciate.

The script:

tell application "Finder"
display dialog "Synchronize Calendars?"
set mySync to the result
if the button returned of mySync is "OK" then
try
activate
with timeout of 60 seconds
tell application "Terminal"
activate
do script with command "/usr/bin/scp ~jreades/Library/Calendars/*.ics xxx@yyy.com:Calendars/"
end tell
idle
end timeout
end try
tell application "Terminal" to quit
end if
end tell
     
Mac Elite
Join Date: May 1999
Location: San Jose, CA
Status: Offline
Reply With Quote
Dec 1, 2002, 03:10 AM
 
First, scrub the 'tell application "Terminal"' wrapped.

You don't need to run this in the terminal. AppleScript will spawn a new shell to execute the command.

Therefore you'll end up with something like:

...
if the button returned of mySync is "OK" then
try
do script with command "/usr/bin/scp ~jreades/Library/Calendars/*.ics xxx@yyy.com:Calendars/"
end try

On that basis, and assuming you don't have any more code to add, you're all set. You don't need to wait for the timeout because you don't have any further commands to execute after the copy has finished.
Gods don't kill people - people with Gods kill people.
     
Mac Elite
Join Date: Mar 2001
Location: Provo, UT
Status: Offline
Reply With Quote
Dec 2, 2002, 04:40 PM
 
While not directly applicable to the example in question, I should add one more thing. If you've installed Fink then you have the program "expect" which you may run.

Expect basically just waits for some text from a shell command or text. If you used old terminal packages from the 80's, it is similar to the macros which waited for some stream of text to do something.

What this lets you do is act on text coming out of a command. Yes there are other ways to do this with Applescript, such as parsing the data. Further you can get elegant in languages such as Perl or Python for handing output. But this is a nice command for avoiding those complexities. Further sometimes for some interactive programs Applescript can't easily handle things.

There are no man pages for expect for some reason. However the home page covers a lot.

http://expect.nist.gov/

Combining expect with Applescript Studio allows you to quickly put front ends on a lot of Unix applications.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 06:24 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2