Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

thriftinkid

macrumors regular
Original poster
Mar 24, 2008
119
0
Hey Guys,

I've been messing with a script I found that send out multiple emails to different people. The following script should read the email addresses I want to send the my message to from a .txt file called "address.txt" I got it to work through automator on one system with MAC OS 10.5. But I tested it on another system with 10.4 and I got the following error:

Applescript Error:

Can't make into type file.


Any ideas?

Here is the script, including the automator end tags:

Code:
on run {input, parameters}
	
	--direct to your plain text file with addresses, and name, tab delimited
	set theAddressDOC to read file
	("MacintoshHD:Users:test:Movies:address.txt")
	
	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
		try
			--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 theletter to file
		("MacintoshHD:Users:test:Movies:web links body text.txt")
		
		-- 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
			
		else
			--the must be a name
			set theBody to "Here are the links for " & Name_text & theletter
		end if
		theBody
		
		
		-- Choose the account to send the message from
		set theSender to "myemail@gmail.com"
		
		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
	return input
end run
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
Add some:
Code:
display dialog "Message here"

In there and narrow down where the error is happening. Once you know what line it is, if you still can't figure it out post again. Make each message different so you can tell exactly where in the script it's running into trouble.

I'm pretty sure there's a way to just put messages into the "console" in the script editor, but this should work fine for narrowing down where this is happening.

-Lee
 

thriftinkid

macrumors regular
Original poster
Mar 24, 2008
119
0
Add some:
Code:
display dialog "Message here"

In there and narrow down where the error is happening. Once you know what line it is, if you still can't figure it out post again. Make each message different so you can tell exactly where in the script it's running into trouble.

I'm pretty sure there's a way to just put messages into the "console" in the script editor, but this should work fine for narrowing down where this is happening.

-Lee

It is showing it can't read the bolded part of the following line:

set theAddressDOC to read file
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
I moved the ("MacintoshHD:Users:test:Movies:address.txt") onto the same line that had the error and it seemed to work properly.

-Lee
 

Sayer

macrumors 6502a
Jan 4, 2002
981
0
Austin, TX
There are two problems

  1. You have not defined the variable "file" before trying to use it
  2. You cannot use "file" as a variable name as it is a reserved keyword

Any of this not make sense to you?

How about doing:

set sourceFile to "MyHD:path:To:File.txt"

and then ... read sourceFile ?

You could even do at the beginning of the script: property sourceFile : "MyHD:path:To:File.txt"

This has the benefit of being editable from within/by the script and the changes saved within the script file automatically.
 

thriftinkid

macrumors regular
Original poster
Mar 24, 2008
119
0
There are two problems

  1. You have not defined the variable "file" before trying to use it
  2. You cannot use "file" as a variable name as it is a reserved keyword

Any of this not make sense to you?

How about doing:

set sourceFile to "MyHD:path:To:File.txt"

and then ... read sourceFile ?

You could even do at the beginning of the script: property sourceFile : "MyHD:path:To:File.txt"

This has the benefit of being editable from within/by the script and the changes saved within the script file automatically.

I tried setting the source file firstr, but I got the following syntax error:

Expected end of line, etc. but found “(”.
 

thriftinkid

macrumors regular
Original poster
Mar 24, 2008
119
0
I tried setting the source file firstr, but I got the following syntax error:

Expected end of line, etc. but found “(”.

I tried to re write it like the following:

Code:
set sourceFile to "MacintoshHD:Users:test:Movies:address.txt"
	set theAddressDOC to read sourceFile

and I got this applescript error:

Can't make "MacintoshHD:Users:test:Movies:address.txt" into type file.


I then re wrote it again like this:


Code:
set sourceFile to "MacintoshHD:Users:test:Movies:address.txt"
	set theAddressDOC to sourceFile

It ran the script. But when I looked at the out going mail message. Instead of applying the text within the text document "address.txt", it literally added the text documents location "MacintoshHD:Users:test:Movies:address.txt" into the header.
 

jeremy.king

macrumors 603
Jul 23, 2002
5,479
1
Holly Springs, NC
Code:
set sourceFile to open for access "MacintoshHD:Users:test:Movies:address.txt"
set theAddressDOC to read sourceFile 
close access sourceFile

This of course, assumes your file is there. You might be better off browsing for it.
 

thriftinkid

macrumors regular
Original poster
Mar 24, 2008
119
0
Code:
set sourceFile to open for access "MacintoshHD:Users:test:Movies:address.txt"
set theAddressDOC to read sourceFile 
close access sourceFile

This of course, assumes your file is there. You might be better off browsing for it.

I gave it a shot, but it started adding crazy amount of info, and I have no idea where it is pulling it from:

{\colortbl;\red255\green255\blue255;}\margl1440\margr1440\vieww9000\viewh8400\viewkind0

It kept opening up new mail messages and adding more similar text. None of this is the text from the "address.txt" document.
 

jeremy.king

macrumors 603
Jul 23, 2002
5,479
1
Holly Springs, NC
I gave it a shot, but it started adding crazy amount of info, and I have no idea where it is pulling it from:

{\colortbl;\red255\green255\blue255;}\margl1440\margr1440\vieww9000\viewh8400\viewkind0

It kept opening up new mail messages and adding more similar text. None of this is the text from the "address.txt" document.

You sure that's a text file you are dealing with? and not an RTF saved with a .txt file extension?
 

jeremy.king

macrumors 603
Jul 23, 2002
5,479
1
Holly Springs, NC
I don't believe so. Is there a way to make absolutely sure?

I think it is.

Open it in a real text editor, such as TextWrangler, TextMate, or vi and inspect the contents.

Or simply type the following in Terminal, and inspect the result.

Code:
cat /Users/test/Movies/address.txt

Just because something opens (or is created) with TextEdit, it doesn't mean it's a text file.
 

thriftinkid

macrumors regular
Original poster
Mar 24, 2008
119
0
I think it is.

Open it in a real text editor, such as TextWrangler, TextMate, or vi and inspect the contents.

Or simply type the following in Terminal, and inspect the result.

Code:
cat /Users/test/Movies/address.txt

Just because something opens (or is created) with TextEdit, it doesn't mean it's a text file.

the first response line from the terminal is:

{\rtf1\mac\ansicpg10000\cocoartf824\cocoasubrtf470

I'm assuming that would mean its an RTF. What is the difference? And can I changed the current coding, or do I have to go back and change the coding where that text document is actually created to save out differently?
 

jeremy.king

macrumors 603
Jul 23, 2002
5,479
1
Holly Springs, NC
the first response line from the terminal is:

{\rtf1\mac\ansicpg10000\cocoartf824\cocoasubrtf470

I'm assuming that would mean its an RTF. What is the difference? And can I changed the current coding, or do I have to go back and change the coding where that text document is actually created to save out differently?

I don't use TextEdit, but I would assume there is an option in the Save As dialog to make it plain text - which is what you want.
 

thriftinkid

macrumors regular
Original poster
Mar 24, 2008
119
0
I don't use TextEdit, but I would assume there is an option in the Save As dialog to make it plain text - which is what you want.

I checked before, and it didn't give me an option. I thought I bypassed it by specifying in my script how I wanted it saved. My other issue is that I already had this script working running with Mac OS 10.5. I am trying to put it on a system with 10.4, and now I'm getting these issues. Do you know why?
 

thriftinkid

macrumors regular
Original poster
Mar 24, 2008
119
0
I checked before, and it didn't give me an option. I thought I bypassed it by specifying in my script how I wanted it saved. My other issue is that I already had this script working running with Mac OS 10.5. I am trying to put it on a system with 10.4, and now I'm getting these issues. Do you know why?

I changed my preferences to automatically save to a plain text doc always, but it didn't help
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.