Applescript Help- Gmail Drive creation

Joined
Nov 11, 2007
Messages
33
Reaction score
0
Points
6
Location
USA
Your Mac's Specs
MacBook Intel Core 2 2.16 GHz 2 GB iPod video(30GB) and a Shuffle(new)
I googled Gmail drive and got a post on another forum :(

here it is:
Mini-Hint: Automate backups to gmail using applescript
I got a gmail account a week ago and was surprised to see the notification in the upper right that I now had pop access. Now to put that 1 gb of storage to work, I decided to set up mail.app to automatically archive and backup a few of my directories. Make sure you activate pop in your gmail preferences, and optionally setup mail.app for gmail (only necessary if, like me, gmail is your only ticket into the world of pop mail).
Here's the applescript to backup the Documents and Texts folders in my home directory:

Code:
do shell script "cd ~;tar -czf Backup/`date +%Y-%m-%d`.tgz Documents Texts"
set p to do shell script "ls -t1 ~/Backup |head -1" 
set target_file to "/Users/username/Backup/" & p
tell application "Mail"
	set newMessage to make new outgoing message with properties ¬
		{subject:target_file, content:"Whatever reminder you want inside the message"}
	
	tell newMessage
		make new to recipient at beginning of to recipients with properties ¬
			{address:"[email protected]"}
		
		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 newMessage
end tell
It archives and zips 2 directories under the home directory called Documents and Texts to the ~/Backup directory - note how the filename of the created archive includes the date. The "ls ... | head" command is just a way to get the last modified file in the directory, which would be the zipped archive we just created. (The unix part of the script is inelegant and messy). It then makes a new email message with the archive as an attachment and sends it to your gmail account. Save the script as an application and you just need to double click it any time you want to backup your directories.

Obviously, to make this work as an online backup system, you'll have to select the "leave messages on server" option in your gmail settings. (You can always create a separate gmail account to be used solely for backups). Also, it's rumored that the attachment limit for gmail is 10megs per file, so it's probable that you'll have to modify the script to send multiple attachments if they are > 10 megs. It's a good idea to setup a filter to have your backups automatically stored in their own "folder" outside of the inbox. If you need to restore your files, just download the archive, cd to where you want to expand the archive (only cd to the original directories' parent directory - ~ in this example - if you want to overwrite the existing directories) and use "tar -zxvf /path/to/file" :
tar -zxvf /Users/karl/Desktop/2004-11-16.tgz

Um so yeah i got the script to work and did somethings on my own however the last bit
Also, it's rumored that the attachment limit for gmail is 10megs per file, so it's probable that you'll have to modify the script to send multiple attachments if they are > 10 megs.

Does anyone know how to do this???

MY code looks like this
Code:
tell application "Safari"
	open location "http://gmail.google.com/gmail"
end tell



property username : "agentsmithbackup"
property newline : (ASCII character 10) --character for new line

on open of these_items
	--calls send_message with the list of files gotten as a droplet
	send_message(these_items)
end open

--accepts a list of files
on send_message(target_files)
	set theResult to display dialog "Title:" default answer ""
	set theSubject to text returned of theResult
	tell application "Mail"
		
		--combine filenames of all files into one string for subject
		set n to 1
		set filenames to ""
		repeat until n is the ((length of target_files) + 1)
			set n_file to item n of target_files
			if n is less than (length of target_files) then
				set filenames to filenames & POSIX path of n_file & ", "
			else
				set filenames to filenames & POSIX path of n_file
			end if
			set n to n + 1
		end repeat
		
		--set message properties
		set newMessage to make new outgoing message with properties ¬
			{subject:theSubject & ": " & filenames, content:newline}
		
		tell newMessage
			--message should be sent to self
			make new to recipient at beginning of to recipients with properties ¬
				{address:username & "@gmail.com"}
			
			--add attachments from the list		
			set n to 1
			tell content
				repeat until n is the ((length of target_files) + 1)
					set n_file to item n of target_files
					set filepath to POSIX path of n_file
					make new attachment with properties {file name:filepath} ¬
						at after the last word of the last paragraph
					set n to n + 1
				end repeat
			end tell
		end tell
		
		--send the message
		send newMessage
		
	end tell
end send_message

so yeah everything works but i cant send anything over 20MB (is the limit now, the post was from '05)

Thanks for your help,

Willgecko
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top