• 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: on idle() handler in script object
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: on idle() handler in script object


  • Subject: Re: on idle() handler in script object
  • From: has <email@hidden>
  • Date: Thu, 25 Aug 2005 21:05:25 +0100

Simon Forster wrote:

> > If you describe what it is you're trying to achieve, maybe a
> > solution can be suggested.
>
>Folder action script (which is applied to any sub-folders within the
>defined top level folder too). When a file is created in the folder
>(or its sub-folder(s)), the file size is checked every x seconds
>[...]
>I guess I'll use a technique similar to the one I employed last time
>- basically a queue of script objects which the main script loops
>through.

That's what I'd do, though I'd probably punt the monitoring part out of the folder action script and into a stay-open applet. You don't really need anything fancy. Something like:

property _kDelay : 2
property _jobQueue : {}

on idle
	repeat with oRef in _jobQueue
		oRef's process() returning isFinished
		if isFinished then set oRef's contents to missing value
	end repeat
	set _jobQueue to _jobQueue's scripts
	return _kDelay
end idle

on addJob(theFile)
	script
		property _file : theFile
		property _previousSize : 0

		on process()
			set currentSize to size of (info for _file)
			set isFinished to currentSize is _previousSize
			if isFinished then
				--perform backup and write to log
			else
				set _previousSize to currentSize
			end if
			return isFinished
		end process
	end script
	set end of _jobQueue to result
end addJob

The folder action script then calls the applet's addJob handler for each file to be processed.

has
--
http://freespace.virgin.net/hamish.sanderson/
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: on idle() handler in script object
      • From: Simon Forster <email@hidden>
  • Prev by Date: Re: [newby] Detect if a script was started from the command line
  • Next by Date: Re: Folder action to rename files
  • Previous by thread: Re: on idle() handler in script object
  • Next by thread: Re: on idle() handler in script object
  • Index(es):
    • Date
    • Thread