• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Saving to array list
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Saving to array list


  • Subject: Re: Saving to array list
  • From: Brian Christmas <email@hidden>
  • Date: Fri, 02 Nov 2012 21:00:47 +1100

On 02/11/2012, at 8:06 PM, Axel Luttgens <email@hidden> wrote:


> Hello Brian,
>
> I've had the opportunity to adapt your script so as to implement my suggestion (for the sake of clarity, I've removed the parts not directly related to your question).
>
> The idea is thus to first write an empty list to some file.
> This yields a file eight bytes long, with following data in hexadecimal:
> 	6c 69 73 74 00 00 00 00
> That data may be interpreted as:
> 	bytes 1 to 4: ascii characters 'list'
> 	bytes 5 to 8: 0 encoded as a 32-bit integer
>
> Appending an item to the list contained in the file is then just a matter of:
> 	increment the integer stored in bytes 5 to 8
> 	write the new item, in its binary form, to the end of the file.
>
> HTH,
> Axel
>
>
> property MailManagerFolderPath : ((path to desktop) as text) & "Mail Manager Folder:"
>
> set theZeroedDate to date ("1-1-2012")
> set c to current date
> initYearlyTally("2012 RunningTally")
> set DailyTally to read file (MailManagerFolderPath & " RunningTally") using delimiter ","
> repeat 365 times
> 	writeYearlyTally("2012 RunningTally", theZeroedDate, DailyTally)
> 	set theZeroedDate to theZeroedDate + 1 * days
> end repeat
> set YearlyTally to read file (MailManagerFolderPath & "2012 RunningTally") as list
> say (current date) - c
>
> on initYearlyTally(FileName)
> 	local fRef
> 	set fRef to open for access file (my MailManagerFolderPath & FileName) with write permission
> 	set eof fRef to 0
> 	write {} to fRef
> 	close access fRef
> end initYearlyTally
>
> on writeYearlyTally(FileName, writeitem1, writeitem2)
> 	local fRef, currListLength
> 	try
> 		set fRef to open for access file (my MailManagerFolderPath & FileName) with write permission
> 		set currListLength to read fRef from 5 to 8 as integer
> 		write (1 + currListLength) to fRef starting at 5
> 		write {writeitem1, writeitem2, return} to fRef starting at (1 + (get eof fRef))
> 		close access fRef
> 	on error errmsg
> 		try
> 			close access fRef
> 		end try
> 		display dialog errmsg
> 	end try
> end writeYearlyTally
>
G'day all

Thank you everyone for your input, but especially to Axel, whose method above works very, very well (less than 1 second).

I tried all suggestions, but needed to preserve the comma delimited list, as other aspects of my main program use that particular list, and I couldn't change it to a semi-colon delimited list. I have to preserve the days data when swapping from Leopard to Mountain Lion in a few weeks time.

I've learnt a lot about lists with vanilla Applescript in the last two days, and have kept all answers for future reference.

In Aussie slang... Good on yer fellas!

Regards

Santa
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >Re: Saving to array list (From: Axel Luttgens <email@hidden>)
 >Re: Saving to array list (From: Axel Luttgens <email@hidden>)

  • Prev by Date: Re: wrong result when trying to get Selection from finder window
  • Next by Date: Re: Mail navigation script
  • Previous by thread: Re: Saving to array list
  • Next by thread: Re: Saving to array list
  • Index(es):
    • Date
    • Thread