English Amiga Board


Go Back   English Amiga Board > Requests > request.Other

 
 
Thread Tools
Old 29 April 2021, 19:50   #1
KONEY
OctaMED Music Composer
 
KONEY's Avatar
 
Join Date: Jan 2009
Location: Venice - Italy
Age: 49
Posts: 666
Watch files for changes

Can anyone suggest an utility and/or and ARexx script to monitor a file for changes and eventually trig some events? Aminet didn't help me...

thanks!
KONEY is offline  
Old 29 April 2021, 20:33   #2
daxb
Registered User
 
Join Date: Oct 2009
Location: Germany
Posts: 3,303
What do you mean by monitor and what kind of changes exactly? With ARexx you can use STATEF() to compare file size, protection flags, time stamp and comment. Or you use checksum to compare. Should it work only while the program or script is running or does it need a database to compare with?
daxb is offline  
Old 29 April 2021, 22:00   #3
KONEY
OctaMED Music Composer
 
KONEY's Avatar
 
Join Date: Jan 2009
Location: Venice - Italy
Age: 49
Posts: 666
When a file is changed by any other program, so I guess timestamp is good.

I'll give a try to the AX command, thanks!
KONEY is offline  
Old 29 April 2021, 22:08   #4
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 6,985
dos.library has a function to get notified when a file is changed. IPrefs uses it for example to update prefs when a prefs editor exits with Use or Save.

But I am not aware of a utility which allows general use of this function. It shouldn't be too difficult to write one, though.
thomas is offline  
Old 30 April 2021, 11:29   #5
daxb
Registered User
 
Join Date: Oct 2009
Location: Germany
Posts: 3,303
It seems RMH (RexxMustHave http://aminet.net/package/util/rexx/rmh ) library contains notify functions that can be used for files. Yes, there is also an example notify.rexx.
daxb is offline  
Old 30 April 2021, 19:45   #6
KONEY
OctaMED Music Composer
 
KONEY's Avatar
 
Join Date: Jan 2009
Location: Venice - Italy
Age: 49
Posts: 666
daxb suggestion turned out to be of great value, with the power of ARexx do what I needed was as simple as this:

Code:
/* watch a file and execute it, useful to test code compiled externally */

SAY "WATCH A FILE FOR CHANGES AND EXECUTE IN CASE"
SAY "ARexx script by KONEY 2021"
SAY "--------------------------------------------------"

library = 'rexxsupport.library'
IF ~SHOW( 'L', library ) THEN DO
	IF ~ADDLIB( library, 0, -30, 0 ) THEN DO
		SAY 'Failed to add library ' || library || '.'
		EXIT 10
	END
END

initial_file =  STATEF("j")
SAY initial_file 
loop=1
SAY "WATCHING..."
DO until loop > 1
	actual_file =  STATEF("j")
	IF actual_file ~=  initial_file THEN	DO
		SAY "CHANGES DETECTED!"
		ADDRESS COMMAND  "J  >NIL:"
		initial_file =  STATEF("j")
		END
END

EXIT
KONEY is offline  
Old 30 April 2021, 20:36   #7
daxb
Registered User
 
Join Date: Oct 2009
Location: Germany
Posts: 3,303
The problem is the "stupid" endless loop that has to be used. I would at least DELAY() the loop to save some CPU time. I've never tried but the RMH notify seems to be a better way:
Code:
/*
    Name:           notify.rexx
    Template:       FILE,CLIP=CLIPUNIT/K/N,TIMEOUT/K/N
    Description:    wait for a changes on a FILE or a CLIP with timeout
                    default for CLIP is 0
                    default for TIMEOUT is 10 seconds
*/

parm.1.value=0
parm.2.value=10

if ~RMHReadArgs("FILE,CLIP=CLIPUNIT/K/N,TIMEOUT/K/N") then do
    call PrintFault(IoErr(),ProgramName("NOEXT"))
    exit
end

if parm.1.value<0 | parm.2.value<0 | parm.2.value>100 then do
    call PrintFault(115,ProgramName("NOEXT"))
    exit
end

if ~parm.0.flag | parm.1.flag then name="CLIP"
else name=parm.0.value

if name=="CLIP" then noti=StartNotify(name,parm.1.value)
else noti=StartNotify(name)
if noti<0 then do
    call PrintFault(IoErr(),ProgramName("NOEXT"))
    exit
end
ns=NotifySignal(noti)

timer=CreateTimer()
ts=TimerSignal(timer)

call StartTimer(timer,parm.2.value)
mask=wait(or(ns,ts))
if and(mask,ns)~=0 then do
    if name=="CLIP" then do
        say "Clip unit" parm.1.value "changed"
        if ReadTextClip("C")~=0 then do
            say "Clip unit" parm.1.value "content is:"
            say c
        end
    end
    else say "File:" name "changed"
end
else if and(mask,ts)~=0 then say "Timeout"
call FreeNotify(noti)
daxb is offline  
Old 30 April 2021, 20:57   #8
KONEY
OctaMED Music Composer
 
KONEY's Avatar
 
Join Date: Jan 2009
Location: Venice - Italy
Age: 49
Posts: 666
Thanks, I agree. But when I'm executing this I'm basically waiting for some code to be compiled into the "J" executable which when is ran it takes over the OS, until exited then waits for some code... in loop
KONEY is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Watch this space.............. Galahad/FLT Amiga scene 31 02 February 2024 13:09
The Amiga(like) Smart Watch stevelord News 9 02 July 2020 15:36
Amiga promo watch dreamkatcha Nostalgia & memories 3 18 November 2015 18:17
Watch your time mai request.Old Rare Games 3 11 August 2012 16:27
ebay watch Imran MarketPlace 6 04 September 2005 04:40

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 08:27.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.13910 seconds with 13 queries