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

MacBoy88

macrumors regular
Original poster
Feb 4, 2003
202
147
Illinois
Applescript?

could this be done with an Applescript?? I don't know Applescript, so I would need some help.
 

Mr_Ed

macrumors 6502a
Mar 10, 2004
706
669
North and east of Mickeyland
I was bored . . . .

I was wondering how to do this some time ago and got distracted. Your question made me think of it again, and as I said, I was bored . . . :D

This is an AppleScript script that should do the trick if you attach it to a Mail rule.
Code:
do shell script "ftp -o /tmp/doppler.jpg http://www.wqad.net/weather/doppler.jpg"

tell application "Mail"
	
	set addrVar to "__YOUR_EMAIL_ADDRESS__"
	set subjectvar to "Doppler Update"
	
	tell application "Finder"
		set the target_file to (file "Macintosh HD:tmp:doppler.jpg") as alias
		set bodyvar to the name of target_file
	end tell
	
	set composeMessage to (make new outgoing message)
	
	tell composeMessage
		make new recipient at beginning of to recipients with properties {address:addrVar}
		set the subject to subjectvar
		set the content to bodyvar
		tell content
			make new attachment with properties {file name:target_file} at after the last word of the last paragraph
		end tell
	end tell
	
	send composeMessage
	
end tell

- Open the Script Editor application (Applications:AppleScript:Script Editor).
- Create a New script and paste the above inside.
- Replace the __YOUR_EMAIL_ADDRESS__ text with your own (or your phone's) email adddress.
- If your system disk is named something other than "Macintosh HD", make the corresponding change in the set the target_file... line to match the name of the HD in your system.
- Compile the script. Make sure there are no errors.
- If you are curious, you can run it right from the Script Editor to test it. Just hit the "Run" button.
- Save it as a 'Script' somewhere convenient (such as your home Applications folder) and name it something sensible (such as "DoDoppler.scpt").

Now go to the Mail application and add your new rule in the "Preferences" "Rules" pane. Set up the "Condition" to match a string in the "Subject" as you want it, then under "Perform the following actions:" select "Run AppleScript" from the menu on the left, and "Choose" your newly created script on the right.

I hacked some of the script (how to compose a message and add an attachment) from a hint posted on maxosxhints.com, and added the retrieval of your JPG image from the web (first line). The script itself is pretty simple and could be easily customized by anyone who can work the Script Editor.

Worked for me. Hope it works for you.

Boredom put to some use . . .
:)
 

Mr_Ed

macrumors 6502a
Mar 10, 2004
706
669
North and east of Mickeyland
Still bored . . .

I played with this a little longer and made it a little bit more "compliant" to the suggested structure of a "Rule Action" script. It also now extracts the "Sender" address from the incoming mail message and uses it to send out the email with the attached file. In other words, your "Doppler Update" would be sent to the address where the requesting email came from. Good or bad depending on what you want. If you use the old script with a hard coded email address, I could see some "friend" thinking it would be funny to bombard your phone with Doppler Updates just by repeatedly e-mailing your home address :)

You might also drop the script into the "Mail Scripts" folder so it can appear in the "Scripts" menu in your Mail app.

Updated script:
Code:
do shell script "ftp -o /tmp/doppler.jpg http://www.wqad.net/weather/doppler.jpg"

using terms from application "Mail"
	on perform mail action with messages theMessages for rule theRule
		
		tell application "Mail"
			repeat with eachMessage in theMessages
				
				set addrVar to eachMessage's sender
				set subjectvar to "Doppler Update"
				
				tell application "Finder"
					set the target_file to (file "Macintosh HD:tmp:doppler.jpg") as alias
					set bodyvar to the name of target_file
				end tell
				
				set composeMessage to (make new outgoing message)
				
				tell composeMessage
					make new recipient at beginning of to recipients with properties {address:addrVar}
					set the subject to subjectvar
					set the content to bodyvar
					tell content
						make new attachment with properties {file name:target_file} at after the last word of the last paragraph
					end tell
				end tell
				
				send composeMessage
			end repeat
		end tell
	end perform mail action with messages
end using terms from
 

MacBoy88

macrumors regular
Original poster
Feb 4, 2003
202
147
Illinois
OK.....I used the first one that you gave me because I have to have it sent a diffrent address than where it is comming from. It dose send a message to my phone, but the picture dose not come threw. If you could give me a buzz on iChat, Shortay1988, sometime tonight. Thanks!!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.