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

Similar Messages

  • 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

  • Passing AppleScript string variable to shell script

    I have a script which uses the md5 command line utility to make convenient-sized hashes of some very long strings. Right now I save each string in a temporary text file which is then referenced in the command line:
    set hash to do shell script "md5 -q" & space & quote & POSIX path of tempFile & quote
    This works well, but I wonder if it isn't a little inefficeint, re-writing the temporary file with each new string. md5 has a -s option, which allows the string data to be placed directly in the command line:
    set myText to "Hello World"
    set hash to do shell script "md5 -q -s" & space & quote & myText & quote
    I know that if I do it this way I have to be careful to "escape" all occurrences of quote characters within myText to avoid command line syntax problems. This would not be difficult (in fact, it has already been done for another reason), but I have two questions:
    (1) Are there any other ASCII characters that would have to be similarly escaped? I've tried strings with line breaks in them: Mac-, Unix-, and Windows-style breaks, and they all seem to work, but are there any hidden dangers to doing this?
    (2) myText can get very long: say, 10,000 characters or more, so the command line would be correspondingly long. Is there any kind of limit on the length of command lines in the particular species of UNIX that is running under the Mac hood?
    Many thanks.
    Dual 1.2 GHz   Mac OS X (10.4.8)  
    Dual 1.2 GHz    

    >(1) Are there any other ASCII characters that would have to be similarly escaped? I've tried strings with line breaks in them: Mac-, Unix-, and Windows-style breaks, and they all seem to work, but are there any hidden dangers to doing this?
    There are many characters that can fall foul of a do shell script command, which is why Apple gave a convenient way of handling it via quoted form of:
    <pre class=command>set myText to "Hello World"
    set hash to do shell script "md5 -q -s "  & quoted form of myText</pre>
    This will take care of escaping various characters that might confound the shell.
    >(2) myText can get very long: say, 10,000 characters or more, so the command line would be correspondingly long. Is there any kind of limit on the length of command lines in the particular species of UNIX that is running under the Mac hood?
    It varies by OS version, but 262,000 bytes is the technical limit.

  • Pass the text file name to the command prompt using servlet

    hi to all,
    I have a HTML page that takes the user inputs. Once the user clicks on the submit button on the HTML page, these values will be capture by a servlet and then store into a text file. A new text file is generated each time the user clicks on the submit button.
    Now, i need to call a command prompt window and then pass the text file name to another program for execution. Any idea how i can pass the text file name to the command prompt???
    Thanx a lot....
    kinki

    hi, thanx 4 ur reply.
    But i not onli want to display the file name on the Tomcat command prompt. I must also able to call up a program to execute the command. If i used System.out.println(); it onli display the value on the console windows. But not executing it... anyway where i can do it???.
    thanx...
    Kinki

  • Is it possible to pass a variable from a shell script back to an Automator action?

    Is it possible to pass a variable from a shell script back to an Automator action?
    For instance, if I assign a value of foo to $var1 in my shell script how would I retrieve/pass that value in the next Automator action. I see that there is a variable called "Shell Script" but I can't any information on how to use it. 

    red_menace,
    Thanks but I still don't understand how to pass a single value that was set in the UNIX scipt back to Automator has a variable. Take the example below, I write 4 varables to STDOUT and all 4 are stored in a variable named "storage".  How do I assign 1 of these values to the Automator "storage" variable? For instance if I wanted to assign the value of $var2 to "storage" , how would I do that?

  • 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.

  • 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

  • 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}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Can a java app pass values to a c-shell script?

    hello everyone,
    I'm running a shell script that executes a java app.
    I need to pass values from the java app to the shell script, such that I can code
    java myapp
    echo <value1>
    echo <value2>where value1 and value2 have been set in the app.
    is there a way to do this?
    Thanks for your help.
    Tom

    Wira, I've tried this, and can't get it to work. The
    problem may be that Runtime.getRuntime().exec() is
    running the script on a separate process(?), Yep.
    and I
    never see any output in the same context as the
    script that's running the java app.
    I've tried this from the command line as well, and I
    don't see any output from the script being called
    from the java app.
    I know the script is being run, because if I change
    the script name to a name that doesn't exist, I get
    an ioexception, when I change it back everything runs
    ok.
    Note that I'm testing this under XP with batch files;
    eventually it will run on unix.
    does that make a difference right now?Forget java for right now.
    Start working on a way for the script to hoist the values into itself.
    For example if the script calls another script which does the echo what happens?
    Or can you call another script, set some env variables, and then see them in the original script?

  • Echo colored text in a shell script?

    As part of a shell script I'm working on, I want to be able to print colored (preferably red) text to the Terminal window, to provide warnings to the user.
    How can I code in echoing colored text?
    (I did some googling and couldn't find anything that seemed to apply to what I want to do.)
    Any help would be appreciated!
    Thanks in advance!

    The following is a shell script that displays the terminal colors and the escape sequences used to generate them:
    #!/bin/sh
    # colors.esc - display the terminal colors and the escape sequences that
    # generate them. "Blink" is _NOT_ shown, as it is a very
    # annoying effect, and should be avoided at all costs in normal
    # daily uses.
    # Usage: colors.esc [12 character or less display string]
    # Bob Harris
    E=$(printf ' ') # escape <E>
    R="${E}[0m" # reset <E>[0m
    typeset dsp_str=""
    typeset dsp_txt
    typeset fg_text
    typeset bg_text
    if [[ $# != 0 ]]; then
    dsp_str=$(printf "%12.12s" "$*")
    fi
    color=(Black Red Green Yellow Blue Magenta Cyan White)
    for bg in "" 0 1 2 3 4 5 6 7 # for each background color
    do
    b=$bg && [[ X$b != X ]] && b="4$b;" # deal with no background color ""
    echo " ------------ ----bold---- -underline-- --reverse---"
    for fg in 0 1 2 3 4 5 6 7 # for each foreground color
    do
    f="3$fg" # setup foreground color
    line=""
    for a in "" 1 4 7 # for each attribute
    do
    [[ X$a != X ]] && a=";$a" # deal with no attribute ""
    if [[ -z "$dsp_str" ]]; then
    dsp_txt=$(printf "%12s" "<E>[${b}${f}${a}m") # build esc text
    else
    dsp_txt="$dsp_str" # use supplied text
    fi
    line="${line}${E}[${b}${f}${a}m${dsp_txt}${R} " # build entry
    done
    fg_text=$(printf "%-7s" ${color[$fg]}) # translate foreground color
    bg_text=$(printf "%-9s" "Bg${color[$bg]}") # translate background color
    [[ X$b = X ]] && bg_text=$(printf "%-9s" " ") # no bckgnd color
    line="$bg_text $fg_text $line" # build final display line
    echo "${line% }" # display the colorized line
    done
    done
    echo " ------------ ----bold---- -underline-- --reverse---"
    bg_text=$(printf "%-9s" " ")
    fg_text=$(printf "%-7s" "Reset")
    dsp_txt=$(printf "%12s" "<E>[0m")
    line="$bg_text $fg_text $dsp_txt" # build final display line
    echo "${line% }"

  • How to pass arguments to a Unix shell script from PL/SQL?

    We want to run a Linux shell script from PL/SQL (10g). This is our code to run the script only and it works fine.
    dbms_scheduler.create_job
              job_name=>'RUN_LINUX_SCRIPT_' || v_job_name,
              job_type=>'EXECUTABLE',
              job_action=>'/vol0/FileLoadDir/Bank/DATA_FILES/spell_check.sh',
              enabled=>TRUE,
              auto_drop=>FALSE
            );Now we have a requirement to pass 2 arguments to the .sh file. In the .sh file the 2 arguments are defined as $1 and $2.
    I used this method.
    dbms_scheduler.create_job
              job_name=>'RUN_LINUX_SCRIPT_' || v_job_name,
              job_type=>'EXECUTABLE',
              job_action=>'/vol0/FileLoadDir/Bank/DATA_FILES/spell_check2.sh',
              --job_action=>'/vol0/FileLoadDir/Bank/DATA_FILES/spell_check2.sh /vol0/FileLoadDir/Bank/DATA_FILES/ebill2.fmt_form_strings_.txt /vol0/FileLoadDir/Bank/DATA_FILES/abcdefghij.txt',
              --job_action=>'#!/bin/bash spell /vol0/FileLoadDir/Bank/DATA_FILES/ebill2.fmt_form_strings_.txt > /vol0/FileLoadDir/Bank/DATA_FILES/abcde.txt',
              number_of_arguments => 2,
              enabled=>FALSE,
              auto_drop=>FALSE,
              comments => 'Testing by Channa'
          DBMS_SCHEDULER.SET_JOB_ARGUMENT_VALUE (
            job_name                => 'RUN_LINUX_SCRIPT_' || v_job_name,
            argument_position           => 1,
            argument_value          => '/vol0/FileLoadDir/Bank/DATA_FILES/ebill2.fmt_form_strings_.txt');
          DBMS_SCHEDULER.SET_JOB_ARGUMENT_VALUE (
            job_name                => 'RUN_LINUX_SCRIPT_' || v_job_name,
            argument_position       => 2,
            argument_value          => '/vol0/FileLoadDir/Bank/DATA_FILES/abcdefghij.txt');
          DBMS_SCHEDULER.enable (name => 'RUN_LINUX_SCRIPT_' || v_job_name);But I get an error saying:
    STANDARD_ERROR="/vol0/FileLoadDir/Bank/DATA_FILES/spell_check2.sh: line 4: read: `/vol0/FileLoadDir/Bank/DATA_FILES/ebill2.fmt_form_strings_.txt': not a valid identifier
    /vol0/FileLoadDir/Bank/DATA_FILES/spell_check2"

    Check this post:
    pass parameter from PL/SQL to Unix "as is"

  • Passing a parameter to a shell script through concurrent program

    Hi All,
    I am trying to pass a runtime parameter from oracle application to a shell script which inturn calls a sql script. The parameter iam passing has a space for example. iam passing something like "Customer 1" so how does the shell script interpret this parameter. Any ideas are appreciated.
    Thanks,

    You may need to read the input parameters first, e.g.:
    set file [lindex $argv 0]
    Then: send "put $file\r"
    There is a good example at http://en.wikipedia.org/wiki/Expect

  • Passing paramter from ANT to shell script doesn't seems to work for me;Help

    Hi,
    what iam "trying" to do is to pass some variables from my ANT script to a shell script. This is what iam doing with my 3 files. Iam getting errors when iam doing this.
    1) build.xml file:
    <?xml version="1.0" encoding="iso-8859-1"?>
    <project name="dev" default="all" basedir=".">
        <!-- (2) Create the class path -->
        <path id="common.class.path">
            <pathelement
    location="/opt/bea/weblogic81/server/lib/weblogic.jar"/>
        </path>
        <!-- create a reference for the class path utilized -->
        <property file="./myAnt.properties"/>
        <property name="common.class.path" refid="common.class.path" />
        <property name="Deploy.scripts.folder" value=
    "/opt/bea/weblogic81/server/bin/applicat
    ions" />
        <property name="1" value="${ANTPATCH}" />
        <property name="2" value="${WEBLOGICJAR}" />
        <property name="3" value="${ADMINPORTNUMBER}" />
        <property name="4" value="${HOSTNAME}" />
        <target name="xyz">
            <echo message="***********deployment**********"/>
            <property name="general.deployment.script.name"
    value="${general.script}" />
        </target>
        <target name="sangitatest">
            <echo message="This is the TESTNET box"/>
            <exec dir="${Deploy.scripts.folder}"
    executable="${Deploy.scripts.folder}/${genera
    l.deployment.script.name}" />
            <arg line="${1}"/>
            <arg line="${2}"/>
            <arg line="${3}"/>
            <arg line="${4}"/>
        </target>
        <target name="all" depends="xyz,sangitatest" />
    </project>---------------------------------------
    2) myAnt.properties file:
    general.script=deployScript.sh
    ANTPATCH=/opt/bea/wlserver6.1/lib/latest_deploy.jar
    WEBLOGICJAR=/opt/bea/wlserver6.1/lib/weblogic.jar
    ADMINPORT-NUMBER1=7001
    HOSTNAME=reliant2-----------------------------------------
    3) deployScript.sh file:
    export ANTPATCH=$1
    export WEBLOGICJAR=$2
    export ADMINPORTNUMBER=$3
    export HOSTNAME=$4
    java -cp "$ANT-PATCH":"$WEBLOGIC-JAR" weblogic.deploy -port
    "$ADMIN-PORT-NUMBER" -host "$HOSTNAME" -component testMon:beamon_biko_s1 deploy
    weblogic testMon /export/home/san5sxs/applications/beamon/myfile.war-------------------
    and the Exception is:
    [echo] This is the TESTNET box
    [exec] /opt/bea/weblogic81/server/bin/applications/deployScript.sh: ANTPATCH=: is not an identifier
    [exec] Result: 1
    BUILD FAILED
    file:/opt/bea/weblogic81/server/bin/build.xml:30: Could not create task or type of type: arg.
    Ant could not find the task or a class this task relies upon.
    any help in this matter ??
    regards,
    sangita

    Have you looked at [url http://ant.apache.org/]ant's website
    That's apache's ant. I'm not sure if there are others or not.
    if so, here is the mailing list [url http://ant.apache.org/mail.html]info

  • Passing variable from sql to shell script

    Usually we can pass arguments from shell script to the sql that us called inside the shell script. But I also want to do the reverse. I have the location of my backup path in a table. I want to run the rman script (shell), read this parameter from the table and use this to construct the "format" path in rman. Anyone has any ideas about this. Thanks.

    To achieve getting the modified value from the table everytime the job runs, I encapsulated this in another job.
    BEGIN
    DBMS_SCHEDULER.CREATE_JOB(
    JOB_NAME           => 'TEST_LOGS_MAIN',
    JOB_TYPE             => 'PLSQL_BLOCK',
    JOB_ACTION          => 'declare
    v_aname varchar2(32);
    begin
    select aname into v_aname from attr where attrid = 3;
    DBMS_SCHEDULER.CREATE_JOB(
    JOB_NAME        => ''TEST_LOGS'',
    JOB_TYPE        => ''EXECUTABLE'',
    JOB_ACTION      => ''/opt/sql/testy.sh'',
    number_of_arguments => 1,
    COMMENTS        => ''TEST'');
    dbms_scheduler.set_job_argument_value(''TEST_LOGS'',1,v_aname);
    dbms_scheduler.enable(''TEST_LOGS'');
    end;',
    REPEAT_INTERVAL => 'FREQ=MINUTELY',
    ENABLED           => TRUE);
    END;
    /

  • 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

Maybe you are looking for

  • Pages 5.0.1 crashes (not font related?)

    Hello, Pages 5.0.1 reliably crashes when trying to open a document that it has created itself (the program itself opens without crashing). To clarify, I can create a new document (call it Doc1), via a template or just blank, and work on it, etc., wit

  • Mail will not shut down so mac stays on

    Mail stops mac shutting down.

  • FOX Formula definition

    Greetings All!!! I am recieving an error Types of parameter RATE (P) and variable RATE1(F) are inconsistent .. I am using following FOX code DATA FISC_VAR TYPE 0FISCVARNT. DATA FISCYEAR TYPE 0FISCYEAR. DATA RATE1 TYPE F. FOREACH FISCYEAR. CALL FUNCTI

  • Once new numbers transfer/port, did you call to cancel your old service?

    So my phone numbers have finally transferred for my husband and I, and we're up and running. Do we call Verizon and cancel our service or will it automatically cancel out for us?

  • FileMerge.app crashing at startup

    I've searched but couldn't find any pages or posts about this. I'm trying to use FileMerge.app 2.3, included with Leopard's Dev Tools, and it's crashing at launch. I've tried trashing the prefs but that didn't help. Anyone else having this problem, o