Reputation: 87
I'm using my script to check a text file and send updates to me based on its changes.
Everytime I use the "property" tag inside of a "repeat" tag, it malfunctions and gives me the error: "Expected “end” but found “property”." I could use "set", but I don't want the value reset everytime the script is repeated. Thank you!
repeat
set theCEXRaw to read file "Macintosh HD:Users:adamvallorani:Desktop:CEX:CEXRaw"
set theGHS to paragraph 11 of theCEXRaw
set theBTC to paragraph 13 of theCEXRaw
set thePRICE to paragraph 26 of theCEXRaw
property oldBTC : 0
if theBTC > oldBTC then
set theBTC to oldBTC
set notif to "Your BTC has increased!"
display notification notif with title "CEXalert"
end if
set BuyGHS to "0.02356001"
set SellGHS to "0.02361999"
if thePRICE > SellGHS then
set notif2 to "Sell your GHS now!"
display notification notif2 with title "CEXalert"
end if
if thePRICE < BuyGHS then
set notif3 to "Buy some GHS now!"
display notification notif3 with title "CEXalert"
end if
delay 2
end repeat
the "property" line is where the error -Expected “end” but found “property”- occurs
Upvotes: 2
Views: 683
Reputation: 13181
Solution
At first glance I thought you might have a scoping problem because one must move the property statement outside of the repeat loop. To be effective properties must be defined outside of and before the repeat loop. But that is not exactly correct. Properties are values which retain their state after the script executes and so you will need to consider if this is the appropriate way to capture your value (the property value will be retained between script runs). It would be more appropriate to create a top level variable outside of the repeat statement using a line like:
set variablename to 0 -- or some other value
This will force the variable to reset each time the script runs and provide the proper values one would expect.
If you are trying to save a script property rather than a variable you can see some very good examples on how to do this at the following page of the Applescript Language Guide. Also note the language for how these are scoped in Applescript.
If all else fails you can adopt some code like the following which will allow you to log the variable within the loop:
set wordList to words in "Where is the hammer?"
repeat with currentWord in wordList
log currentWord
if contents of currentWord is equal to "hammer" then
display dialog "I found the hammer!"
end if
end repeat
Please keep in mind that the variable must be set initially outside of the repeat loop and then changed as needed within the loop. A simpler way to accomplish this would be to use the value inside your repeat loop by assigning it to a temporary variable and logging the results to make sure you get exactly what is needed.
Upvotes: 0
Reputation: 697
Property statements are declarations that create pre-initialized global variables and must appear outside any handler code. If you move the property statement to the top of your script AppleScript will accept it. For the purposes of you example, you can simply say set oldBTC to 0
.
Upvotes: 2