I have a script that is supposed to gather some values from different fields on a web page and add them in a CSV file. But something is halting it when preparing to append it to the file.
The script in all its glory is below and it is supposed to work with all ongoing tennis matches here: http://www.betfair.com/exchange/tennis Set the tennis match as the frontmost window in safari
global kampkob1, kampkob2, kampsalg1, kampsalg1, matchet, spiller1, spiller2, theString, filePath
set filePath to ("Macintosh HD:Brugere:anders:Skrivebord:" as text) & "kamp.csv"
tell application "System Events"
tell process "Safari"
try
set kampkob1 to name of button of UI element 2 of row 3 of table 1 of group 7 of group 1 of group 3 of UI element 1 of scroll area 1 of group 1 of group 1 of group 2 of window 1
set kampkob2 to name of button of UI element 2 of row 4 of table 1 of group 7 of group 1 of group 3 of UI element 1 of scroll area 1 of group 1 of group 1 of group 2 of window 1
set kampsalg1 to name of button of UI element 3 of row 3 of table 1 of group 7 of group 1 of group 3 of UI element 1 of scroll area 1 of group 1 of group 1 of group 2 of window 1
set kampsalg2 to name of button of UI element 3 of row 4 of table 1 of group 7 of group 1 of group 3 of UI element 1 of scroll area 1 of group 1 of group 1 of group 2 of window 1
set matchet to value of static text of group 1 of UI element 1 of row 2 of table 1 of group 7 of group 1 of group 3 of UI element 1 of scroll area 1 of group 1 of group 1 of group 2 of window 1
set spiller1 to value of static text of group 9 of group 3 of group 2 of group 1 of group 3 of UI element 1 of scroll area 1 of group 1 of group 1 of group 2 of window 1
set spiller2 to value of static text of group 9 of group 4 of group 2 of group 1 of group 3 of UI element 1 of scroll area 1 of group 1 of group 1 of group 2 of window 1
set theString to kampkob1 & kampkob2 & kampsalg1 & kampsalg2 & matchet & spiller1 & spiller2
end try
end tell
end tell
set theResult to writeTo(filePath, theString, text, true)
if not theResult then display dialog "There was an error writing the data!"
on writeTo(targetFile, theData, dataType, apendData)
-- targetFile is the path to the file you want to write
-- theData is the data you want in the file.
-- dataType is the data type of theData and it can be text, list, record etc.
-- apendData is true to append theData to the end of the current contents of the file or false to overwrite it
try
set targetFile to targetFile as text
set openFile to open for access file targetFile with write permission
if apendData is false then set eof of openFile to 0
write theData to openFile starting at eof as dataType
close access openFile
return true
on error
try
close access file targetFile
end try
return false
end try
end writeTo
The first half until the “end tells” my own while the rest is more or less a direct copy from a script by regulus 6633 in the thread here http://macscripter.net/viewtopic.php?id=36861. “My” part delivers a string like
{“1.07 1612”, “13.5 1241”, “1.08 15518”, “15.5 111”, "Matchet: ", “DKK 390.035”, “15”, “15”}
to the rest of the script but somehow somethings goes wrong already in the first line after “end tells”. Any suggestion on what I do wrong. Plus is my file path in the correct format? I have tried using “Users” and “Desktop” instead of “Brugere” and “Skrivebord” but it seems like it makes no difference.
Thank you.
Browser: Safari 600.1.25
Operating System: Mac OS X (10.8)