Getting a script to run itself recursively
Getting a script to run itself recursively
- Subject: Getting a script to run itself recursively
- From: Jim Witte <email@hidden>
- Date: Sun, 27 May 2007 03:17:01 -0400
I've got the following script fragment, which tries to get the path
to the current script file, and then tell the Finder to run itself:
set sPath to the path of (item 1 of the document of me)
-- 'path of me' strangely enough returns BOTH the script file path,
-- AND the path to 'Standard Additions' - presumably because
-- I use it here, even though it is definitely not what I'd think of as
-- 'me' in this context (coming from a HyperTalk/Transcript bkg
-- that is..)
display dialog sPath
display dialog "Contune?" buttons {"Yes", "No"}
if button returned of the result is "Yes" then
run script ("ilamp:Users:billw:Destop:Untitled.scpt") as file
-- run script sPath --as file
end if
But the finder apparently wants a 'file' type object, and sPath is
a string, and I see no way to either coerce the string into a 'file',
or to create a 'file' (or alias) object/type that points to the path
sPath.. Sigh.. Why can't programming languages simply do coercions
like this automatically? (Or can someone convince Runtime/MetaCard
to make Transcript into a full OSA-complient grammar - after prying
the format of the grammar file out of Apple's cold dead hands.. if
that's possible..)
What I want to do in the context of my actual script (a poor-man's
iTunes alarm clock with fade-in, which I really should just redesign
from scratch..) is for the computer to check the time, put the
computer *back* to sleep if it isn't correct (after 6 am), and then
(in a command queued the next time the computer wakes up), to run the
same script AGAIN. (My iMac flat panel has a funny habit of waking
itself up for unknown reasons.. The wake code is 0x0040 in Console,
if that means anything to anyone)
Ideally, the script should tell the computer to run itself, then
tell the computer to sleep, and then (when it wakes up again) end the
FIRST instance of the script.. Is there a way to make (properly tail-
recursive) recursive scripts like this, or would it be better to just
set it up as a loop, or a tail-recursive procedure call within the
script itself, so it never has to worry about getting the finder to
run itself again..
Jim
_______________________________________________
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