New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

 
Start a Discussion
 

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
OS X - Development and Darwin Discussion and questions about development for Mac OS X.

Applescript Help- Gmail Drive creation


Post Reply New Thread Subscribe

 
Thread Tools
Willgecko

 
Willgecko's Avatar
 
Member Since: Nov 11, 2007
Location: USA
Posts: 33
Willgecko is on a distinguished road
Mac Specs: MacBook Intel Core 2 2.16 GHz 2 GB iPod video(30GB) and a Shuffle(new)

Willgecko is offline
I googled Gmail drive and got a post on another forum

here it is:
Quote:
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:"user@gmail.com"}
		
		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
Quote:
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
QUOTE Thanks

Post Reply New Thread Subscribe


« Script to Open all Programs | Help Installing Lazarus »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread
Thread Starter
Forum
Replies
Last Post
Replacing Hard Drive on Macbook experience alucard Apple Notebooks 24 10-14-2007 04:21 PM
Cannot see optical drive or read files from superdrive cgeiber OS X - Operating System 0 05-27-2007 10:57 AM
Creating backups and bootable images... 2kx2 Switcher Hangout 4 05-26-2007 08:53 PM
From PC to Mac: transferring files, Mac Mini hard drive djmitch Other Hardware and Peripherals 4 03-23-2005 12:56 PM
2 harddrives puzzle Morgan19 OS X - Operating System 6 04-15-2004 02:38 PM

All times are GMT -4. The time now is 05:17 AM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
X

Welcome to Mac-Forums.com

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!


(4 digit year)

Already a member?