Timm
Timm

Reputation: 169

Notification when Terminal is ready/finished - Applescript

is there a way to get notified when terminal finished a command?

-> I run another script(not mine!) which downloads data when this script finished I want to quit terminal and do other stuff with this data.

EDIT:
I may didnt ask correctly...

Example:


tell application "Terminal"
   keystroke "php downloadscript.php"
   keystroke return
end tell

if (downloadFinished) -- do stuff else -- wait till finished

Edit 2: Awesome! Thank you! Working like that:


tell application "Terminal"
    set frontWindow to window 1
    repeat until busy of frontWindow is false
        delay 1
    end repeat
    #display dialog "finished"
end tell
greetings hatschii

Upvotes: 8

Views: 6033

Answers (1)

Lri
Lri

Reputation: 27613

Terminal's Dock icon starts bouncing when a tab prints \a and the tab is not focused or Terminal is not frontmost:

sleep 5; printf '\a'

You could also run something like afplay /System/Library/Sounds/Blow.aiff. Or use terminal-notifier:

sudo gem install terminal-notifier
terminal-notifier -message ''

You can wait until a program finishes running by checking the busy property of a tab:

tell application "Terminal"
    set w to do script "sleep 5"
    repeat
        delay 1
        if not busy of w then exit repeat
    end repeat
end tell

Upvotes: 6

Related Questions