anyone write an ap that runs constantly in the background.
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
anyone write an ap that runs constantly in the background.
Hi I was wondering if anyone had any experience relating to having a livecode ap that runs constantly in the background for instance checking to see if the contents of a folder has changesd and if so updating a database.
Would a acceptable plan be to on ap launch begin tracking the time and every 10 seconds check the folder contents of a folder and if the contents has changed then take action. Any potential problems with this?
Dave
Would a acceptable plan be to on ap launch begin tracking the time and every 10 seconds check the folder contents of a folder and if the contents has changed then take action. Any potential problems with this?
Dave
Re: anyone write an ap that runs constantly in the backgroun
Hi Dave,
Sure, you can do that. Use send in 10 secs to repeatedly check the value of the files function.
The only downside is that your hard disk will never ever spin down and will have a much shorter life span and if you'd drain the battery if using a laptop. A much better way would be to have the operating system send a message to your app when the folder changes. The Mac can do this with folder actions. I don't know how to do this on Windows and Linux. Maybe you could do it with AutoIt.
If you tell a little more about the purpose of your app, then I/we/someone might come up with a better alternative.
Kind regards,
Mark
Sure, you can do that. Use send in 10 secs to repeatedly check the value of the files function.
The only downside is that your hard disk will never ever spin down and will have a much shorter life span and if you'd drain the battery if using a laptop. A much better way would be to have the operating system send a message to your app when the folder changes. The Mac can do this with folder actions. I don't know how to do this on Windows and Linux. Maybe you could do it with AutoIt.
If you tell a little more about the purpose of your app, then I/we/someone might come up with a better alternative.
Kind regards,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Re: anyone write an ap that runs constantly in the backgroun
What Mark said.
Make two stacks. In each make a button and a field. Put this into the button script of stack 1:
In the button in stack 2:
If you press the button in stack 1, you will start an incrementing value in the field. This will run while you navigate over to stack 2 (or anywhere else), where you can press the button all day to create random numbers in the stack 2 field. Go anywhere, the counter runs, and you can do your file thing instead of counting integers.
Eventually, the counter in stack 1 will stop. Read up on the pendingmessages to see how this works. Write back if you need to.
Craig Newman
Make two stacks. In each make a button and a field. Put this into the button script of stack 1:
Code: Select all
on mouseup
put 0 into fld 1
doThis
end mouseup
on doThis
if fld 1 > 20 then
put the pendingmessages into pend
repeat for each line thisMessageID in pend
cancel item 1 of thisMessageID
end repeat
exit to top
end if
add 1 to fld 1
send "doThis" to me in 2 seconds
end doThis
Code: Select all
on mouseUp
put random(99) into fld 1
end mouseUp
Eventually, the counter in stack 1 will stop. Read up on the pendingmessages to see how this works. Write back if you need to.
Craig Newman
Re: anyone write an ap that runs constantly in the backgroun
Thanks for the info. A little more on the project.
The idea is to use live code to check every few seconds to see if a text file or text file(s) have been added to a collection folder on a windows PC. The text files will have a date time stamp for a file name. Runrev can put the name of the file into a container and check it against the last date timestamp that it processed and saved . If the folder contains a new text file then read 15 lines of data from the text file, launch an irev file on a web server to connect to the MySQL database and INSERT the 15 lines of data into the MySql database on the web server, then place the processed text file into a secondary historical collection folder. Leaving the first folder empty and waiting for another update.
Users in the field get a page letting them know there is new info that needs to be acted on. They click a button on their iPad and a Irev page is activated, processes a POST request to the web server db, and updates their screen with the data.
It's EMS emergency response data. The dispatch data will be printed via a text file to the folder as well as broadcast over the radio. Clicking the button on the iPad gives responders a hard copy of the dispatch info.
Dave
The idea is to use live code to check every few seconds to see if a text file or text file(s) have been added to a collection folder on a windows PC. The text files will have a date time stamp for a file name. Runrev can put the name of the file into a container and check it against the last date timestamp that it processed and saved . If the folder contains a new text file then read 15 lines of data from the text file, launch an irev file on a web server to connect to the MySQL database and INSERT the 15 lines of data into the MySql database on the web server, then place the processed text file into a secondary historical collection folder. Leaving the first folder empty and waiting for another update.
Users in the field get a page letting them know there is new info that needs to be acted on. They click a button on their iPad and a Irev page is activated, processes a POST request to the web server db, and updates their screen with the data.
It's EMS emergency response data. The dispatch data will be printed via a text file to the folder as well as broadcast over the radio. Clicking the button on the iPad gives responders a hard copy of the dispatch info.
Dave
Re: anyone write an ap that runs constantly in the backgroun
Hi Dave,
If there is a person who manually puts the text files into the folder, then I'd create a standalone and tell the user to drop the files on top of the standalone instead of the folder. The standalone grabs the file path, does what you want and eventually puts the file into the historical folder. This avoids the repeated checking of the folder. If the user does difficult about this, you could change the icon of the standalone into a folder icon
If the user doesn't put the files into the folder manually, then I'll need more details.
Best,
Mark
If there is a person who manually puts the text files into the folder, then I'd create a standalone and tell the user to drop the files on top of the standalone instead of the folder. The standalone grabs the file path, does what you want and eventually puts the file into the historical folder. This avoids the repeated checking of the folder. If the user does difficult about this, you could change the icon of the standalone into a folder icon

If the user doesn't put the files into the folder manually, then I'll need more details.
Best,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Re: anyone write an ap that runs constantly in the backgroun
Thats a great idea that I will hold for the future! In this case however a text file is being sent across town to a printer. We are intercepting the text file and printing it to disk (electonicly placing it in the collection folder) and then passing the data along to the printer. We would like to get that hard copy out to the users in the field the users that are away from the printer.
The dispatchers that type in the data originaly dispatch units via CAD and send the data to our printer. They have other agencies they answer to and have little interest in altering there operation based on our needs. Hence the work around. Thanks for all your ideas. That gives me something to work with.
Dave
The dispatchers that type in the data originaly dispatch units via CAD and send the data to our printer. They have other agencies they answer to and have little interest in altering there operation based on our needs. Hence the work around. Thanks for all your ideas. That gives me something to work with.
Dave
Re: anyone write an ap that runs constantly in the backgroun
Dave,
I've used a few scripts I've found online (including here) that I can, for example, use as macros within Outlook to extract certain emails to a file of key:value pairs placed in a designated inbox folder, then launch a standalone stack (sReader.exe in the example) that looks in the inbox for new files then parses any it finds, records their content, and fires off some other specific stack. Here's one I use, written in VBA:
I didn't create it, I extracted it from a number of examples I found on line, like MSDN.
I also recently read an article about using Windows Event Viewer to assign tasks to events that looks promising, but haven't tried it yet - while exploring, the number of available Windows events to drill into to figure which ones to use is daunting.
http://blogs.technet.com/b/wincat/arch ... vent.aspx
I've used a few scripts I've found online (including here) that I can, for example, use as macros within Outlook to extract certain emails to a file of key:value pairs placed in a designated inbox folder, then launch a standalone stack (sReader.exe in the example) that looks in the inbox for new files then parses any it finds, records their content, and fires off some other specific stack. Here's one I use, written in VBA:
Code: Select all
Sub TriggerReader(MyMail As MailItem)
Dim strID As String
Dim objMail As Outlook.MailItem
Dim newFileName As String
Dim objFSO
Dim outFile
Dim inboxPath As String
Dim objShell
On Error Resume Next
inboxPath = "C:\AWork\InBox\"
strID = MyMail.EntryID
Set objMail = Application.Session.GetItemFromID(strID)
Set objFSO = CreateObject("Scripting.FileSystemObject")
newFileName = inboxPath & "z" & objMail.EntryID & ".txt"
Set outFile = objFSO.CreateTextFile(newFileName)
outFile.writeLine "rSubj: " & objMail.Subject
outFile.writeLine "rTo: " & objMail.To
outFile.writeLine "rCC: " & objMail.CC
outFile.writeLine "rName: " & objMail.SenderName
outFile.writeLine "rAddr: " & objMail.SenderEmailAddress
outFile.writeLine "rSent: " & objMail.SentOn
outFile.writeLine "rRecip: " & objMail.Recipients -- NG, delete this line.
outFile.writeLine "rCreation: " & objMail.CreationTime
outFile.writeLine "rBody: " & objMail.Body
outFile.writeLine "---------------------"
outFile.writeLine "rHTML: " & objMail.HTMLBody
outFile.writeLine "---------------------"
outFile.Close
Set objShell = CreateObject("WScript.shell")
objShell.Run ("C:\AWork\sReader.exe")
Set objMail = Nothing
Set objFSO = Nothing
Set outFile = Nothing
Set objShell = Nothing
End Sub
I also recently read an article about using Windows Event Viewer to assign tasks to events that looks promising, but haven't tried it yet - while exploring, the number of available Windows events to drill into to figure which ones to use is daunting.
http://blogs.technet.com/b/wincat/arch ... vent.aspx
Walt Brown
Omnis traductor traditor
Omnis traductor traditor