I’ve got a heap of datafiles being saved in the following way, where ‘StartTime’ is based on the ‘Current date’ format.
My problem is in reading the info back. Setting a variable, even as ‘as date’ to item 3 of the list results in…
<NSAppleEventDescriptor: 'Idt '($string of 16 characters$)>
How can I convert this back to a date please?
Regards
Santa
set theWriteString to {}
set end of theWriteString to content of text field "initials" of window "Illustrator Interface"
set end of theWriteString to theclient
set end of theWriteString to StartTime
set end of theWriteString to ElapsedTime
set end of theWriteString to Znumber
set end of theWriteString to content of text field "Finished Name" of window "Illustrator Interface"
set end of theWriteString to ""
set end of theWriteString to ""
set end of theWriteString to ""
set thetempYear to year of (current date)
set IllPathFolder to "Ill Interface Data " & thetempYear as text
set IllPath to (path to desktop) & MailPrintingFolder as text
set IllfileName to "IllustratorInterfaceData.dat"
my writefile2(IllPath, IllPathFolder, IllfileName, theWriteString)
set StartTime to {}
assuming StartTime is of class date, the date will automatically be coerced to its string representation while appending it to a string. Consider that the format of the date string depends on the date format settings in the International PrefPane.
You can set a date variable by a string with this syntax
set myDate to date myLocalDateString
Edit: I overlooked that theWriteString is a list. So this post is not really helpful
It’s hard to say how to read things back when you don’t show how they’ve been written! You have a variable called ‘theWriteString’ which is actually a list. If you’re writing this list to your data file, you should be able to read it back ‘as list’ and have everything in it perfectly preserved.
Nigel the only thing not reading back correctly is the ‘current date’ saved as variable ‘StartTime’, which I mentioned above.
Using Stefans method…
tell application "Finder"
set temp to every folder of folder (ptd & MMFolder) as list
set theOpList to DataOperator
set theZList to {}
set theJobList to {}
set theStartList to {}
repeat with x in temp
if "Ill Interface Data" is in name of x then
try
set temp to file "IllustratorInterfaceData.dat" of x as text
set temp2 to read file temp as list
repeat with y in temp2 as list
if (item 1 of y is in theOpList) or theOpList = "Every Operator" then
if item 4 of y > 0 then
if item 2 of y = SelectedClient then
set end of theStartList to date ((item 3 of y))
set end of theZList to item 5 of y
set end of theJobList to item 6 of y
end if
end if
end if
end repeat
on error errmsg
display dialog errmsg
end try
end if
end repeat
end tell
I get an error message that ‘Finder got an error:Cant make date “Friday, 8 etc” into type integer.’
my method is nonsense, because when you read a file as list, you get all classes back.
First of all, avoid these hugh Finder tell blocks. Read/write belongs to Standard Additions,
the Finder is not needed.
Second of all, maybe there is a misunderstanding: With the syntax
repeat with y in temp2
y contains item 1 of temp2 (actually a reference to item 1 of the list) in the first loop, item 2 of temp2 in the next one and so on. Item 1 of y might be just one character, if item 1 of temp2 is a string.
BTW: After reading the text file as list, temp2 is a list, the coercion in the repeat line is useless (as well as the coercion in the second line )
Thanks for the input fellas, but the situation looks impossible. I’ve tried all sorts of things, even trying to generate the time string from the error messages, but inexplicably the code does not error the same every time.
I had an afternoon siesta, and woke up with the answer.
I made a stupid mistake with…
set temp to file "IllustratorInterfaceData.dat" of x as text
when it should have been…
tell application "Finder"
set temp to every folder of disk "Jobs" as list
end tell
set theOpList to DataOperator
set theZList to {}
set theJobList to {}
set theStartList to {}
repeat with x in temp
if "Ill Interface Data" is in name of x then
set temp to name of x as text
if DataYear = word 4 of temp then
try
set temp3 to ((x as text) & "IllustratorInterfaceData.dat") as text
tell application "Finder"
set temp2 to read file temp3 as list
end tell
repeat with y in temp2
if (item 1 of y is in theOpList) or theOpList = "Every Operator" then
if item 4 of y > 0 then
if item 2 of y = SelectedClient then
set end of theStartList to (item 3 of y) as date as text
set end of theZList to item 5 of y
set end of theJobList to item 6 of y
end if
end if
end if
end repeat
on error errmsg
display dialog errmsg
end try
end if
end if
end repeat
Works fine now, thanks for the encouragement, and for persevering with me
Regards
Santa
PS the Finder loop to read is necessary cause it’s part of an Xcode project.