How to quit an AppleScript programmatically?

I have an applescript that is continually running. Every 60 seconds it opens an application which runs certain processes.
My Problem is that while the applescript is running the computer is not able to restart or shutdown. So I need to capture the shutdown command or the restart command within my applescript so as to stop it and quit.
Any ideas?
My Applescript:
<pre>
tell application "Finder"
repeat until theCount > 200
activate
open application file "FullScreenWindow.app" of folder "TimeSheetDaemon" of startup disk
delay 14400 -- son segundos
end repeat
end tell
</pre>
Thanks

Hi
You need to use quit and idle handlers in a stay-open application:
--begin script
on idle
tell application "Finder" to open application file "FullScreenWindow.app" of folder "TimeSheetDaemon" of startup disk
return 14400
end idle
on quit
continue quit
end quit
--end script
This way there's no need for an endless repeat loop, and the script app gracefully handles the quit event sent to it by shutdown, restart or logout.
Hope this helps,
H

Similar Messages

  • Applescript to quit an applescript

    Hi all,
    I'm trying to quit an applescript application (so should be an app, no?) through another applescript without results... even when i do a "killall myapp" from the terminal i have this error:  "No matching processes belonging to you were found"
    How can this be?
    The application i want to quit is as simple as this:
    delay 400
    do shell script "echo try>> /Users/caDesktop/dst.txt"
    Thanks!

    Your application isn't going to quit if told to quit (directly or via System Events) while it is in that long delay, since it won't get the message until the delay is completed.  The shell command killall will terminate the process, but an AppleScript application process does not have the name of the application - it has the name of the executable, which would be applet or droplet.

  • How to add (multiple) cursors programmatically in an XY graph?

     how to add (multiple) cursors programmatically in an XY graph?
    I am building an XY graph. then I would like to add cursors at certain locations (positioned on x axis) I determine through a program.
    How can I add cursors programatically?
    Thank you.

    Initialize a cluster array (CrsrList type) with as many cursors as you think you would ever need.   Setup your cursors dynamically, then delete the unused cursors (array elements) and then update your CursorList property.
    Message Edited by vt92 on 03-20-2009 04:04 PM
    "There is a God shaped vacuum in the heart of every man which cannot be filled by any created thing, but only by God, the Creator, made known through Jesus." - Blaise Pascal
    Attachments:
    cursors.PNG ‏5 KB

  • How can I use Applescript to copy a file's icon to the clipboard?

    Hello,
    How can I use Applescript to copy a file's icon to the clipboard?
    Thanks.
    Lennox

    there is no way to do that that I know of. but you can extract an icon of a file to another file using command line tool [osxutils|http://sourceforge.net/projects/osxutils]. you can then call the relevant command from apple script using "do shell script".

  • How do I use AppleScript to Change the Creation Date to the Current Date?

    I sorted my downloads folder by creation date and found that the items were sorted seemingly randomly. On closer inspection, I saw that the creation dates were not the same as the dates that I downloaded the items, so I figures that Snow Leopard was using the date given to it by the server.
    In order to get the items sorted by download date, I figured I'd use Hazel, but it doesn't have a “change creation date” item. It does, however, have an “run AppleScript” item.
    So my question is this: how do I use AppleScript to change the creation date of an item to the current date?

    TC (Techno Cat) wrote:
    Okay, I tried changing the creation date with SetFile, but it kept giving me an error:
    What am I doing wrong?
    Looks like the date and time was not quoted
    Try this Applescript. It will change the creation date of every file in the Downloads folder to the current date and time:
    <pre style="
    font-family: Monaco, 'Courier New', Courier, monospace;
    font-size: 10px;
    font-weight: normal;
    margin: 0px;
    padding: 5px;
    border: 1px solid #000000;
    width: 720px;
    color: #000000;
    background-color: #E6E6EE;
    overflow: auto;"
    title="this text can be pasted into the AppleScript Editor">
    set current_date_and_time to do shell script "date \"+%m/%d/%Y %H:%M\""
    tell application "Finder"
    set filelist to every file of the alias (the path to downloads folder as text)
    repeat with currentFile in filelist
    do shell script "/usr/bin/SetFile -d " & quoted form of current_date_and_time & space & quoted form of POSIX path of (currentFile as string)
    end repeat
    end tell</pre>

  • How to write an applescript and ignore errors

    I'm writing an applescript that uses a shell command that will always return an error. Applescript stops as soon as the error occurs. I want the applescript to continue running. How should I tell Applescript to ignore errors?

    The basic construct is a try/end try block which runs your own code when an error occurs rather than stopping your script.
    An alternative when using do shell script is to suppress stdout and stderr so that errors are not returned to the application. Which you can do by appending ' > /dev/null 2>&1 &' to the end of the shell command.
    Note, though, that your command will not work as written because 'choose folder' will return an alias object which can not be passed to a shell command as-is. Shell commands require unix-style paths for all file/folder parameters. Fortunately, AppleScript makes this easy by providing a POSIX path command which will convert an alias to a unix path. Additionally, since Mac paths can commonly include spaces and other non-shell safe characters, you may want to quote the path, too, like:
    <pre class=command>set shell_script to "usr/local/bin/readpst -o " & quoted form of POSIX path of mbox_output & " " & pst_input & " > /dev/null 2>&1 &"</pre>

  • How to quit Microsoft Database Daemon SyncServicesAgent?

    I am attempting to update Microsoft Office, but when I download the update, I receive the message that I need to quit these applications:
    -Microsoft Database Daemon
    -SyncServicesAgent
    I do not know how to quit these applications and they do not appear in the "Force Quit" menu.  Suggestions?

    I share your frustration. Tried for 50 minutes straight to delete and they kept coming back. Today I tried again, following the instructions given to close in Activity Monitor. Clicked on 'Quit process' and confirmed only to see them pop up again, and this time 'quit process' was greyed out so I couldn't click it. Finally i tried the keyboard instructions given (alt -cmd - Q) and yeayy! **** things stopped long enough for me to install an update. Might just be coincidence but it worked for me

  • How to create an IDoc programmatically at Inbound side?

    Hi,
    How to create an IDoc programmatically at Inbound side?
    Assume that you have a file(material master details) which is enough to create master data.
    Regards,
    Thiyagu

    Read the documentation of this FM first:
    FU IDOC_INBOUND_ASYNCHRONOUS                                                                               
    K. tekst
                                                                                    IDoc inbound processing via tRFC                                                                               
    Functionality
                                                                                    This function module starts inbound processing in the case of port type    
        "tRFC". The function module is a successor to INBOUND_IDOC_PROCESS,        
        which processes IDocs in the Release 4.0 record types. If you are          
        processing IDocs in Release 3.X record types, the function module          
        INBOUND_IDOC_PROCESS must still be called.                                                                               
    The function module checks the ID 'EDI_MES' in authorization object        
        B_ALE_RECV against the received message type.                                                                               
    The IDocs are saved by the function module IDOC_INBOUND_WRITE_TO_DB (a     
        COMMIT for all IDocs) and then transferred directly to the application     
        by the dispatcher module IDOC_START_INBOUND.                                                                               
    Parameter
                                                                                    IDOC_CONTROL_REC_40                                                        
        IDOC_DATA_REC_40                                                                               
    Exceptions
                                                                                    Functiegroep                                                                               
    Edited by: Micky Oestreich on Jun 11, 2009 12:52 PM

  • Simple introduction/tutorial on how to make Cocoa-Applescript Applets?

    I'm looking for a simple tutorial on how to make Cocoa-Applescript Applets.  I'm pretty new to Applescript, but fairly good at it, and I was wondering how Cocoa-Applescript Applets worked.  I was curious as I've been wondering if it was possible to somehow display images in Applescript, and it apparently is the only/easiest way.  My problem is that I haven't been able to find any tutorials on using it, so I was wondering if you guys could point me in the right direction, that'd be great!
    thanks in advance

    The main difference is with how the Cocoa APIs are used - in addition to the AppleScript and AppleScriptObjC release notes, there are some examples and resources at Mac OS X Automation.  Note that in Yosemite, AppleScriptObjC is available to all scripts, not just applets and libraries.

  • How can I use AppleScript Studio to display an image

    How can I use AppleScript Studio to display an image in a dialog?

    Add an image well to your window in Interface Builder.
    You can also add an image file to the Resources group of your Xcode project and then set the image to be displayed inside the image well directly in Interface Builder. No AppleScript code is needed if the image is contained within your app bundle and can be set ahead of time like this.
    If the image is contained in your app's bundle but you need to set or change the image at run time then you can use a line of AppleScript to load it into the image well using just it's filename:
    set image of image view "yourImageView" of window "yourWindow" to load image "YourImageFile.jpg"
    If you need to load an image from an arbitrary location outside your app's bundle then use a path to the image file...
    set image of image view "yourImageView" of window "yourWindow" to load image "/path/to/YourImageFile.jpg"
    Steve

  • How to change focus in programmatic way?

    Hi,
    1. how to change focus in programmatic way?
    2. is there any way to define tab index?
    With Regards,
    Wai Phyo

    1). http://docs.oracle.com/cd/E16162_01/apirefs.1112/e17491/tagdoc/af_scrollComponentIntoViewBehavior.html
    2). no

  • The iCal upgrading will not stop and I do not know how to quit it...help!

    The iCal upgrading will not stop and I do not know how to quit it...please help!

    Best thing to do is post in the iCal forum:
    https://discussions.apple.com/community/applications/ical

  • How to quit apps?

    hi, i've recently switched from blackberry to the iphone 4 and was curious to how i quit apps? on my blackberry i know that if i keep anything running in the background e.g. mail, browser and not formally 'close' it, it will slow down my bb. does iphone operate the same way? will i need to formally quit/close apps? if so, how do i go about doing that?

    http://whenwillapple.com/blog/2010/04/19/iphone-os-4-multitasking-explained-agai n/

  • HT2492 When I try to update Adobe Flash Player I'm prompted to quit Safari and Dashboard Client. I quit Safari but I don' know how to quit Dashboard Client. Can anyone help with this challenge?

    When I try to update Adobe Flash Player I'm prompted to quit Safari and Dashboard Client. I quit Safari but I don' know how to quit Dashboard Client. Can anyone help with this challenge?

    Carolyn,
    Thank you. It worked
    Angus.

  • How to quit the games after open it?

    How to quit the games after open it?

    iOS 7 How to Close Apps
    Double Tap the Home Button... Then swipe the App (not the icon) Upwards... Tap the Home Button when finished.
    From Here  >  http://support.apple.com/kb/HT4211

Maybe you are looking for