Applescript Error, End of file error

Discussion in 'Mac Programming' started by thriftinkid, Jun 26, 2008.

  1. thriftinkid macrumors regular

    Mar 24, 2008
    Hey guys,

    I have been using this script on another machine using an automator workflow, and it has been running fine.

    When I switch to a different computer I got the following error:

    Applescript Error

    End of line (-39)

    Here is the following applescript I found that I have been using:

    	--direct to your plain text file with addresses, and name, tab delimited
    	set sourceFile to open for access "Macintosh HD:Users:CS4:Movies:address.txt"
    	set theAddressDOC to read sourceFile
    	close access sourceFile
    	set pcount to count paragraphs in theAddressDOC
    	repeat with i from 1 to number of paragraphs in theAddressDOC
    		set this_item to paragraph i of theAddressDOC
    		set Name_text to "" -- set to blank
    		-- using try so if there is a an error, in this case it will be when the is no name, the script will carry on
    		-- instead of stopping. The Name_text will reamin as "" if it does
    			--use delimiters (tab) in this case to split the result of this_item and try to set Name_text to the name
    			set AppleScript's text item delimiters to tab
    			set para_text to text of this_item
    			--get the second half of paragraph
    			set Name_text to text item 2 of para_text
    		end try
    		--get the first half of paragraph
    		set address_text to text item 1 of para_text
    		--reset the delimiters
    		set AppleScript's text item delimiters to ""
    		set theAddress to address_text
    		-- direct to a doc of what you want the email to say in plain text
    		set sourceFile to open for access "Macintosh HD:Users:CS4:Movies:web links body text.txt"
    		set theletter to read sourceFile
    		close access sourceFile
    		-- What is the subject of the Emails
    		set theSubject to "Here Are Your Requested Uploaded Links"
    		-- Check to see if Name_text contains a name or not
    		if Name_text is "" then
    			--if no name
    			set theBody to " you to view" & theletter
    			--the must be a name
    			set theBody to "Here are the links for " & Name_text & theletter
    		end if
    		-- Choose the account to send the message from
    		set theSender to ""
    		tell application "Mail"
    			set newMessage to make new outgoing message with properties {subject:theSubject, content:theBody & return & return}
    			tell newMessage
    				-- Default is false. Determines whether the compose window will
    				-- show on the screen or whether it will happen in the background.
    				set visible to true
    				set sender to theSender
    				make new to recipient at end of to recipients with properties {address:theAddress}
    				tell content
    					tell application "Mail"
    						send newMessage
    					end tell
    					-- delay to allow the Mail program to send and not bog down, adjust as needed
    					delay 10
    				end tell
    			end tell
    		end tell
    	end repeat
    Automator highlighted read sourcFile in the line:

    "set theletter to read sourceFile"

    Any idea what's going on here? Any help would be greatly appreciated.
  2. lee1210 macrumors 68040


    Jan 10, 2005
    Dallas, TX
    This might be something you've already checked, but on the other machine does the file:
    Macintosh HD:Users:CS4:Movies:web links body text.txt

    If it does exist, does it have a non-zero size?

  3. thriftinkid thread starter macrumors regular

    Mar 24, 2008
    Yeah it exists. I double checked the path as well to make sure it wasn't misspelled or looking for the file in the wrong place.
  4. thriftinkid thread starter macrumors regular

    Mar 24, 2008
    I actually think I figure it out LEE. It was a permissons issue for writing to that folder. I have taken care of it. There are some other issues, but I'm going to look into them for a bit first before posting again. Save you guys the headache
  5. schruteBeets macrumors newbie

    Jul 15, 2009
    thriftinkid, I'm having a very similar issue with one of my scripts and it'd be helpful to me if you could post whatever your fix was as I am sure we won't be the only ones to have this problem in the future. Thanks man.
  6. mysterytramp macrumors 65816


    Jul 17, 2008
    One possible way to debug something like this is to use a try block.

    	set theLetter to read sourceFile
    on error error_message number error_number
    	display alert "Error number: " & (error_number as string) & return ¬
    		& ("Message: ") & error_message
    end try
    The error numbers and messages can be obtuse, but they can provide at least a clue to what's wrong.


Share This Page