• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to make an app quit
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to make an app quit


  • Subject: Re: How to make an app quit
  • From: Andrew Oliver via AppleScript-Users <email@hidden>
  • Date: Wed, 21 Oct 2020 16:39:22 -0700

You should switch this to an idle() handler rather than run.

As written, 99.9% of the time your script is stuck in the ‘delay 60’ statement.
It won’t respond to other events (such as Quit) during this time. It might
respond on the next iteration, but you’d have to wait up to 59.9 seconds to
find that out.

By comparison, an idle handler is designed to sit in the background,
automatically waking up on schedule to perform its task. It should then respond
to Quit commands appropriately.

The change is simple, replace your repeat… end repeat loop with an on idle… end
idle handler, and instead of including ‘delay 60’, return 60 as the number of
seconds before the handler should run again. E.g.:

property Done: false

on idle
    doSomething()

    return 60
end idle

on quit
  set done to true — not sure if you need this, but your internal code might
reference it
continue quit


When you save the app you need to enable the ’Stay Open’ option so that the
idle handler is called appropriately.
Now the doSomething() block will run every 60 seconds until quit.


> On Oct 21, 2020, at 3:39 PM, Gil Dawson via AppleScript-Users
> <email@hidden> wrote:
>
> Hi--
>
> I made an app to check some stuff.  Once it was working, I made a few changes
> so that it would run every minute, then saved it as an app.
>
> It works fine, EXCEPT that it won't quit when I tell it to Quit.  (But Force
> Quit works.)
>
> Below is a skeleton of my code.  Is this enough to figure out what I'm
> missing?
>
> --Gil
>
>
> property Done : false
>
> repeat until Done
>       try
>
>               # tell...
>               # if (X) then error...
>
>               # The "--" lines allow me to ⌘R this script for testing.
>
>               --              return
>
>               delay 60 -- not used when testing
>
>       on error errm number errn
>               --      log "Error: " & errm & " (" & errn & ")"
>               --      return
>       end try
> end repeat
>
> on quit
>       set Done to true
>       continue quit
> end quit
>
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> AppleScript-Users mailing list      (email@hidden)
> Help/Unsubscribe/Update your Subscription:
> Archives: http://lists.apple.com/archives/applescript-users
>
> This email sent to email@hidden

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: How to make an app quit
      • From: Gil Dawson via AppleScript-Users <email@hidden>
References: 
 >How to make an app quit (From: Gil Dawson via AppleScript-Users <email@hidden>)

  • Prev by Date: How to make an app quit
  • Next by Date: Architecture of Audio Plug-ins via AppleSctript or via shell?
  • Previous by thread: How to make an app quit
  • Next by thread: Re: How to make an app quit
  • Index(es):
    • Date
    • Thread