AppleScript – Mail to Flickr and 23hq

Flickr 及 23hq 都有提供用 E-mail 來上傳照片的功能
利用 E-mail 來上傳照片的確方便又好用
你必須先到 http://www.flickr.com/account/uploadbyemail/ 去設定好你要寄到 Flickr 的 E-mail
以及到 http://www.23hq.com/ 你的帳號裡的 settings 處去設定好你要寄到 23hq 的 E-mail (兩邊的做法還真是像啊)
若有使用 iPhoto,在 iPhoto 中選好照片後,再點選 “電子郵件” 來寄信即可
其實這樣子就已經很方便了
另外,我參考 Gmail HD 的程式,簡單的寫了一個 AppleScript
可以很簡單的把照片(不管是從哪一個檔案夾或是直接從 iPhoto 中拉出也行)直接拖拉到 “Mail to Flickr and 23hq” 的 Icon 上即可,然後填入信件標題及內容即可自動寄出
當然,寄信的信箱還是用免費又快容量又大 Gmail 囉…:)

flickr23

另外,直接點選 Icon 就可以連到 flickr 及 23hq 的網頁去看圖片

以下是程式碼: (寄到 flickr and 23hq 的 E-mail 及 Gmail 帳號記得改成你自己的)

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 "http://www.flickr.com/photos/改成你的帳號/"
			open location "http://www.23hq.com/改成你的帳號"
		end tell
	end if
end tell

property username : "改成你的 Gmail 帳號" --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)
	set today to current date
	set y to year of today as string
	set m to month of today as string
	set d to day of today as string

	--輸入標題及內容
	tell me to set myTitle to display dialog "請輸入標題: " default answer ("照片: " & y & m & d) buttons {"預設", "自訂"} default button 2 with icon 1 giving up after 300
	if button returned of myTitle = "自訂" then
		set mailTitle to (text returned of myTitle)
	else
		set mailTitle to ("照片: " & y & m & d)
	end if
	tell me to set myContent to display dialog "請輸入內容(照片說明): " default answer "上傳到 flickr 及 23hq 的照片" buttons {"預設", "自訂"} default button 2 with icon 1 giving up after 300
	if button returned of myContent = "自訂" then
		set mailContent to (text returned of myContent)
	else
		set mailContent to "上傳到 flickr 及 23hq 的照片"
	end if

	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:mailTitle, content:mailContent & 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:"改成你要寄到 flickr 的信箱@photos.flickr.com, 改成你要寄到 23hq 的信箱@23hq.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

3 Responses to “AppleScript – Mail to Flickr and 23hq”

  1. wen zhang Says:

    这个在 Script Editor 里面总提示語法错误:(“我要看照片?”) 的 \

  2. Chung-Yen Chang Says:

    那是 AppleScript 編譯上的問題,它只吃 MacRoman 編碼的字
    所以,請自行把訊息改成 “英文” 或是 “簡體中文” 吧

  3. kansir Says:

    謝謝!真的很有用。
    :-)

FireStats icon Powered by FireStats