Applescript: display dialog while doing shell script

Hello there,
I'm making an applescript app for my company, and had  a question.
The functionallity of the app is working great, but there is a certain step which can take up to several minutes.
This can give the user the feeling that nothing is happening and things are stuck.
Is there a possibility to display a dialog as long as the action (shell script) is running?
Something along the lines of "Now performing action X. please wait...)
Thanks for your thoughts!
Grtz

With regular AppleScript you can start the shell script in the background (see do shell script in AppleScript) and then put up a dialog, although you would have to periodically check to see if the shell script is finished.  In Lion, the AppleScript Editor has a Cocoa-AppleScript template that you can use (kind of a wrapper application that lets you use various Cocoa methods without having to use Xcode), in which case you could put up an indeterminite progress indicator and then do the shell script.
AppleScript Studio is deprecated as of Snow Leopard, but there are some AppleScriptObjC in Xcode tutorials at MacScripter.  An additional source of information and templates is macosxautomation, but they seem to be having some server problems at this time.  I also have a Progress Window template application example, it can be downloaded here.

Similar Messages

  • Applescript Display Dialog Default Answer Rendering Issue

    After I installed Lion, I started having issues with Applescript rendering a dialog with a textbox.
    This is the sort of thing I end up seeing:
    The text box in the dialog doesn't render properly, and it's not possible to enter anything into it.  I've played with the display dialog parameters but it doesn't matter if I give an empty string for the default answer or other text, the behaviour is always the same.
    Does anyone have any ideas as to what the issue might be?  I suspect I might need to reinstall Lion, but I'm not sure that's even going to clear up the issue.
    Thanks in advance.

    Tried replacing 'Standard Additions' osax, dumping editor prefs, dumping ALL user prefs (not recommended for faint of heart), using a different copy of Script Editor. Nothing helped.
    The user account displaying the bug is an old one; likely updated continuosly from the days of Tiger or earlier.
    A std account on the same drive, which merely went through the Snow Leopard -> Lion transition, does not exhibit the edit-text display bug.
    So I bit the bullet, and used Migration Assistant to move to a new account on a clean install of Lion on a spare hard drive. 3.5 hours later, the Applescript edit text display bug is gone.
    As far as I can tell, all docs, Apps etc. made it through intact.
    If that continues to look true over the next few days, I'll try using SuperDuper! to copy the new drive back to the older, faster HD.
    Perhaps some other Lion bugs'll also go away now that I've got a cleaner install.

  • Applescript: display dialog until memory card is inserted

    I'm developing an applet to automate the process of copying video footage from my camera's memory cards onto my hard drive. It works perfectly, except that I cannot quit it. Here is the part of the code that needs help. It checks every 5 seconds for a memory card and, if one is inserted, continues to copy everything off it.
    repeat
         set cardIn to 1
              with timeout of 86400 seconds
                        tell application "Finder"
                                  repeat while cardIn is 1
                                            if exists disk "EOS_DIGITAL" then
                                                      set cardIn to 0
                                            else
                                                      delay 5
                                            end if
                                  end repeat
                        end tell
              end timeout
         (the rest of the code)
    end repeat
    The problem is that there is no way I can find to quit once it is in this wait loop. The menu command to quit and the Command-Q hotkey both do nothing so I have to force quit when done. What I'd like is to be able to have a dialog displayed asking this user if they want to quit while it's waiting, but I don't know how to do that without it having to "give up after 5 seconds". That makes a new dialog display again every 5 seconds when it rechecks for memory cards, which would get very annoying for anyone using the computer.
    I wish something like this would work...
    repeat until (list disks) contains "EOS_DIGITAL"
         display dialog "Waiting for card..." buttons {"Quit"}
         tell me to quit
    end repeat
    ...but it still waits for a button to be clicked in the dialog. I want this to be a truly automatic process, where plugging in a memory card triggers the whole copy process (which is already done and works perfectly) so I would rather not have to click a button to continue.
    Is there any way to have a dialog displayes with a quit button that automatically goes away once a memory card is inserted without using "giving up after x seconds"?

    Keeping a script or application locked up inside delays or repeat loops will keep it from responding to system events.  There are a few ways to monitor when a volume gets mounted:
    Write your application using AppleScript in Xcode to watch for a workspace notification;
    Use launchd or a folder action to watch the /Volumes folder (an alias is added to the folder when a volume is mounted);
    Make your script into a stay-open application and use an idle handler to periodically check.

  • Applescript: display dialog / saving to . . .

    The following script always has the document folder selected in the "save as" window
    How do I designate another locaiton  such as the desktop
    or even  create a folderat the desk top and have it selected as the save to
    (G5 PPC OS X 10.5.8 Applescript)
    Thank you
    say (text returned of (display dialog ¬
        "Enter what you would like synthesized into a file." default answer ¬
        "Welcome to Mac OS X.")) saving to (choose file name with prompt ¬
        "Choose where you would like to to save the file." default name "say.aiff")

    The choose file / defaul location is a reference to a folder which is useful
    But how do I change the locaiton from the documents folder to the desktop
    The desktop is not a folder and won't work with this comand
    I googled and come up with  a solution:
    say (text returned of (display dialog ¬
        "Enter what you would like synthesized into a file." default answer ¬
        "Welcome to Mac OS X.")) saving to (choose file name with prompt ¬
        "Choose where you would like to to save the file." default name "say.aiff" default location path to desktop)
    Thanks for pointing me in the right direction

  • Applescript with Mail attachments and shell scripts (pdftk)

    I'm trying to create a script that I can call using mail rules that will:
    1. save an attached PDF file to a folder (folder name is 'PDFs_from_Mail:')
    2. save each page of the PDF as a separate file
    3. delete the old file
    so far, i used the script below called from mail to save the attachments to the
    -- script called from mail
    using terms from application"Mail"
      onperform mail action with messages theMessages
        tell application"Finder" to set ptd to (path to desktopfolder) as string
        tell application"Finder" to set pathToAttachments to(path to desktop folder as string) &"PDFs_from_Mail:"
        tell application"Mail"
           repeatwith theMessage in theMessages
                if theMessage's mailattachments is not {} then
                      repeatwith theAttachment in theMessage's mailattachments
                            settheFileName to pathToAttachments & theAttachment's name
                            try
                                     save theAttachment in theFileName
                              onerror errnum
                            endtry
                      endrepeat
                end if
             endrepeat
          end tell
      endperform mail action with messages
    end usingterms from
    tell application"Mail"
        setmyMessages to selection
        tellme to perform mail action with messages myMessages
    end tell
    -- end of script called from mail
    after the file is in the folder, i'd like to automatically call a script that splits it in to pages and saves each file.  I found pdftk can do what I need.  I got the following working, which uses a folder action script to process the file:
    -- burst script
    on addingfolder items to this_folder after receiving added_items
       tellapplication "Finder"
           set fold_name tothe name of this_folder
               try
                   repeatwith i from 1 to number ofitems in added_items
                          set theFile toitem i of added_items
                          set oldDelimiters toAppleScript's text item delimiters
                          set AppleScript's textitem delimiters to {":"}
                          set theFolder to(((text items 1 thru ((count everytext item of (theFile asstring)) -1)) of (theFile asstring))) as string
                          set AppleScript's textitem delimiters to oldDelimiters
                                --get the file name
                                   set theFileName to the name of theFile
                                                     do shell script"/usr/local/bin/pdftk " & (POSIX path oftheFile) & " burst output " & (POSIXpath of theFolder) & "/" & theFileName &"_%03d.pdf"
                                                      delete theFile
                                                    endrepeat
                                        end try
                         endtell
    end adding folder items to
    -- end burst script
    the shell script that is called is in the format:
    pdftk myfile.pdf burst
    the output parameter basically adds the page number to the end of the original filename for each file that is created
    my idea was to attach the folder action script to the 'PDFs_from_Mail' folder, and when the first script is called, the file would be saved to that folder and trigger the folder action script burst the file.  it works for individual messages, but when I try using it with the hundreds of messages that I have, all kinds of crazy things happen... the filenames are all wrong and it seems like it goes on infinitely.
    My familiarity with applescript is somewhat limited (as you may have guessed) and I'm wondering if there is a better approach.  perhaps if I incorporate the shell script into the script called from mail it may streamline everything.
    my problem is that I am not sure what code I need to keep in each script.
    can anyone take a quick look at this and give me some advice?
    my goal is to have these individual pages in a folder so that I can use quick view to page through them.  if the pdf is more than one page, then I have to get involved in scrolling up/down and it becomes difficult to find things efficiently.
    thanks!

    just a quick update and a general questions about applescripting with shell scripts...
    i attached the above folder action burst script to a folder, and have been dragging pdf files into it, one at a time.
    sometimes the script runs fine and the new files are created and the old pdf is deleted.  other times, there is a long delay between when I drop a pdf file into the folder and when the new files are created.  and sometimes nothing even happens at all (uaually if i dont wait for at least 30 seconds or so between dropping the files in the folder).  I also noticed that the window title text (area showing the folder name at the top of the finder window) becomes grayed out when the script is running and sometimes it remains grayed out for a few minutes after the script has run.
    could it be that the shell script just takes a really long time to work?  i am afraid to drop more than one file at a time as the last time I tried that the output was all wrong and I had to force quit processes and shut down. 

  • ORA-01017 encountered while executing shell scripts

    Hi,
    While executing backup scripts for one of my databases, the script contains a login section which fails as shown below
    Script login section:
    sqlplus / << END > /tmp/$PROGRAM.tmp
    Error generatedf in logfile:
    SQL*Plus: Release 11.2.0.3.0 Production on Wed Apr 10 11:32:06 2013
    Copyright (c) 1982, 2011, Oracle. All rights reserved.
    ERROR:
    ORA-01017: invalid username/password; logon denied
    Couple of points to be noted:
    1) There are two other databases in the same server and they don't have any issue
    2) I am able to login into this database as "/"
    3) I am able to connect to the same databases as sysdba from another server
    4) The script runs successfully when I modify it as: sqlplus / as sysdba << END > /tmp/$PROGRAM.tmp

    if you connect sqlplus as
    $ sqlplus /You're not identifying that's why you got ORA-01017
    instead if you connect as "sqlplus / as sysdba" , check:
    sqlplus / as sysdba--how it works
    ===========================================
    please mark your threads as answered when you got the correct answer:
          866746     
    Handle:      866746 
    Status Level:      Newbie
    Registered:      Jun 18, 2011
    Total Posts:      3
    Total Questions:      3 (3 unresolved)Edited by: Fran on 12-abr-2013 3:47

  • AppleScript Display dialog if clause

    What I'm trying to do now is have a pop up trigger from a calendar event(already know that part) and ask a user if they are ready to launch another workflow. If they select NO I want there to be a 5 minute delay and then have the same question asked again. I cant figure out how to loop the original question back through and I know there has to be a way to do it.
    Heres my code so far...
    set question to display dialog "If you're ready to clock in, punch for lunch, or clock out click YES. If you are stuck on a chat cancel this bad boy." buttons {"No", "Yes"} default button 2
    set answer to button returned of question
    if answer is equal to "Yes" then
              tell application "Finder" to activate
              tell application "System Events"
      keystroke "c" using {command down, control down, option down}
              end tell
    end if
    if answer is equal to "No" then
              display dialog "Automator will snooze for 5 minutes" buttons {"Snooze", "Snooze"} default button 2
    delay 300
    display dialog question
    end if
    Thanks in advanced for any input!

    You can also just put the whole thing in another repeat statement:
    repeat -- forever
      set answer to button returned of (display dialog "If you're ready to clock in, punch for lunch, or clock out click YES. If you are stuck on a chat cancel this bad boy." buttons {"No", "Yes"} default button 2)
      if answer is equal to "Yes" then
        tell application "Finder" to activate
          tell application "System Events"
            keystroke "c" using {command down, control down, option down}
          end tell
        exit repeat
      else
        display dialog "Automator will snooze for 5 minutes" buttons {"Snooze"} default button 1 giving up after 10
        delay 300
      end if
    end repeat

  • Getting error while running shell scripts

    Hi DBAS,
    I Have one requirement,i want connect n database dynamically by using dynamic password and execute some oracle commands,i written some script ,but while running i am getting error,please any one correct my error ,i am not able to getting error
    passwrd.pw like this
    abc@abc
    aaa@aaa
    # vi healthcheck.ksh
    #!/bin/ksh
    export PW=`cat /applis/forum/pune/dbhealthchecks/.pw/passwrd.pw`
    for (( i = 0 ; i < ${#PW[@]} ; i++ ))
    do
    sqlplus -s larry/$PW<<EOI
    spool sysdate.dat
    select sysdate from dual;
    done
    exit;
    EOI
    error :
    line 2: syntax error at line 11: `for' unmatched
    thanks!
    larry
    Edited by: tmadugula on Mar 18, 2011 6:26 AM

    Could you explain the reason for the for loop and connection attempts while incrementing var $i?
    It is also no a good idea to provide a password at the command line since it can be seen with 'ps' command.
    Better:
    sqlplus -s <<-EOI
    connect larry/$PW
    etc.

  • Showing a cancelable dialog while doing a time consuming operation

    I am using SwingUtils.invoklater and placing my long operation in a seperate thread , I would like to show a cancel-able dialog so the the long operation can be interrupted by the user, it seems like the the JOptionPain that I am using (although in a seperate thread) it halts my main thread), any one has a suggestion of psedue code to resolve this situation.

    perhaps a ProgressMonitor might suit

  • Automator/Applescript not running shell script properly

    I can open Terminal, and this command works:
    lame -h --abr 256 /Users/myhome/Desktop/Some\ Wav\ File.wav /Users/myhome/Desktop/TheMP3.mp3
    But when I try to run the same command in applescript from Automator, it fails.
    set sourceFile to quoted form of POSIX path of "/Users/myhome/Desktop/Some Wav File.wav"
    set mp3File to quoted form of POSIX path of "/Users/myhome/Desktop/TheMP3.mp3"
    set command to "lame -h --abr 256 " & sourceFile & " " & mp3File
    display dialog command
    do shell script command
    The display dialog outputs:
    lame -h --abr 256 '/Users/myhome/Desktop/Some Wav File.wav' '/Users/myhome/Desktop/TheMP3.mp3'
    Which, as little as I know of applescript, is how applescript handles spaces in filesnames. Can anyone please help?

    You need *do shell script* attribute described in the 10.4 Changes section of http://developer.apple.com/mac/library/releasenotes/AppleScript/RN-AppleScript/R N-104/RN-10_4.html#//appleref/doc/uid/TP40000982-CH104-SW1 Additional info can be gained by posting to the AppleScript and Unix forums under OS X Technologies.

  • How to do multiple shell scripts in AppleScript

    I got some solutions from previous posts on how to run sudo in Applescript, but there is still some minor syntax issues when I try to get to the destination directory. Usually in shell script I just type
    cd directory-destination
    in several lines to batch process those commands, but when I work with applescript, if I do do shell script for every "cd" command, instead of getting an overall result, I would get intermediate results individually.
    I read doc and learned that there might be a way to put commands together by using the & sign?
    Message was edited by: ttback

    An individual do shell script command runs in its own shell, so to perform multiple commands within that shell you need to combine them into a single statement. You can use the ampersand '&' operator to concatenate text strings, and the semicolon ';' to separate the commands, for example:set theFolder to "/Applications"
    do shell script "cd " & theFolder & "; ls -l ."See the technical note do shell script in AppleScript.

  • Shell script and keyboard shortcut

    I wrote a bash script, and I would like to start it with a keyboad shortcut, but I can't figure out how to do that. Does anyone know?

    Hi Hugo,
       Keyboard shortcuts are meant for Carbon and Cocoa applications but it can be done; you just have to wrap the shell script in some sort of application. One way is Sveinbjorn Thordarson's Platypus but I just wrap mine with an AppleScript, invoking it with "do shell script". You have to save the AppleScript as an application. Then you open the "Keyboard & Mouse" pane of "System Preferences" and select the "Keyboard Shortcuts" tab. Click the plus sign, '+', pick a key combination and specify your AppleScript or Platypus app as the target.
    Gary
    ~~~~
       Are there those in the land of the brave
       Who can tell me how I should behave
          When I am disgraced
          Because I erased
          A file I intended to save?

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

  • Return results of cURL shell script direct to AS?

    Is there a way to return the results of a cURL shell command (which I have working fine) directly to the AS script? The result of the cURL command is a small text file.
    Or am I stuck with opening the resulting file to read its contents?

    The solution is simple - your original shell example uses quoted strings, and you can't just copy/paste that into an AppleScript because AppleScript also uses quotes to delineate strings.
    The answer lies in escaping the quotes, so that AppleScript knows to pass the actual quote symbol to the shell (and therefore onto curl) rather than have AppleScript interpret it itself.
    do shell script "/usr/bin/curl --data \"browserRequest=true&lat1=43%C2%B043%2738.11%22&lat1Hemisphere=N&lon1=69%C2%B0 4 9%2752.85%22&lon1Hemisphere=W&startYear=2013&startMonth=1&startDay=1&resultForm at=csv\" http://www.ngdc.noaa.gov/geomag-web/calculators/calculateDeclination"
    Note how the quotes surrounding your data are escaped.
    (Note also that the above command generates a 500 error off the server because the parameter data is invalid, but I assume you can fix that)

  • Deploy application using ant script vs shell script

    Hi,
    I work with OAS 10.1.2 and I'm using shell script with dcmctl command to deploy EAR into OC4J but I know that ant script do the same things. I want to know if my choice is good or is it better to use ant script ?
    Regards

    This is difficult to decide.
    When you have just a few ear files you deploy once in a while a shell script might be sufficient. When developing more complex systems you should use ant as this is easier to maintain.
    cu
    Andreas

Maybe you are looking for

  • Error in downloading \ installing Flash Player

    I have tried to install the new version five times this morning - all ending up in the same error. I reach the point where the installer says "Close Internet Explorer". When this is done it continues to give the same message and doesn't progress any

  • PC will not update. Mac updated fine...

    When trying to update from the PC I get a message that states that the update server is down or may be offline, or the firewall settings could be wrong. Would that be MY firewall settings? The mac updated with no problem, but my PC will not update. T

  • What do you do if you forgot the answers to the security questions??

    I forgot the answers to the security questions for my apple ID. I recently received an iPad Mini for my birthday. ( Don't spam the comments saying happy late birthday, we're not here for a party. ) I want to be able to purchase apps and music from it

  • Ctrl+O behavior in Office 2013

    When using Word, Excel, PPT 2013.  The CTRL+O shortcut does not launch the Open dialog box for me.  Instead, the File (Alt+F) screen appears.  Why is this?

  • Error during download Creative Cloud

    Hi, I can't download and install the Creative Cloud. I receive each 5 minutes following error: The server is not responding currently, please try after some time. (Error code: 207) I have this error since yesterday and I have still this error. Also t