How to silently exit a Folder Action?

Hi all,

A client’s primary in-house software application writes a backup file to a certain folder. The server (which runs 24/7) will create the backup file once per day, including on Sunday; however, the office is only open for business Monday-Saturday.

I’ve written a Folder Action that keeps an eye on the backup folder for each day’s new, daily backup file, then automagically copies the new file to an external hard drive, and to a USB keychain drive. The external hard drive is always connected; the keychain drives are automagically ejected once the copy has completed, then swapped out once per day with the next day’s keychain drive so as to be prepared for the following evening’s backup (the keychains go off-site for disaster protection). It’s actually quite pretty, with prompts for keychain drives with the proper volume name, automagic ejecting of the keychain drive and a “go home!” confirmation, etc.

The Folder Action works great, Monday-Saturday. However, I would like to make the Folder Action simply exit on Sunday (without attempting to copy the backed-up data), as no actual transactions take place that day and regardless, there’s no one there to swap out the keychain drive when they’re prompted to do so. I suppose I could enclose everything in the following:

if (weekday of (current date)) is not "Sunday" then
work my mojo
end if

However, that seems heavy-handed to me. In a larger sense (and my apologies if this is one of those I’ve-forgotten-more-than-many-will-ever-know moments), I’d like to use something like the following:

if (weekday of current date)) is "Sunday" then
quietly end this script, exit out gracefully with no dialogs, and have a nice day
end if

I’m not looking for a full-on re-write of my existing code”instead, just the construct needed to tell the Folder Action to stop in its tracks, without generating a visible error message.

Any tips for a fellow scripter? :wink:

Thanks much for the time,
MBJ

Hello

You may try:

if (weekday of current date)) is "Sunday" then return

Yvan KOENIG (from FRANCE mercredi 11 octobre 2006 19:38:7)

Hi Yvan,

Thanks for that, and that had been my first thought. You indirectly helped me to sort it out, so I’ll describe same here for the benefit of otherrs.

For those just wanting to know how to cleanly exit out of a Folder Action, it’s the same as if you wanted to exit cleanly out of any other script: just use “return”.

~ ~ ~

Note that for all examples to follow, I’ve artificially changed the date on my test system to reflect Sunday.

First: The following example will still beep when run in Script Editor:

if weekday of (current date) is "Sunday" then return
beep

Interestingly: If I change it to “is not”, the script does exit cleanly:

if weekday of (current date) is not "Sunday" then return
beep

That led me to consider the obvious: “Sunday” in quotes is a text string, which is not what is returned by:

get weekday of (current date)

With that new bit of knowledge, the following example works properly (no beep):

if weekday of (current date) is Sunday then return
beep

So that’s it! Again, I appreciate the tip from Yvan that was able to lead me in the right direction. Thanks so much! :smiley:

Best wishes,
MBJ

hi ms,

try:


if ((weekday of (current date))) is "Sunday" then
	return
else
	beep
end if

you need to wrap the code in the conditional if block.

cheers.

hi ms,

i actually had some trouble w/ that code, so i tried this instead:


set currDate to (current date) as string
if word 1 of currDate is "Sunday" then
	return
else
	beep
end if

seems to work better…

cheers.