Subject: AppleScript - Quick Attachment, Memo via Contextual menu
Hi Christopher,maybe this is another modification of your original script, I found this somewhere in the Notes Forums and modified it to my needs.
If you have the Big Cat Scripts (contextual menu) Plugin installed (see http://ranchero.com/bigcat/ ), you can send any file(s) directly from the Finder via Ctrl-Klick.
BUT - I have problems attaching files with long filenames! As I read you extended script, this should be a problem with your script, too.
Regards, Thomas
— Here’s the script —
property ToAddress : “”
property alertFilesize : 2000000
on run
tell application “Finder” to set selecteditems to the selection
set the_File to selecteditems as list
main(the_File)
end run
– ---------------------------- Main Subroutine is used by BigCat ----------------------------
on main(filelist)
(* When double-clicked as an application, it asks for a file *)
log (count item of filelist) & “items in the_File”
log class of filelist
if the (count of items in filelist) is 0 then
set filelist to choose file with prompt "Choose a file to send:" as list
-- display dialog (data size of the_File)
(* Send alias as list - otherwise it creates an error*)
send_file(filelist as list)
else
-- display dialog "Los geht’s."
(* Check for large Attachments *)
getFilesize(filelist)
(* Remove folders from list *)
set filelist to cleanList(filelist as list)
(* Send the files *)
send_file(filelist)
end if
end main
– ---------------------------- Clean List of folders ----------------------------
on cleanList(filelist)
set cleanFileList to {}
repeat with oneItem in filelist
set singleItem to oneItem as alias
log class of singleItem
if singleItem as text does not end with “:” then
– display dialog item i in filelist as text
set cleanFileList to cleanFileList & (singleItem as alias)
log “<” & singleItem & “> added to cleanFileList”
end if
end repeat
if (count of items in cleanFileList) is 0 then
display dialog “Nothing to send, you might have selected only folders.”
quit
end if
log cleanFileList
return cleanFileList
end cleanList
– ---------------------------- Make Filename-List ----------------------------
on getFilenames(filelist)
set names to {}
repeat with theItem in filelist
(*pfad-Angaben in Filenamen umwandeln )
try
–set theattachments to theattachments & (((folder of theItem as text) & (name of theItem)) as alias)
set names to names & " [" & name of theItem & "] "
on error number -1728
( Fehler -1728 ignorieren *)
end try
end repeat
–display dialog names
return names
end getFilenames
– ---------------------------- Make Filename-Selection ----------------------------
(* This will make the selcetionList used by getFilesize sub *)
on makeSelection(filelist)
set selectionList to {}
repeat with i from 1 to (count of items in filelist)
set selectionList to selectionList & (name of (item i of filelist))
end repeat
return selectionList
end makeSelection
------------------------------ Get Size of Files ----------------------------
on getFilesize(filelist)
–display dialog “Checking filesize”
set itemSize to “”
repeat with theItem in filelist
– display dialog theItem as string
set itemSize to itemSize + (data size of theItem)
end repeat
–display dialog itemSize / 1000
if the itemSize is greater than alertFilesize then
repeat
set theResult to display dialog “Achtung!” & return & ¬
“Die Attachment(s) sind grösser als 2 MB!” & return & ¬
return & “Filesize: " & {round (itemSize / 1000) rounding as taught in school} & " kB” with icon caution ¬
buttons {“Continue”, “Cancel”, “Show Files”} default button “Cancel”
if button returned of theResult is “Show Files” then
set filelist to choose from list makeSelection(filelist) OK button name ¬
“Continue” with multiple selections allowed and empty selection allowed
else if button returned of theResult is “Continue” then
exit repeat
end if
end repeat
end if
end getFilesize
– – RunScript again
on runAgain(the_File)
–getFilesize(the_File)
send_file(the_File)
end runAgain
------------------------------ Send Function & Notes Stuff ----------------------------
on send_file(filelist)
set CCAddress to “”
set Subject to “”
set ctitems to count of items in filelist
display dialog (“You have selected " & ctitems & " item(s).”) with icon 0 buttons (“I know!”) giving up after 1
---- Ask for recipient
repeat
set SendTo to display dialog "Send this file to:" buttons {"Cancel", "Add CC List", "OK"} ¬
default answer
ToAddress default button “OK”
set ToAddress to the text returned of SendTo
if (ToAddress is not “”) then
exit repeat
end if
end repeat
----- Add CC recipient
if the button returned of SendTo is "Add CC List" then
set CCTo to display dialog "CC this file to: (separate by comma)" buttons {"Cancel", "OK"} ¬
default answer "" default button "OK"
if the button returned of CCTo = "OK" then
set CCAddress to the text returned of CCTo
end if
end if
----- Enter Subject
set SubjectEntry to display dialog "Enter the subject line:" buttons ¬
{"Cancel", "OK"} default answer ("File(s): " & (getFilenames(filelist) as string)) default button "OK"
set Subject to the text returned of SubjectEntry
----- Enter Body Text
set BodyEntry to display dialog "Enter any additonal comments:" buttons ¬
{"Cancel", "OK"} default answer ("See the attachments:" & return) default button "OK"
set BodyText to the text returned of BodyEntry
----- Notes Stuff
tell application "Notes"
set myDB to make new database with data {"", ""}
try
openmail myDB
end try
set myDoc to make new document with data {myDB}
set rtitem to make new richtextitem with data {myDoc, "Body"}
replaceitemvalue myDoc itemname "Body" newvalue BodyText
repeat with i from 1 to ctitems
tell application "Finder"
set singleItem to (item i of filelist) as text
log "Trying to embed: <" & singleItem & ">"
end tell
--display dialog singleItem
try
embedobject rtitem type 1454 class "" source singleItem
on error
tell application "Finder"
beep
set theResult to display dialog "Can’t attach a folder or filename is too long." buttons ¬
{"Show Problem", "Cancel", "Continue anyway"} default button "Continue anyway"
if button returned of theResult is "Show Problem" then
display dialog singleItem buttons {"Continue"} default button "Continue"
end if
end tell
-- appenditemvalue myDoc numactions "Body" newvalue ("Not attached: [" & singleItem & "]")
end try
end repeat
replaceitemvalue myDoc itemname "SendTo" newvalue ToAddress
replaceitemvalue myDoc itemname "Subject" newvalue Subject
replaceitemvalue myDoc itemname "CopyTo" newvalue CCAddress
send myDoc without attachform
end tell
log "---->>>>>>> Mail created"
end send_file