• 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: Still don't understand timeout
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Still don't understand timeout


  • Subject: Re: Still don't understand timeout
  • From: Robert Poland <email@hidden>
  • Date: Fri, 19 Aug 2011 14:21:07 -0600

Steve,

You're telling me that a single action like "set numberOfItemsInWindow to "error" (below) can't be controlled with the "timeout" function?

set numberOfItemsInWindow to "error"
try
with timeout of 2 seconds
tell application "Finder"
activate
tell application "System Events"
tell process "Finder"
tell menu 1 of menu bar item "Edit" of menu bar 1
click menu item "Select All"
end tell
end tell
end tell
tell application "Smile" to chrono
set itemsInWindow to selection -- selection is a large folder, over 220 items.
tell application "Smile" to set x to chrono
set x to "A - " & x
set numberOfItemsInWindow to count of itemsInWindow
end tell
end timeout
on error
beep 3
tell application "Smile" to set x to chrono
set x to "B - " & x
end try

tell application "Finder" to select {} -- deselect choice(s)
tell application "System Events"
activate
display dialog x & return & numberOfItemsInWindow as text
end tell


On Aug 19, 2011, at 1:16 PM, Steve Mills wrote:

On Aug 19, 2011, at 14:01:13, Robert Poland wrote:

If I understand right "with timeout" doesn't end and stop the block. Is there something that will do that?

A timeout is a per-command timeout. So if a *single* command doesn't return control back to the script within the timeout, then it'll force it to return control to the script. The same mechanism is provided as a parameter to the "display dialog" command (giving up after). Try it and you'll see.

If you want to force a loop to timeout once a given time limit is reached, you'll have to measure the time limit yourself.

set startTime to current date

repeat while true
set nowTime to current date

if (time of nowTime) - (time of startTime) ≥ 2 then exit repeat

say "z"
end repeat

The above won't work if startTime is before midnight and nowTime is after midnight. If you anticipate that happening, add the day of the month multiplied by the number of seconds in a month. But then that'll break if you start on the 31st and cross midnight into the 1st of the next month. Didn't there used to be a command called "the ticks" that returned the number of ticks since system boot? That was most useful.

--
Steve Mills
Drummer, Mac geek

Robert Poland - Fort Collins, CO



 _______________________________________________
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: Still don't understand timeout
      • From: Steve Mills <email@hidden>
    • Re: Still don't understand timeout
      • From: Axel Luttgens <email@hidden>
    • Re: Still don't understand timeout
      • From: Bill Cheeseman <email@hidden>
References: 
 >Re: Still don't understand timeout (From: Steve Mills <email@hidden>)

  • Prev by Date: Re: Still don't understand timeout
  • Next by Date: Re: Dock Preferences in Lion
  • Previous by thread: Re: Still don't understand timeout
  • Next by thread: Re: Still don't understand timeout
  • Index(es):
    • Date
    • Thread