Mini-Hint: Automate backups to gmail using applescript
Filed in: 公告, 網路服務, 軟體 Add comments
Mini-Hint: Automate backups to gmail using applescript
在 Mac OS X 上找不到 Gmail Drive 等程式,用這種方法倒是不錯
把檔案直接拉到 “Gmail HD” 的 Icon 上後,它就自動用 Mail.app 以附件方式幫你寄到 Gmail 上了
還算很方便
我稍微改了一下程式,一個是把最後自動把 Mail.app 關掉那行 mark 掉 (因為 Mail.app 不需要關掉啊)
另外,由於我的信件都是用 Mail.app 來收,包括 .Mac MSN Yahoo Gmail 等多個帳號都是,但我預設是用 .Mac 帳號來寄信,因為,問題又來了,這樣會變成從 .Mac 寄到 Gmail 去,雖然還是寄到了,但是速度很慢 (慢在 .Mac?),所以,我改成了用 Gmail 帳戶寄給自己,這樣一來,速度就快多了,也不用多占用一份 .Mac 的空間
底下是程式碼:(注意,有些地方要手動改一下,改成你的 Gmail 帳號)
(*
Author: Jayson Kempinger
E-mail: EvilGlowingApple@gmail.com
Date created: 7 December 2004
Gmail backup script
Drop files/folders onto this as an application. This script will send the files as attachments in an e-mail
to the gmail address specified by the property username.
Code to send message and set the subject/body found at http://forums.macosxhints.com/showthread.php?t=31163
modified to support dropping of files and multiple files.
*)
set the alert_message to ("取回備份檔案?")
tell application "Finder"
display dialog the alert_message buttons {"是", "否"} default button 2 with icon 1
set the user_choice to the button returned of the result
if user_choice is "是" then
tell application "Safari"
open location "https://mail.google.com/mail/"
end tell
end if
end tell
property username : "請改成你的 Gmail 帳號(不需要 @gmail.com)" --gmail username
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)
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:"File: " & filenames, content:"This e-mail is meant mearly as a backup of the following files." & newline, sender:"請改成你的 Gmail 帳號@gmail.com"}
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
--tell application "Mail" to quit
end send_message