HOME > AppleScript > WebブラウザからD&Dした画像を新規フォルダに保存


(*
1. アプリケーションまたはアプリケーションバンドルとして保存。
2. Dockに登録。
3. Webブラウザから画像をドラッグ&ドロップ。
4.フォルダ名を入力(デフォルトの名前は「新規フォルダ-yyyymmddhhmmss」)
5.デスクトップに新規フォルダが作られ,その中に画像が保存される。

なぜかDockに登録しないと使えない。
起動が遅いので"実行後、自動的に終了しない"にチェックを入れたほうがよい。

Safari、IE、Opera、シイラでは問題ないが、Firefoxからドラッグ&ドロップするとDockが終了し、画像も保存されない。また、Firefoxも不安定になる。
*)

on open dropItems

tell application "Finder" to if (number of items of dropItems) is not 1 then return

set theText to "新規フォルダ-" & curDate() of me

namingFolder(dropItems, theText) of me

end open

on namingFolder(dropItems, theText)
tell application "Finder"
tell me to set theResult to (display dialog "新しいフォルダの名前: " & return & "" default answer theText buttons {"キャンセル", "OK"} default button 2)
if button returned of theResult is "OK" then
set folderName to (text returned of theResult)
if folderName is "" then set folderName to theText
if folderName starts with "." then
display dialog "\".\"で始まる名前は使えません。"
namingFolder(dropItems, theText) of me
else if folderName contains ":" then
display dialog "\":\"が含まれる名前は使えません。"
namingFolder(dropItems, theText) of me
else
set existsFolder to (exists of (folder folderName of (path to desktop folder)))
if existsFolder is true then
set n to 1
repeat until existsFolder is false
set newFolderName to (folderName & " " & n)
set n to (n + 1)
set existsFolder to (exists of (folder newFolderName of (path to desktop folder)))
end repeat
set newFolder to (make new folder at (path to desktop folder) with properties {name:newFolderName})
move (item 1 of dropItems) to newFolder
else
set newFolder to (make new folder at (path to desktop folder) with properties {name:folderName})
move (item 1 of dropItems) to newFolder
end if
end if
end if
end tell
end namingFolder

on curDate()

set theMonth to (month of (current date) as number)
if (theMonth < 10) then set theMonth to ("0" & (theMonth as string))
set theDay to (day of (current date))
if (theDay < 10) then set theDay to ("0" & (theDay as string))
set theHour to (hours of (current date))
if (theHour < 10) then set theHour to ("0" & (theHour as string))
set theMinute to (minutes of (current date))
if (theMinute < 10) then set theMinute to ("0" & (theMinute as string))
set theTime to (seconds of (current date))
if (theTime < 10) then set theTime to ("0" & (theTime as string))

((year of (current date)) & theMonth & theDay & theHour & theMinute & theTime) as string

end curDate

HOME > AppleScript > WebブラウザからD&Dした画像を新規フォルダに保存

TOP

created: 2005-12-18T06:05:00+09:00
last modified: 2006-04-04T00:31:30+09:00
author: AquaBowler