• 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: Choosing files
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Choosing files


  • Subject: Re: Choosing files
  • From: Shane Stanley <email@hidden>
  • Date: Sat, 15 Nov 2014 10:27:07 +1100

On 14 Nov 2014, at 12:52 pm, Shane Stanley <email@hidden> wrote:

Before you run the following code, a warning: ASObjC code that involves drawing stuff on screen, like this, has to be run in the foreground on what is known as the main thread. Scripts are nearly always run on the main thread -- the one exception being in script editors, where they are usually run on background threads. So when you are trying out this code, if you don't run it in the foreground, you will crash your editor.

But when you're testing code, it's easy to forget. To be safe, you can insert the following snippet after the use statements:

if not (current application's NSThread's isMainThread()) as boolean then
display alert "This script must be run from the main thread." buttons {"Cancel"} as critical
error number -128
end if

Then if you accidentally run on a background thread, you will get an alert instead of a potential crash.

-- 
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>

 _______________________________________________
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

References: 
 >Choosing files (From: Shane Stanley <email@hidden>)
 >Re: Choosing files (From: Shane Stanley <email@hidden>)
 >Re: Choosing files (From: Shane Stanley <email@hidden>)

  • Prev by Date: Re: Choosing files
  • Next by Date: SpeechRecognitionServer gone?
  • Previous by thread: Re: Choosing files
  • Next by thread: Re: Choosing files
  • Index(es):
    • Date
    • Thread