On 27/09/2012, at 9:19 PM, Shane Stanley <
email@hidden> wrote:
On 27/09/2012, at 7:35 PM, Christopher Stone <
email@hidden> wrote:
But maybe it will spark an idea.
Like this:
tell application "Finder"
set sel to selection as alias list
end tell
tell application "TextEdit"
tell front document
set its text to "Now is the time for all good men to come to the aid of their country."
repeat with i in sel
make new attachment at after character -1 with properties {file name:i}
end repeat
end tell
end tell
G'day, and thanks Shane and Chris.
Works a treat Shane, this is what I've ended up with, as a test script for alterations to a much larger script. Rebuilding the rtfd's will save me a lot of work. I've also noticed a peculiarity with Mail, if I close the main window, and use this script to re-open the window, all mailboxes vanish, so I've had to resort to closing and re-opening Mail under certain circumstances, just in case any of you were wondering about the convoluted approach about running Mail.
Regards
Santa
global newFolderName
global newFolderPath
global ptd
global posixPath
on run
set ptd to path to desktop
tell application "Mail"
activate
try
set selected mailboxes of message viewers to mailbox "* items to shift"
set the selected messages of message viewers to message 1 of mailbox "* items to shift"
end try
tell application "System Events" to tell process "Mail"
set FLaG to (enabled of menu item "Save Attachments…" of menu 1 of menu bar item "File" of menu bar 1 is true)
end tell
if not FLaG then
tell application "Finder"
repeat while exists process "Mail"
try
tell application "Mail" to quit
end try
end repeat
repeat while not (exists process "Mail")
try
tell application "Mail" to activate
end try
end repeat
end tell
end if
set selected mailboxes of message viewers to mailbox "* items to shift"
set tempmessages to messages of mailbox "* items to shift"
if (count of tempmessages) > 0 then
repeat with MessageCount from 1 to count of tempmessages
say (count of tempmessages)
my CreateFolder()
my frontmostCheck()
set the selected messages of message viewers to message MessageCount of mailbox "* items to shift"
my saveAttachments()
end repeat
end if
end tell
end run
on saveAttachments()
my folderCheck()
my frontmostCheck()
set posixPath to POSIX path of newFolderPath
tell application "System Events" to tell process "Mail"
if enabled of menu item "Save Attachments…" of menu 1 of menu bar item "File" of menu bar 1 is true then
my frontmostCheck()
click menu item "Save Attachments…" of menu 1 of menu bar item "File" of menu bar 1
repeat until exists pop up button 1 of group 1 of sheet 1 of window 1
my frontmostCheck()
end repeat
select pop up button 1 of group 1 of sheet 1 of window 1
my frontmostCheck()
keystroke (posixPath)
my frontmostCheck()
click button "Go" of sheet 1 of sheet 1 of window 1
my frontmostCheck()
repeat until exists button "Save" of sheet 1 of window 1
my frontmostCheck()
end repeat
my frontmostCheck()
click button "Save" of sheet 1 of window 1
my frontmostCheck()
tell window 1
delay 0.2
repeat 1 times
keystroke "s" using {command down, shift down}
end repeat
delay 2
keystroke newFolderName
delay 0.2
try
keystroke "d" using {command down}
end try
try
if value of checkbox "Include Attachments" of group 1 of sheet 1 = 0 then click checkbox "Include Attachments" of group 1 of sheet 1
end try
try
tell group 1 of sheet 1
tell pop up button 1
click
set x to 0
repeat until exists menu item "Rich Text Format" of menu 1
if x ≥ 40 then exit repeat
delay 0.1
set x to x + 1
end repeat
click menu item "Rich Text Format" of menu 1
delay 0.1
end tell
end tell
end try
repeat while exists sheet 1
click button "Save" of sheet 1
delay 0.1
end repeat
end tell
tell application "Finder"
set theContents to every item of folder newFolderPath as alias list
end tell
repeat until exists ((ptd & newFolderName & ".rtfd") as text)
end repeat
delay 0.5
tell application "TextEdit"
activate
open (ptd & newFolderName & ".rtfd") as text as alias
end tell
repeat with eachItem in theContents
try
tell application "TextEdit" to tell front document
make new paragraph at after last paragraph with data return & return & return
make new attachment at after character -1 with properties {file name:eachItem}
end tell
on error errmsg
display dialog errmsg
end try
end repeat
tell application "TextEdit"
activate
save front document
close front document
end tell
end if
end tell
end saveAttachments
on frontmostCheck()
tell application "Finder"
if not application "Mail" is frontmost then tell application "Mail" to activate
end tell
end frontmostCheck
on folderCheck()
tell application "Finder"
repeat until exists folder newFolderPath
end repeat
end tell
end folderCheck
on numberAdjust(theNumber)
set theNumber to theNumber as number
if theNumber = 0 then return "00"
if theNumber < 10 then return "0" & theNumber
return theNumber
end numberAdjust
on CreateFolder()
set WorkingDate to (current date) - (time to GMT)
set theYear to year of WorkingDate
set theMonth to my numberAdjust(month of WorkingDate as number)
set theDays to my numberAdjust(day of WorkingDate)
set theHours to my numberAdjust(hours of WorkingDate)
set theMinutes to my numberAdjust(minutes of WorkingDate)
set theSeconds to my numberAdjust(seconds of WorkingDate)
set newFolderName to (theYear & "-" & theMonth & "-" & theDays & " " & theHours & theMinutes & theSeconds & "Z") as text
set newFolderPath to (ptd & newFolderName) as text
tell application "Finder"
if not (exists folder newFolderPath) then
(make new folder at ptd with properties {name:newFolderName})
end if
end tell
set newFolderPath to newFolderPath as alias
end CreateFolder