Wait for a "do shell script" command to finish

i have an applescript that has to call a few external applications. i currently do this by setting the exact syntax of the external command in a string variable, then issue a "do shell script cmd" (seen many examples across the net using this standard)
my applescript continues beyond these commands. how do i set the applescript to either wait for the above external command to finish, or not?
regards
jingo_man

Usually AppleScript will wait for a shell script to complete before it continues, but adding an ampersand (&) at the end of the shell script command will make it run in the background, which allows the AppleScript to continue. See Technical Note 2065: do shell script in AppleScript for more information.

Similar Messages

  • Beginner question - testing for null string from shell script command

    I'm trying to test the result of a shell script command. I want to put out a message if the result is a null string. At present I get this applescript error "The command exited with a non-zero status"
    I'm sure this is a simple question ... but I can't figure out how to do it. Help!

    You can use try clause for the problem:
    set _result to ""
    try
    set _result to do shell script "/blah/andblah"
    end

  • Which .bash does "do shell script" commands use?

    The "do shell script" command uses the Bourne shell "sh". But I am curious to know which .bash it uses to define the shell environment variables.
    I ran into a problem installing a third-party unix program which required new environment variables to be defined in order to execute. Defining these variables and executing this program from the terminal worked fine.
    But executing it within a "do shell script" command in an Applescript - the program died silently because the environment variables it required were not defined in the shell Applescript uses. It appears to invoke a new shell which does not inherit the environment variables defined in your home user shell.
    (I found this out by 'do shell script "set"' which listed the environment variables Applescript knows about - the ones I defined for the third-party program were not listed).
    A "brute force" way of fixing this is to pass the environment variables directly:
    do shell script "export THIRDPARTY_ENVVAR=blah; /usr/sbin/thirdpartyprogam"
    This works but not exactly elegant, particularly when you need to pass a number of variables.
    So - any better ways to do this? Can I edit the .bash Applescript uses, and where is it?
    Thanks.

    Another option that might work for you... if you are saving/distributing your AppleScript as an "Application bundler" is to group all your shell env. variables and other commands into a separate shell script file. Then include the shell script inside your app bundle. Locate the shell script at runtime and run that with "do shell script".
    For example, create "myShellScript.sh"
    #!/bin/sh
    export THIRDPARTY_ENVVAR=blah
    # ... more variable declarations..
    /usr/sbin/thirdpartyprogam
    # ... more shell commands...
    Store the shell script file inside your AppleScript bundle's Contents -> Resources folder (remember to make the shell script executable). Then your AppleScript can find your shell script at runtime and execute it like this:
    set ssPath to quoted form of POSIX path of (path to resource "myShellScript.sh")
    set stdout to do shell script ssPath
    Steve

  • Complex shell script command

    HI Experts
    can anybody know what this complex shell script command is doing .. i know its looking for some character at some point but exact explanation will be good for learning.
    egrep "^.{292}[CFOPRA][EPR]$" dn.dat
    Thanks

    A simple example can often demonstrate how things work:
    # cat sample.dat
    xABCDE1
    xABCDE2
    ABCDE3
    ABCDE4
    xDBCEA5
    xDBCEA6
    # egrep "^.A" sample.dat
    xABCDE1
    ABCDE4
    Above matches lines that begin with any character followed by an "A".
    # egrep "^.{2}A" sample.dat
    xABCDE2
    Above matches lines that begin with any 2 characters followed by an "A".
    # egrep "^.{2}[AD]" sample.dat
    xABCDE2
    xDBCEA6
    Above matches lines that begin with any 2 characters followed by an "A" or D".
    # egrep "^.{6}[345]$" sample.dat
    ABCDE4
    xDBCEA5
    Above matches any lines ending with "3", "4" or "5",
    provided it's the 7th character.
    # egrep "^.{5}[345]$" sample.dat
    ABCDE3
    Above matches any lines ending with "3", "4" or "5",
    provided it's the 6th character.
    # egrep "^.{6}[EA][26]$" sample.dat
    xABCDE2
    xDBCEA6
    Above matches any lines ending with combinations of "E2, E6, A2, A6",
    provided the combination starts at character position 7.
    {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Xgettext for perl and shell scripts on Solaris 9

    Hi......I have to internationalized perl and shell scripts on Linux and Solaris 9.
    I have used gettext on linux to internationalized both perl and shell scripts but on solaris i m not able to
    achieve the same.
    If we see help of xgettect on Linux, it shows input file options for Perl, Shell, C, C++ etc but help for
    xgettext on Solaris shows input file option for C only.
    Can you please provide me some way of using xgettext for perl and shell scripts on Solaris 9 or
    is there any other way of internationalizing perl and shell scripts on Solaris 9.
    Many Thanks,
    Lokesh

    Signature link blocked.
    db
    Contentprise wrote:
    Hi......I have to internationalized perl and shell scripts on Linux and Solaris 9.
    I have used gettext on linux to internationalized both perl and shell scripts but on solaris i m not able to
    achieve the same.
    If we see help of xgettect on Linux, it shows input file options for Perl, Shell, C, C++ etc but help for
    xgettext on Solaris shows input file option for C only.
    Can you please provide me some way of using xgettext for perl and shell scripts on Solaris 9 or
    is there any other way of internationalizing perl and shell scripts on Solaris 9.
    Many Thanks

  • How to prepare for Converting UNIX shell scripts to PL/SQL

    Hi All
    I was said, that i may have to convert a lot of unix shell script to PL/SQL, what are the concepts i need to know to do it efficently,
    what are the options PL/SQL is having to best do that.
    I know the question is little unclear, but I too dont have much inputs about that i'm sorry for that, just its a question of how
    to prepare myself to do it the best way. What are the concepts i have to be familiar with.
    Many Thanks
    MJ

    Just how much work is involved, is hard to say. Many years ago I also wrote (more than once) a complete ETL system using a combination of shell scripts, SQL*Plus and PL/SQL.
    If the PL/SQL code is fairly clean, uses bind variables and not substitution variables, then it should be relatively easy to convert that PL/SQL code in the script to a formal stored procedure in the database.
    There is however bits and pieces that will be difficult to move into the PL/SQL layer as it requires new software - like for example FTP'ing a file from the production server to the ETL server. This can be done using external o/s calls from within PL/SQL. Or, you can install a FTP API library in PL/SQL and FTP that file directly into a CLOB and parse and process the CLOB.
    Think of Oracle as an o/s in its own right. In Oracle we have a mail client, a web browser, IPC methods like pipes and messages queues, cron, file systems, web servers and services, etc. And PL/SQL is the "shell scripting" (times a thousand) language of this Oracle o/s .
    In some cases you will find it fairly easy to map a Unix o/s feature or command to one in Oracle. For example, a Unix wget to fetch a HTML CSV file can easily be replaced in Oracle using a UTL_HTTP call.
    On the other hand, techniques used in Unix like creating a pipe to process data, grep for certain stuff and awk certain tokens for sed to process further... in Oracle this will look and work a lot different and use SQL.

  • Wait for process before continuing script

    Hey there,
    Just been working on this for a bit now in script editor. I'm still really new to the script editor functions, but would like some direction. If automater is a alternative then please help me understand how to make it work with that.
    Otherwise all help is greatly appreciated!
    Goal of the script:
    1) load disk image. (This works)
    2) open application requiring disk image. (This works)
    3) Check to see in app process is running: running --> wait till it is not, when not running --> eject above disk image
    Code:
    tell application "Finder" -- Note when using tell Finder it gives can't get running of process
              if process "App Process" is not running then
                        set bootDisk to name of startup disk
                        set otherDisks to every disk whose (name is not bootDisk) and (name is not "iTunes") and (name is not "Applications") and (name is not "BOOTCAMP")
                        repeat with myDisk in otherDisks
                                  try
      eject myDisk -- When using tell System Events it give Expected end of line but found identifier on line.
                                  end try
                        end repeat
              end if
    end tell
    Another: Oddly the script will run the app, it throws the error while running, but the app still runs. The disk Image is also gone.
    Thanks again for any helpful comments and direction.
    -- Josh

    Okay, Neil and tw^3, thanks you for your help, I got the effect I wanted cleaned up the code a smidge.
    Code:
    tell application "Finder"
              open document file "DiskImage" of folder "GAMES" of disk "Applications"
        delay 2 & close every window
              open application file "App" of folder "Myth2" of folder "GAMES" of disk "Applications"
    end tell
    delay 4.5
    tell application "System Events"
              repeat
                             if not (exists process "process") then
                                            if exists "DiskName" then
                                                           do shell script "hdiutil detach \"/Volumes/DiskName\""
                      error number -128 --
                end if
                             end if
           if exists (process "process") then
           end if
           delay 10
              end repeat
    end tell
    Last little question about what I have, in the if statement checking if the process does not exist anymore, I put quit after the shell script to eject. but it would just hang there. Would it be better to do a repeat while? or would you just user cancel (error -128) the script from executing like I have it.
    -Josh
    EDIT: made it work better, used a repeat while... and moved the if not exists after the repeat...
    repeat while exists "app process"
    end repeat
    if not (exists process "app process")
    ......blah blah code code
    end if

  • Passing dialog text to a shell script command

    Hi. Newbie here. I got a good book, will learn this sooner or later.
    But right now, I got a problem I can't figure out
    I'd like to display a dialog box that requests some text. I'd then like to use that text as the variable for a shell commmand.
    Let's say for instance that I want to prompt for the asset tag number of the machine and want the result to end up in the ARD Info 1 field. I've got the first and third line, just don't know how to "place" the captured text:
    display dialog "What is this Mac's assett tag number?" default answer ""
    do shell script "defaults write /Library/Preferences/com.apple.RemoteDesktop Text1 <resultfrom_dialoghere>"
    Anyone?
    Darrin

    You use text returned of:
    dialog reply n : Reply record for the ‘display dialog’ command
    properties
    button returned (Unicode text, r/o) : name of button chosen (empty if ‘giving up after’ was supplied and dialog timed out)
    text returned (Unicode text, r/o) : text entered (present only if ‘default answer’ was supplied)
    gave up (boolean, r/o) : Did the dialog time out? (present only if ‘giving up after’ was supplied)
    ex:
    set _result to text returned of (display dialog "What is this Mac's assett tag number?" default answer "")
    do shell script "defaults write /Library/Preferences/com.apple.RemoteDesktop Text1 " & quoted form of _result

  • Automtor shell script "command not found"

    I want to include the execution of a shell script in Automator. The script just executes a third-party application (actually, pdftk) with certain parameters. I have written the script, saved it in my Home directory as "foo.sh", made it executable, and can correctly call it from Terminal with ./foo.sh. It works as expected.
    But if I include it in Automator's workflow, into action "Run shell script", its execution breaks complaining that "pdftk: command not found". This indicates that the script is correctly found and read by Automator. How is it, that Terminal's bash can find the command, but Automator doesn't ? Have commands to be written in a special way to be understood by Automator ? Perhaps third-party commands are not allowed in Automator ?

    As twtwtw has said, you environment when running Automator is NOT the same as when you are in a Terminal session.
    pwd:
    /Users/harris
    /bin/ls -dlaeO@ .
    drwxr-xr-x  349 harris  harris  - 11866 Mar 14 22:06 .
    id -a:  uid=501(harris)
    gid=501(harris)
    groups=501(harris),
    204(_developer),
    100(_lpoperator),
    98(_lpadmin),
    80(admin),
    61(localaccounts),
    12(everyone)
    $# 0
    printenv: SHELL=/bin/bash
    TMPDIR=/var/folders/zv/zvU6+bMiHTeElG+JIWOdzk+++TI/-Tmp-/
    Apple_PubSub_Socket_Render=/tmp/launch-rVMvHQ/Render
    USER=harris
    COMMAND_MODE=unix2003
    SSH_AUTH_SOCK=/tmp/launch-fH4Gt7/Listeners
    __CF_USER_TEXT_ENCODING=0x1F5:0:0
    PATH=/usr/bin:/bin:/usr/sbin:/sbin
    PWD=/Users/harris
    DBUS_LAUNCHD_SESSION_BUS_SOCKET=/tmp/launch-RIPIu6/unix_domain_listener
    SHLVL=1
    HOME=/Users/harris
    LOGNAME=harris
    DISPLAY=/tmp/launch-ttdbVO/org.x:0
    FRED=3-Mar-2009
    _=/usr/bin/printenv

  • Shell scripts commands

    Hello.
    I'm having my first contact with Oracle Retail and I'm doing some shell scripts to extract/transform/load data.
    I was checking some scripts and I saw some commands as rmse_terminate, message, verifybinary, _call.
    Do you know where I can find some document explaining these commands and providing others if exist?
    Today I'm working with AIP, RDF and RMS.
    Let' me know if you can provide me a link or other path where I can find the document
    Thanks
    Edson

    Hi Ahmed,
    Can you please mention the names of the scripts where you found these calls, and the application to which those scripts belong to?
    Erik

  • Shell script Command Merge

    Can anyone help me to merge two commands into a single command
    1. cd ../../https-eportaldevw5/logs | cat pid
    2. ps -ef | grep $pid
    note-This $pid will be the output of command 1

    Thanks.. that was really helpful to me..
    one more question..
    when I am executing multiple commands one after another in a single go then one of the in-between command is not executed and skipped without execution.
    Example:
    echo "************************ SCC *****************************" > /tmp/output/op1.txt
    ps -ef | grep $(cat /opt/netscape/iPlanet/https-eportaldevw5/logs/pid) >> /tmp/output/op1.txt
    echo "****************** GLS ********************" >> /tmp/output/op1.txt
    ps -ef | grep $(cat /opt/netscape/iPlanet/https-eportaldevw3/logs/pid) >> /tmp/output/op1.txt
    echo "****************** TE Corporate ********************" >> /tmp/output/op1.txt
    ps -ef | grep $(cat /opt/netscape/iPlanet/https-eportalpoc/logs/pid) >> /tmp/output/op1.txt
    echo "****************** GCT ********************" >> /tmp/output/op1.txt
    ps -ef | grep $(cat /opt/netscape/iPlanet/https-eportaldevw1/logs/pid) >> /tmp/output/op1.txt
    echo "****************** eCommerce ********************" >> /tmp/output/op1.txt
    ps -ef | grep $(cat /opt/netscape/iPlanet/https-eportaldevw6/logs/pid) >> /tmp/output/op1.txt
    echo "****************** IMO ********************" >> /tmp/output/op1.txt
    ps -ef | grep $(cat /opt/netscape/iPlanet/https-eportaldevw7/logs/pid) >> /tmp/output/op1.txt
    echo "****************** ADR ********************" >> /tmp/output/op1.txt
    ps -ef | grep $(cat /opt/netscape/iPlanet/https-eportaldevw8/logs/pid) >> /tmp/output/op1.txt
    echo "****************** Corporate Trust Portal Server ********************" >> /tmp/output/op1.txt
    ps -ef | grep $(cat /opt/netscape/iPlanet/https-eportaldevw13/logs/pid) >> /tmp/output/op1.txt
    echo "****************** Corporate Trust App Server********************" >> /tmp/output/op1.txt
    ps -ef | grep $(cat /opt/netscape/iPlanet/https-eportaldevw14/logs/pid) >> /tmp/output/op1.txt
    echo "****************** GMW ********************" >> /tmp/output/op1.txt
    ps -ef | grep $(cat /opt/netscape/iPlanet/https-eportaldevw4/logs/pid) >> /tmp/output/op1.txt
    cat /tmp/output/op1.txt
    In above example,
    echo "****************** Corporate Trust App Server********************" >> /tmp/output/op1.txt
    this command is skipped when I am executing all commands in a signle go..
    Can anyone suggest me anything in this.

  • Startup shell script help for newbie?

    New to UNIX (linux)... need the bash shell script commands for my r.c local file to start my services when server boots.
    I got my ds, dps and admin server in their respective /opt directories. I need the shell commands to have these start. Of course I can start them manually but when I try a line like this in a script, it doesnt work:
    ./var/opt/sun/directory-server/slapd-dsserver/start-dsserver
    Some path problem or dot thing?

    There are a few other things you may want to consider, such as what the default browser is, are tabs being used, is the page loaded yet, etc, but Safari has a do javascript command in it's scripting dictionary. The following script will open a new document and run your specified javascript, or you can go to their NPR Program Stream Page and download a playlist that will run directly from iTunes.
    <pre style="
    font-family: Monaco, 'Courier New', Courier, monospace;
    font-size: 10px;
    margin: 0px;
    padding: 5px;
    border: 1px solid #000000;
    width: 720px; height: 335px;
    color: #000000;
    background-color: #FFDDFF;
    overflow: auto;"
    title="this text can be pasted into the Script Editor">
    set my_script to "NPR.Player.openPlayer(2, 0, '03-21-2008', NPR.Player.Action.PLAY_NOW, NPR.Player.Type.PROGRAM, NPR.Player.Mode.LIVE)"
    tell application "Safari"
    activate
    set the URL of the front document to "http://www.npr.org/"
    if my page_loaded(20) is false then error numner - 128 -- page not loaded in time
    do JavaScript my_script in document 1
    end tell
    on page_loaded(timeout_value) -- from http://www.apple.com/applescript/archive/safari/jscript.01.html
    delay 2
    repeat with i from 1 to the timeout_value
    tell application "Safari"
    if (do JavaScript "document.readyState" in document 1) is "complete" then
    return true
    else if i is the timeout_value then
    return false
    else
    delay 1
    end if
    end tell
    end repeat
    return false
    end page_loaded
    </pre>

  • Java GUI for a shell script

    I have a file with passwd format.I made a script for this file that is working as I wanted it to work.I have a list of options and each time I give an option,the script is doing something(for example,if I press "b" it makes something and if I press "a" it makes something else).All the results are an output from the file.
    My question is how can I create a GUI in java for this script.For example if I want the script to do what it would do if I pressed the "a" button on my keyboard,but not by pressing "a",but by choosing from a drop down list or some other graphical feature(by ticking a check box,clicking a button etc).Can I do this with java?
    Lazaros

    Hi,
    I understand you can create a Java Swing gui for a bash shell script which takes both complex input and writes output to the stdout & files, to be specific. Is that correct?
    If yes, could you give a simple example. Say for the following shell script.
    #!/bin/sh
    printf "Enter input\n"
    i=0
    while [ $i -ne 1 ]; do
    read $inputVar
    if [  "$inputVar" == "y" ]; then
    printf "You typed yes\n"
    i=1
    elif [  "$inputVar" == "y"  ]; then
    printf "you typed no\n"
    i=1
    else
    printf "Enter a valid character\n"
    i=0
    fi
    done
    Could you also point to some URL's which might help? Googling for "Java Gui for shell script" returns this as the first page, others dont really help. Googling "GUI for shell script" returns all other gui toolkits for xes but thats not what I want. I want a cross platform (nixes, Win*, MacOS* ) gui for a shell script ( which I plan to run using cygwin etc).
    TIA
    Vinod

  • Starting and stopping an SQL query from within a Shell script

    DB version:10gR2
    OS Version:AIX
    We have a C++ application called WpnCreate.cpp, which is causing some locking problems.
    So, we have decided to capture(using SPOOL) the locking info(session info, blocking program,..etc) using an SQL query.
    WpnCreate.cpp program is initiated by a shell script. So we need this SQL query(.sql) to start firing just before WpnCreate.cpp is called and when WpnCreate.cpp has finished executing, we need the SQL query execution to stop.
    But how do i stop the sql query execution? Should i capture the session id and serial# of this session and use kill -9 at the end of the shell script?
    Flow of the Shell script should be like this
    Step1. Start firing the SQL query which captures the locking info and SPOOL them to a file
    Step2. Execute WpnCreate.cpp program
    Step3. Stop the firing of SQL query once WpnCreate.cpp has finished executing ( i don't know how)How will i go about achieving this?

    How can you run your step 2 untill & unless your step 1 gets over. You can run in background but then it will not capture the correct information.
    I think you need to run your step 1 after step 2 , then only you will be able to capture the information.
    You can run your C++ program in background and can wait for some time using sleep command and then run the query to check the locking information.

  • Input to a shell script

    Hey guys,
    I was wondering let's say I have a text field called "text field"
    I need the contents of it on a click of a button to go to a do shell script "stuff stuff/ stuff stuff/ (content from text field here)/ stuff stuff" Some thing of this sort. Hope this makes sense, Thanks a lot, Max

    Thanks for the response Ed! I still can't seem to get it to work. Let me explain in a little more detail what I need to happen, any help would be great!
    I have an app that starts a server from a do shell script command.
    It technically never ends, and it it constantly outputting data. As a result when I run the program, the server starts and runs fine, but the program locks up because it is waiting for the command to end. Is there a way I can get the data to go somewhere, I don't need to look at it so it could just disappear.
    Here is my code:
    on clicked theObject
    if theObject is button "Start" of window "Window" then
    set serverName to content of text field "servername" of window "Window"
    set adminPass to content of text field "adminpass" of window "Window"
    set serverPassword to content of text field "serverpassword" of window "Window"
    set botsTrue to state of button "bots" of window "Window"
    set statsTrue to state of button "stats" of window "Window"
    set serverPass to state of button "serverpass" of window "Window"
    set shellScript to "/Applications/Zap\\!\\ Folder/ZAP.app/Contents/MacOS/ZAP -dedicated -hostname " & serverName
    set shellScript to shellScript & " -adminpassword "
    set shellScript to shellScript & adminPass
    if botsTrue = 1 then set shellScript to shellScript & " -bots"
    if statsTrue = 1 then set shellScript to shellScript & " -stats"
    if serverPass = 1 then set shellScript to shellScript & " -password "
    if serverPass = 1 then set shellScript to shellScript & serverPassword
    do shell script shellScript
    display dialog shellScript
    end if
    end clicked
    Thanks a lot!

Maybe you are looking for

  • Contracts Dislplay in SC

    Hi all, So, in our implementation currently, if you have a contract for an item or product catagory, the system will automatically assign the contract to an item in the SC, on item level it will also change the price.  This is expected, but if you ha

  • Javax.servlet.ServletException: 115682-------------jsf problem

    I have this code , some time it works ,some time not, i am not getting where is the problem *************************************start code*************************************************** <body> <f:view> <h:form id="viewForm"> <b><p align="center"

  • Problem with an ALC-WKS-007-040 error

    Hi all, I'm trying to develop a BP with forms in XDP. However this does not work as I get an ALC-WKS-007-040 error when I try to render the form in Workspace. I have tried to set up the renderPDF instead of the default renderer, but I still get an er

  • New logic pro user ! pls help

    Hi Everyone I just upgraded to logic pro , from a logic 6 os9 system..Previously, if i right clicked outside an audio file (in the arrange window) and then dragged around the file, it would zoom in on the audio file (and if i right clicked again, the

  • Disc Read Error Ctr + alt + Delete

    When I booted up my computer today with a black screen it says Disc Read Errir Ctr + alt + Delete. I restart it as it asks only to end up back at the same screen shortly after. Is something wrong with the Hardware of my computer? I unplugged any USB