Quit AppleScript App

Hello, I am creating an AppleScript app and have a button for quitting the app. What is the script so I can quit my app?
Thanks

In your button handler you can use a statement such as:
  tell me to quit -- OK
    -- or --
  current application's NSApp's terminate() -- better
If there isn't anything else that your button handler is doing, you can also just connect it to the application's terminate action (this will work the same as selecting the quit menu item) - in IB, select the Application object, look in the Connection Inspector for the terminate: action, and drag a connection to the button.

Similar Messages

  • Ensure AppleScript App Quits

    I have an AppleScript saved as a run only app which I call every hour from launchd.
    Most of the time it works fine, but occasionally something causes the app not to quit when it's done its thing.  This means that next time an error is thrown and the process does not run (so it fails until I force quit the app).
    I have tried wrapping the whole script in a try...with timeout...end timeout...on error return...end try structure but that makes no difference.
    The core of the script is a run shell script that calls a perl script which in turn gets data from a web site.  I have tried nesting a try...on errror...end try around this that simply sets the content of the variable that should be populated from the script in the event that any error occurs.
    The final part of the script is opening a [text] file and inserting a few lines at the top.  Again I have tried wrapping this in a try...on error return...end try stricture.
    None of these efforts seems to have any effect.  However, I can't get the script to fail when I run it from the ApplScript Editor.
    Would I be better to use osascript to call a script rather than the app, or am I doing something more fundamental wrong?

    I'm not trying to be coy either, but I don't see that posting the whole script is going to help particularly because the perl script uses WWW::Mechanize to get data from a website where I have to provide user credentials - hence, it will not be possible to run it without those credentials.
    The expectation is that I will get approximately ten lines of data back (which I put into a local variable).  I then use an offset check to determine whether a particular string is present.  If it is present, I then go on to compose a message (using Messages) to send to myself.
    Regardless of the content, I open a local text file and insert the web response at the beginning of the file (as an activity log).  The file is then closed for access and that's it.
    I have only once seen an error when I ran the script from the AS Editor and this seemed to indicate a problem with the site's availability - so when Mechanize couldn't find any identifiable data, it threw an error.
    The app is not saved as stay open, but it does.  All I can say for certain is that the log file does not get written to, so I suspect that the problem lies with the perl script.  It is for that reason that I wrapped it in a try...with timeout structure.  (My understanding of the timeout, is that if script execution fails to complete within the timeout an error will be thrown, so this is picked-up by the try...on error.  That understanding may be wrong.)
    So, after all that, here is the script [with a single hard-coded address obscured for privacy]:
    try
              set desktopPath to (path to desktop) as alias
              set FlightCheckLog to (desktopPath as text) & "FlightCheckLog.txt"
              set targetList to {"Sep-7", "Sep-8", "Sep-9", "Sep-10"}
              tell application "Messages"
                        set theBuddy to buddy id "<OBSCURED>"
              end tell
              set messageSent to false
              try
                        with timeout of 300 seconds
                                  set theFlights to do shell script "~/Documents/perl/FilghtCheck.pl -x -c J -d 2013-09-07 ATH-LHR"
                        end timeout
              on error
                        set theFlights to ""
              end try
              repeat with theDate in targetList
                        set theOffset to (offset of theDate in theFlights)
                        if theOffset is not 0 then
                                  set theFlight to text (theOffset - 5) thru end of theFlights
                                  set theReturn to (offset of return in theFlight)
                                  set theFlight to text 1 thru (theReturn - 1) of theFlight
                                  tell application "Messages"
      send theFlight to theBuddy
                                            set messageSent to true
                                  end tell
                        end if
              end repeat
              try
                        set theFile to open for access FlightCheckLog with write permission
      get eof theFile
                        if result > 0 then
                                  set fileText to read theFile
      set eof theFile to 0
                        else
                                  set fileText to ""
                        end if
                        if messageSent then
                                  write ((current date) & return & theFlights & return & "MESSAGE SENT" & return & return & fileText) as text to theFile
                        else
                                  write ((current date) & return & theFlights & return & return & fileText) as text to theFile
                        end if
      close access theFile
              on error
                        return
              end try
    on error
              return
    end try

  • Applescript app won't quit

    I need a little help.  I have written an AppleScript app that "touches" one of my external drives every 55 seconds to keep it from spinning down.  However, this app won't quit when I depress command-Q ... even though I have included an "on quit" handler.  Can anyone suggest what I need to change to have this app respond properly to command-Q?  Here's the script:
    with timeout of 99999999 seconds
              tell application "Finder"
      activate
                        repeat
           do shell script "touch -a /Volumes/TimeMachine/.TemporaryItems"
           delay 55
                        end repeat
              end tell
    end timeout
    on quit
           continue quit
    end quit

    AppleScript is not multi-threaded, so the application will never get the quit message because the repeat loop never finishes.  Sitting in a continual repeat loop is not the way to go since it blocks the user interface - instead, resave your application with the option to stay open, and use the idle handler (note that the Finder is not needed for the do shell script command):
    on idle
      do shell script "touch -a /Volumes/TimeMachine/.TemporaryItems"
      return 55
    end idle

  • Key binding to quit an applescript app as an alternative to 'Force Quit'

    Hello,
    I have an AppleScript App which is running for a hour. It is basically a GUI scripting.
    If I want to quit the app in between, I am unable to use 'Force Quit' as the mouse/key board is extensively used by the app.
    I wish to know some alternatives for this issue.
    note:
    Is there anyway I can bind some key combination and once it is pressed, the app should quit?

    +Any suggestions to handle this issue?+
    You can quit a script that is saved as an 'application bundle' with another script.
    Open the 'application bundle' and drag the 'applet' file between the quotes...
    tell application "" to quit
    and you will get this, but with a different path.
    tell application "/Users/tom/Login Items/ReniceR.app/Contents/MacOS/applet" to quit

  • AppleScript App Quit Timer in Yosemite

    Hey all.  I think this is a simple question... but I don't really know.  I fall asleep with EyeTV running and wanted a sleep timer for it... years ago I found a little script online-- I think it's AppleScript... --to quit an app after a specified amount of time.  The script is:
    display dialog "Timer duration (in minutes):" default answer "180"
    delay ((the text returned of the result) * 60)
    tell application "EyeTV" to quit -- Set AppName to the name of the application you want to quit.
    That's it.  A box would pop up asking me to enter the number of minutes 'til quit (180 as the default), and after that amount of time EyeTV would quit.  The problem is, in Yosemite, no matter how much time I enter in the duration box, EyeTV quits the instant I hit return.  I imagine there was a minor change to AppleScript in Yosemite, and I'm hoping someone smarter than me might be able to spot what's changed.
    Thanks for any help.

    Better all around to avoid the delay command and use an applescript app with an idle loop.  save the following as a application from the AppleScript Editor, making sure to click the stay open after run handler checkbox, then run the application.
    global timer, flag
    on run
      display dialog "Timer duration (in minutes):" default answer "180"
      set timer to ((the text returned of the result) * 60)
      set flag to false
    end run
    on idle
      if flag then
      tell application "EyeTV" to quit -- Set AppName to the name of the application you want to quit.
      quit -- send this command so this app will quit on the next idle loop
      return 1
      else
      set flag to true
      return timer
      end if
    end idle

  • Setting text item delimiters in Cocoa-Applescript App

    Does anyone know of a problem with text item delimiters in a Cocoa-Applescript App.  This is in Xcode 4.5.2 and  Mountain Lion
    the following code seems to fail  to set the text item delimeter  to + when I run it in Coca-AppleScript
    --  TSTAppDelegate.applescript
    --  Test Text item Delimiters
    --  Created by Frank Caggiano on 12/22/12.
    --  Copyright (c) 2012 Frank Caggiano. All rights reserved.
    script TSTAppDelegate
      property parent : class "NSObject"
              on applicationWillFinishLaunching_(aNotification)
      -- Insert code here to initialize your application before any files are opened
            tstTxtDel()
              end applicationWillFinishLaunching_
              on applicationShouldTerminate_(sender)
      -- Insert code here to do any housekeeping before your application quits
                        return current application's NSTerminateNow
              end applicationShouldTerminate_
        on tstTxtDel()
            set text item delimiters to "+"
            set d to "-s http://www.nietzschefamilycircus.com"
            set r to do shell script "curl  " & d & " | ~/Desktop/try.pl"
            display dialog "r is " & r
            set rr to every text item of r
            display dialog "rr " & rr
            display dialog "curl " & first text item of rr & " -o "
    end
    end script
    However if you put the tstTstDel() function in the Applescript editor it works as expected.
    The try.pl script is
    #!/usr/bin/perl
    $s ="";
    while (<>) {
        $s .= $_;
    $s =~ m{class="comic"(.*)<div class="footer">}si;
    ($link, $caption,$jj) = ($1 =~ m{<img src="(.*)" alt=.*class="quote">(.*)(</div>.*</div>)}si);
    print $link, "+", $caption, "\n";
    I know this worked in the past. The Coca-Applescript app was written at least as far back as Snow Leopard. The site I am parsing changed their format and I was updating the app as a means to learn the new Coca-Applescript environment.
    Any help appreciated

    OK found it, I needed to use
    set Applescript's text item delimiters to "+"
    instead of just
    set text item delimiters to "+"
    I suppose it is a scoping thing.

  • Is there a way of quitting an app only by pressing on the red button?

    Hello.
    I'm a new Mac user (my MacBook Air bought on April, 17th).
    I was wondering, is there a way of quitting an app by pressing on the red button only, without pressing on the app name on the menu bar and and then on "Quit X"?
    If it's possible, I will be glad to here the way.
    Idanref.

    No.  The red x closes the window but not the application.  An exception is when an app can only have 1 window open. (Like system preferences).   A quick way to close the app is to press CMD Q  on the keyboard.
    Regards,
    Captfred

  • My dad has a brand new iMac. If he quits an app, this window closes, but the app won't finish shutting down, Force quitting does not work.  Once another app is opened, it will not close either.  Now none of the apps are responding. Any ideas?

    My dad has a brand new iMac. If he quits an app, this window closes, but the app won't finish shutting down, Force quitting does not work.  Once another app is opened, it will not close either.  Now none of the apps on the dock are responding. I asked him to click on the apple, and drop down to "About this Mac", but that wouldn't open either. Any ideas?  If I was at his house, I would call Apple Care in a heartbeat, but am home with my sick daughter,,,  Thanks!

    For starters, have him open Disk Utility in Applications>Utilities, select the volume (the indented listing) and Verify Disk. If it reports any problems, have him try a Safe Boot by holding the Shift key at startup. This boot will take much longer than usual. It's checking and trying to repair the drive directory, if possible. Once in Safe Boot, have him repair Permissions.
    For other Disk repair remedies see
    http://support.apple.com/kb/TS1417
    Also, have him try a PRAM Reset. At the startup chime, hold down CMD-Option-P-R together, listen for two more chimes, total three, then let go to finish booting.
    Also, is he running any AV? If so, have him uninstall it. It might be responsible for this behavior. (There are no viruses for OS X.)

  • When I boot up my Mac, Messages opens automatically. I quit the app, but it just re-opens itself. It won't stay off!!! I can't figure out what's wrong with it!

    For the past few months, my Mac has been acting weird. EVERY time I boot up the computer, Messages opens automaticallly (I am runing OS X 10.8.x). I quit the app, but it just re-opens a few seconds later! It just won't stay off! I've looked it up online and nothing helps. I have no idea what to do!!!

    Please read this whole message before doing anything.
    This procedure is a test, not a solution. Don’t be disappointed when you find that nothing has changed after you complete it.
    Step 1
    The purpose of this step is to determine whether the problem is localized to your user account.
    Enable guest logins* and log in as Guest. For instructions, launch the System Preferences application, select Help from the menu bar, and enter “Set up guest users” (without the quotes) in the search box. Don't use the Safari-only “Guest User” login created by “Find My Mac.”
    While logged in as Guest, you won’t have access to any of your personal files or settings. Applications will behave as if you were running them for the first time. Don’t be alarmed by this; it’s normal. If you need any passwords or other personal data in order to complete the test, memorize, print, or write them down before you begin.
    Test while logged in as Guest. Same problem?
    After testing, log out of the guest account and, in your own account, disable it if you wish. Any files you created in the guest account will be deleted automatically when you log out of it.
    *Note: If you’ve activated “Find My Mac” or FileVault, then you can’t enable the Guest account. The “Guest User” login created by “Find My Mac” is not the same. Create a new account in which to test, and delete it, including its home folder, after testing.
    Step 2
    The purpose of this step is to determine whether the problem is caused by third-party system modifications that load automatically at startup or login.
    Disconnect all wired peripherals except those needed for the test, and remove all aftermarket expansion cards. Boot in safe mode* and log in to the account with the problem. The instructions provided by Apple are as follows:
    Shut down your computer, wait 30 seconds, and then hold down the shift key while pressing the power button.
    When you see the gray Apple logo, release the shift key.
    If you are prompted to log in, type your password, and then hold down the shift key again as you click Log in.
    Safe mode is much slower to boot and run than normal, and some things won’t work at all, including wireless networking on certain Macs.  The next normal boot may also be somewhat slow.
    The login screen appears even if you usually log in automatically. You must know your login password in order to log in. If you’ve forgotten the password, you will need to reset it before you begin.
    *Note: If FileVault is enabled, or if a firmware password is set, or if the boot volume is a software RAID, you can’t boot in safe mode.
    Test while in safe mode. Same problem?
    After testing, reboot as usual (i.e., not in safe mode) and verify that you still have the problem. Post the results of steps 1 and 2.

  • How to make text message notification work without quitting the app

    in the text message conversation view, there's only a soft sound alert when new messages are received.
    even when the screen is off, you get no popup preview or a regular notification sound whatsoever.
    the only way to keep getting the regular notification & previews is to quit the app each time you send out a text.
    often times when you are in the middle of something and are unable to focus on the phone itself for the conversation, you forget to quit the message app, then you are totally not aware there have been messages coming in because it only gives you a soft sound alert that's totally unable to hear when you're outside walking, or other similar scenarios.
    It's been bugging me for years, it's specially annoying when the other person I chat with isn't aware of this issue and ocassionally misses out my messages.
    i mean, if apple insists that to avoid this problem, the users MUST remember to quit the conversation RIGHT AFTER EVERY SINGLE LINE, this is just absolutely unrealistic.
    I now do it every time because I'm aware of the issue, but not the other people I have conversations with.
    I've had too many situations where I had to wait for a long time to receive response only to find out that the other person wasn't aware the new text messages, because it was simply too soft to hear, and completely no other sort of things to notify you with.
    so i wonder if there really isn't a way to change the notification behavior, cuz apparently it's impossible that I make everybody I send text to change their habits just for this.
    if anyone knows the answer I'll really appreciate it. thanks

    Submit your feedback directly to Apple using the appropriate link on the Feedback page:
    http://www.apple.com/feedback

  • IPhoto freezes when i open the app, each time it is open on the same photo and when i try to swap to another photo it freezes until i force quit the app.

    I have recently come back from a trip to Venice, i uploaded my photos to iPhoto to view and edit them, half way through the photos from day three of my trip it has frozen on a particular photo. I force quit the app and then re open it and it is still on the same image with the exact same problem. I am now unable to view any photos of my trip as they're all on iPhoto and i cannot access the albums because they are stuck on this one photo. I need to be able to access them by 11th March because i have a project due in about our trip and we need to include the best of our photos and at the moment i am being stopped from even looking at them. PLEASE HELP!

    What version of iPhoto?
    Assuming 09 or later:
    Option 1
    Back Up and try rebuild the library: hold down the command and option (or alt) keys while launching iPhoto. Use the resulting dialogue to rebuild. Choose to Rebuild iPhoto Library Database from automatic backup.
    If that fails:
    Option 2
    Download iPhoto Library Manager and use its rebuild function. This will create a new library based on data in the albumdata.xml file. Not everything will be brought over - no slideshows, books or calendars, for instance - but it should get all your albums and keywords back.
    Because this process creates an entirely new library and leaves your old one untouched, it is non-destructive, and if you're not happy with the results you can simply return to your old one. .
    Regards
    TD

  • Applescript app to batch files using ffmpeg and command

    i'm not a technical person and i hoping that i can get a help to create a custom applescript app. i'd like to create an applescript app to run video files from any folder to encode (using ffmpeg) and save the re-encoded version in a new folder inside the current file folder. i found the script that i need to run inside the applescript:
    ffmpeg -i ORG-FILENAME -c:v libx264 -crf 27 -c:a libfaac -q:a 100 -map_metadata 0 NEW-FOLDER/ORG-FILENAME && touch -r ORG-FILENAME NEW-FOLDER/ORG-FILENAME
    i searched through the forum and found something that might work but my limited knowledge can't get this to work:
    on run
        tell application "Finder"
            set theFolder to (choose folder)
        end tell
        proceed(theFolder)
    end run
    on open theFolder
        proceed(theFolder as alias)
    end open
    on proceed(theFolder)
        tell application "Finder"
            set parentFolder to parent of theFolder as string
            if not (exists parentFolder & "A") then
                make new folder at parent of theFolder with properties {name:"A"}
            end if
        end tell
        tell application "Terminal"
            do script "for f in " & quoted form of POSIX path of theFolder & " do ffmpeg -i \"$f\" -c:v libx264 -crf 27 -c:a libfaac -q:a 100 -map_metadata 0 " & quoted form of (POSIX path of (parentFolder & "A")) & " \"$f\"
    done"
        end tell
    end proceed
    when i run this i get:
    for f in '/Users/admin/Pictures/0/1/' do ffmpeg -i "$f" -c:v libx264 -crf 27 -c:a libfaac -q:a 100 -map_metadata 0 '/Users/admin/Pictures/0/A' "$f"
    done
    macbookpro-7:~ admin$ for f in '/Users/admin/Pictures/0/1/' do ffmpeg -i "$f" -c:v libx264 -crf 27 -c:a libfaac -q:a 100 -map_metadata 0 '/Users/admin/Pictures/0/A' "$f"
    > done
    -bash: syntax error near unexpected token `done'
    can anyone help me please

    You are missing a ";"  after your path argument.
    for f in '/Users/admin/Pictures/0/1/'; do

  • Error on launching Applescript app

    Hey, i created some Applescript app which i scheduled using  Schedule manager or Task Till Down and everything was ok.
    Since 1 month, after a while i turn on the laptop and that everything is running, i receive the alert message (in attachment). If i execute the apps from inside Applescript they are ok.
    After restarting all is working again for a while (sometimes minutes or hours) and then the same problem again.
    Do you have an ideal of which can be the problem?

    Hi,
    I'm sorry for give any solid suggestion about this problem, but I found another thread which similar with yours may be helpful, please take it as reference and try the solution of it.
    http://social.technet.microsoft.com/Forums/windows/en-US/c4147bcc-a430-43fe-b4e9-f999552568da/81-store-apps-wont-load?forum=w8itprogeneral
    Roger Lu
    TechNet Community Support

  • Changing File Association to Applescript App

    Hello,
    I wrote an applescript application that I can use to launch Final Cut Pro (the script displays a message that I want the users to read while FCP is being opened). It works great!
    I tried to associate all my Final Cut Pro files (.fcp) with my applescript application and that doesn't work! It works for a single file, but the moment I click on change all (command+i ->open with->change all) it reverts back to Final Cut Pro. I tried repairing permissions. I tried using RCDefaultApp - that didn't work either.
    Just as a test, I wrote an applescript application that just opens textedit and tried to associate all my .txt files to my application and I had the same issue.
    I would really appreciate any help on this. Thanks!

    This happens because all AppleScript applications (at least those saved via the Script Editor) have the same application signature.
    In order to do this you need to use AppleScript Studio to create a document-based application and define a unique application signature. You then associate Final Cut Pro documents with your application's signature so that the OS will launch your app instead of FCP.
    You may be able to hack it by playing with the resources in the AppleScript app bundle but it's probably easier to do in AppleScript Studio.

  • Works great until I try to quit the app. Hangs every single time.

    Just updated to iLife 09 specifically to take advantage of the new iPhoto features. When I go to quit the app though, a small window drops down saying that it is saving data with a button that gives you the option to finish the save at a later time. Clicking this button will successfully quit the app. If I let the save go through, once the progress bar fills up, it starts blinking and will either 1) crash the app resulting in a message from the OS, or 2) remain on screen until I force quit.
    Running the latest version of iPhoto. Has happened ever since the initial iLife 09 install. Any help would be GREATLY appreciated!

    Library is in my "Pictures" folder. I never moved it out.
    I created a new library as you suggested, entered photos, tagged names, and quit. It quit right away without even stating that it needed to save anything like it does in my main library. The actual message I get when quitting my main Library is this:
    "iPhoto is saving critical information for your photo library. This information includes recent changes such as imported photos, album updates, and ratings. If you prefer, you can save this information later."
    There is a progress bar underneath, and a button that says "Later". If I click the button, it will quit. If I let it run through the save process, the progress bar fills up and then blinks indicating that the app has locked up. I even let it sit there for hours and it never quit after the progress bar was showing that it should be done.

Maybe you are looking for

  • Forgot Password on HP mini 110

    Hi I forgot the windows login password on my Hp mini 110-1135 CA There are not message appearing after 3 tries. It runs on Windows 7. Tranks

  • Ibook won't recognize certain CD-Rs (need help quick)

    I used my work PC to burn a CD-R ("Corporate Express" 700MB/80 min, 52x compatible). The disc includes a Powerpoint presentation and a few jpegs. My iBook sounds like it's trying to read it but nothing pops up in the Finder or Desktop. I see an un-na

  • DB start & Stop With Multiple Homes

    I have four instances on my box in total. Two instances(orcl & prod) run on a file system, One instance (+Asm) is ASM storage and the last instance(test) uses the asm storage. Following are the contents of my oratab file in /etc/oratab orcl:/u01/orac

  • Nikon Coolpix L1 not seen

    This could be related to my other problem of my 7900 not disappearing. but my L1 doesn't appear in iPhoto 6. It does appear and work just fine on my iBook with iPhoto 5. in system profiler, I see it show up on the USB bus, but it has Chinese letters

  • Tried to install iLife '11, now I'm stuck in a login loop

    First my MacBook froze up upon installation complete. So I restarted and now my login screen is stuck in a loop (I login, I see the blue screen, it goes back to the login screen). PLEASE HELP!