Get list from text file

I am having a bugger of a time with this


property myloc : missing value

tell application "Finder" to set MyLoc to container of (path to me) as text

set TheTimesPST to GetTime("PST")
set TheTimesEST to GetTime("EST")

on GetTime(zone)
	set LoadTimes to {""}
	if zone is "PST" then
		try
			set theFile to MyLoc & "PST.txt"
			--set open_file to open for access file theFile without write permission
			set LoadTimes to paragraphs of (read file theFile)
			close access open_file
		end try
	else if zone is "EST" then
		try
			set theFile to MyLoc & "EST.txt"
			--set open_file to open for access file theFile without write permission
			set LoadTimes to paragraphs of (read file theFile)
			close access open_file
		end try
	end if

	return LoadTimes
end GetTime

Both TheTimesPST and TheTimesEST come back blank

This can be more simply written as:

tell application "Finder" to set myloc to container of (path to me) as text
set theTimeEST to paragraphs of (read file (myloc & "EST.txt"))
set theTimePST to paragraphs of (read file (myloc & "PST.txt"))
{theTimeEST, theTimePST}

The problem is that when you dropped the open for access instruction, you forgot to drop the close access one.

Here is my slightly redesigned version :


property myloc : missing value

tell application "Finder" to set myloc to container of (path to me) as text

set TheTimesPST to GetTime("PST")
set TheTimesEST to GetTime("EST")
set myloc to missing value

on GetTime(zone)
	set LoadTimes to {}
	if zone is in {"PST", "EST"} then
		try
			set theFile to myloc & zone & ".txt"
			--set open_file to open for access file theFile without write permission
			set LoadTimes to paragraphs of (read file theFile)
			--close access open_file
		end try
	end if
	
	return LoadTimes
end GetTime

Yvan KOENIG (VALLAURIS, France) samedi 23 octobre 2010 21:21:16

Why do this when you can get the PST and EST times over the internet or through the command line? Ex:

do shell script "curl [url=http://www.providingtime.com/]http://www.providingtime.com/"[/url]

or

do shell script "date"

This is for a script that will be used in a company that is state wide. Each person will need to enter their own times into the EST.txt and PST.txt files.

Also thanks for the ideas guys. I’m goigng to give them a shot and see if I can get them working!