[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference 7.286::macintosh

Title:Apple Macintosh Volume II
Notice:Mac is NOT an acronym - it's Mac or Macintosh *not* MAC
Moderator:SMURF::BINDERONS
Created:Sun Jan 20 1991
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:964
Total number of notes:30983

963.0. "AppleScript Exchange" by SMURF::BINDER (Errabit quicquid errare potest.) Fri May 16 1997 13:20

    This note is a place to share your AppleScripts with others.  Please
    confine replies to this note to actual AppleScript source - discussion
    of AppleScript is in Topic 550.
    
    -dick
T.RTitleUserPersonal
Name
DateLines
963.1Clock synchronization on a networkSMURF::BINDERErrabit quicquid errare potest.Fri May 16 1997 13:2676
(*
    This AppleScript sets a client Macintosh's clock by synchronizing it
    over AppleTalk to the clock of another Macintosh that has a copy of
    Jeremy Kezer's ClockSync applet.  The applet must reside on the server,
    and it must be run from the client.
    
    To work properly, this script must be saved as an application!  If it
    is saved as a compiled script, it will not remember the information
    it needs from one invocation to the next.
    
    This script should be run from the Startup Items folder.  It will
    attempt to set the clock at each startup until it succeeds.  Upon
    success, it stores the name of the day of the week and a counter until
    next Monday.  At each startup thereafter it checks to see whether it
    already set the clock today.  If not, it checks to see whether today is
    Monday.  If so, the clock synchronism is attempted and will be repeated
    at each startup until successful.
    
    The first time the script runs, it will ask the user to find the
    ClockSync applet on the server system.  Thereafter, it will remember
    where the applet is.
*)

property appletPath : "" -- Location of the ClockSync applet, set by file-selection dialog.
property clockSetDay : "" -- On what day of the week did we last set the clock?
property clockSetDelay : 0 -- How many days until Monday?
property serverDisk : "" -- Disk the ClockSync applet lives on, for network checking.
property today : "" -- What day is today?  Did we already set the clock today?

set today to word 1 of ((current date) as string) -- What day of the week is today?

if today � clockSetDay then -- Attempt something only if we haven't already set the clock today.
    if clockSetDelay > 0 then -- It's not Monday yet.
        setDelayDays() -- Set to count down to next Monday.
    else
        if appletPath = "" then -- Go through this if it's the first time we've run in this system.
            choose file with prompt "Please locate the ClockSync applet:" -- Where is the ClockSync applet?
            set appletPath to the result as text
            set saveDelim to AppleScript's text item delimiters
            set AppleScript's text item delimiters to ":"
            set serverDisk to word 1 of appletPath -- Save the server disk name for testing.
            set AppleScript's text item delimiters to saveDelim
            setMyClock() -- Go ahead and set the clock.
        else -- Go this way if we already know where the applet is.
            if (list disks) contains serverDisk then -- Is the server's disk mounted?
                setMyClock() -- Yup, set the clock.
            else
                display dialog "Cannot set clock because the disk �" & serverDisk & "� is not mounted." buttons �
                    {"OK"} default button "OK"
                error number -128 -- Bomb out with "Cancel" error.
            end if
        end if
    end if
end if

on setMyClock()
    try
        tell application "Finder"
            open file appletPath -- Fire off ClockSync.
        end tell
        set clockSetDay to word 1 of ((current date) as string) -- Remember today so we won't run again.
        setDelayDays() -- Set to count down to next Monday.
    on error
        display dialog "Cannot set clock due to an error launching ClockSync." buttons �
            {"OK"} default button "OK"
        error number -128 -- Bomb out with a "Cancel" error.
    end try
end setMyClock

on setDelayDays()
    repeat with counter from 1 to 7
        if word counter of "Monday Tuesday Wednesday Thursday Friday Saturday Sunday" = today then
            set clockSetDelay to 8 - counter -- Set the delay counter to wait until Monday.
        end if
    end repeat
end setDelayDays