Applet to create zip and populate clipboard with filenames?

Hello,

I often email sets of files as attachments. I like zipping and just sending one file to reduce clutter and save space but I also like being able to see which file are contained in an email (and in any attached zips) just at a glance.

Attache (http://www.macupdate.com/app/mac/25205/attache) contains functionality to attach files to an email and create a list of them, but it doesn’t create a zip.

YemuZip is great for creating PC-compatible zips but doesn’t create a list of included files.

The code at the bottom of this suggestion http://hints.macworld.com/article.php?story=20060728110724423 will generate a list of file contained in a zip, although it doesn’t create the zip archive and it displays too much information.

Ideally an application or applet would combine functionality listed above and perform the actions listed below when a user dragged a set of files onto its icon (I’d put the applet into the Places section of Finder so I could directly drag to it from any folder):

  • create a PC-compatible zip (no Mac-only files)

  • open an email

  • paste a list of filenames contained in the zip into the email (just filenames, not the whole file path and not a lot of information about creation date, file size, etc)

  • attach the zip file to the bottom of the email

Do any of you know of any applets that will accomplish this? If not, can any of you think of how this could be accomplished using AppleScript?

Thank you,
Erik

Maybe this one may help :



--=====

on open sel -- sel contient une liste d'alias des éléments 
	-- qu'on a déposés sur l'icône du script (la sélection)
	tell application "System Events"
		set classe1 to (class of item 1 of sel) as text
	end tell
	if (count of sel) = 1 and classe1 is in {"folder", "«class cfol»"} then
		my traite_un_dossier(item 1 of sel)
	else
		my traite_la_liste(sel)
	end if
end open -- fin 2

--=====

on traite_la_liste(les_fichiers)
	
	set p2t to path to desktop
	set nom_de_dossier to ("pièces jointes" & (do shell script "date +_%Y%m%d-%H%M%S"))
	set nouveau_dossier to ("" & p2t & nom_de_dossier)
	tell application "System Events"
		make new folder at end of p2t with properties {name:nom_de_dossier}
	end tell
	set dossier_cible to quoted form of POSIX path of nouveau_dossier
	repeat with i from 1 to count of les_fichiers
		--	set un_posix to quoted form of POSIX path of (item i of les_fichiers)
		do shell script "mv " & quoted form of POSIX path of (item i of les_fichiers) & " " & dossier_cible
	end repeat
	my traite_un_dossier(nouveau_dossier)
end traite_la_liste

--=====

on traite_un_dossier(le_dossier)
	tell application "System Events"
		set les_fichiers to name of disk items of folder (le_dossier as text) whose visible is true
	end tell
	set fichier_archive to my compacte_le_dossier(le_dossier)
	my cree_un_mail("avec pièce jointe", my recolle(les_fichiers, linefeed), fichier_archive as alias)
end traite_un_dossier

--=====

on compacte_le_dossier(le_dossier_source) (* le_dossier_source is an HFS path*)
	local Nom, dossier, nomZip, source, dest
	tell application "System Events" to tell disk item ("" & le_dossier_source)
		set Nom to name
		set dossier to path of container
	end tell
	set source to quoted form of POSIX path of (le_dossier_source)
	set nomZip to Nom & (do shell script "date +_%Y%m%d-%H%M%S.zip")
	set dest to quoted form of POSIX path of (dossier & nomZip)
	do shell script "ditto -ck " & source & " " & dest
	return (dossier & nomZip)
end compacte_le_dossier

--=====

on cree_un_mail(le_sujet, le_texte, le_fichier_joint)
	
	tell application "Mail"
		set new_message to make new outgoing message with properties {subject:le_sujet, content:le_texte, visible:true}
		tell new_message
			make new to recipient at end of to recipients with properties {name:"dupont", address:"durand@baguette.fr"}
			make new paragraph at end of last paragraph of content with data (linefeed & linefeed & linefeed)
			make new attachment at end of last paragraph of content with properties {file name:le_fichier_joint}
		end tell
	end tell
	
end cree_un_mail

--=====

on recolle(l, d)
	local oTIDs, t
	set oTIDs to AppleScript's text item delimiters
	set AppleScript's text item delimiters to d
	set t to l as text
	set AppleScript's text item delimiters to oTIDs
	return t
end recolle

--=====


Yvan KOENIG (VALLAURIS, France) vendredi 24 décembre 2010 20:18:59

Thank you Yvan! How difficult would it be to make these few modifications?:

  • When files are dragged onto the scriptlet they are copied, not moved

  • The script prompts for input which becomes the filename and the subject of the email.

Thank you,
Erik


--[SCRIPT]
--=====
property useFinder : true
(*
true = use the Finder to duplicate the files
false = use a Shell Script to duplicate the files.
Alas, at this time the Shell script fails
*)
--=====

on open sel -- sel contient une liste d'alias des éléments 
	-- qu'on a déposés sur l'icône du script (la sélection)
	tell application "System Events"
		set classe1 to (class of item 1 of sel) as text
	end tell
	if (count of sel) = 1 and classe1 is in {"folder", "«class cfol»"} then
		my traite_un_dossier(item 1 of sel)
	else
		my traite_la_liste(sel)
	end if
end open -- fin 2

--=====

on traite_la_liste(les_fichiers)
	
	set p2t to path to desktop
	set nom_de_dossier to text returned of (display dialog "Give a name for the folder to attach." default answer "")
	if nom_de_dossier is "" then set nom_de_dossier to ("pièces jointes" & (do shell script "date +_%Y%m%d-%H%M%S"))
	set nouveau_dossier to ("" & p2t & nom_de_dossier)
	tell application "System Events"
		make new folder at end of p2t with properties {name:nom_de_dossier}
	end tell
	if useFinder then
		tell application "Finder"
			repeat with i from 1 to count of les_fichiers
				duplicate (item i of les_fichiers) to folder nouveau_dossier
			end repeat
		end tell
	else
		(*
It seems that the syntax which I use to apply cp is not the correct one
*)
		set dossier_cible to quoted form of POSIX path of nouveau_dossier
		repeat with i from 1 to count of les_fichiers
			do shell script "cp -R " & quoted form of POSIX path of (item i of les_fichiers) & " " & dossier_cible
		end repeat
	end if
	
	my traite_un_dossier(nouveau_dossier)
end traite_la_liste

--=====

on traite_un_dossier(le_dossier)
	tell application "System Events"
		set les_fichiers to name of disk items of folder (le_dossier as text) whose visible is true
	end tell
	set fichier_archive to my compacte_le_dossier(le_dossier)
	set le_sujet to text returned of (display dialog "Give the subject of the mail to build." default answer "")
	if le_sujet is "" then set le_sujet to "Avec pièces jointes"
	my cree_un_mail(le_sujet, my recolle(les_fichiers, linefeed), fichier_archive as alias)
end traite_un_dossier

--=====

on compacte_le_dossier(le_dossier_source) (* le_dossier_source is an HFS path*)
	local Nom, dossier, nomZip, source, dest
	tell application "System Events" to tell disk item ("" & le_dossier_source)
		set Nom to name
		set dossier to path of container
	end tell
	set source to quoted form of POSIX path of (le_dossier_source)
	set nomZip to Nom & (do shell script "date +_%Y%m%d-%H%M%S.zip")
	set dest to quoted form of POSIX path of (dossier & nomZip)
	do shell script "ditto -ck " & source & " " & dest
	return (dossier & nomZip)
end compacte_le_dossier

--=====

on cree_un_mail(le_sujet, le_texte, le_fichier_joint)
	
	tell application "Mail"
		set new_message to make new outgoing message with properties {subject:le_sujet, content:le_texte, visible:true}
		tell new_message
			make new to recipient at end of to recipients with properties {name:"dupont", address:"durand@baguette.fr"}
			make new paragraph at end of last paragraph of content with data (linefeed & linefeed & linefeed)
			make new attachment at end of last paragraph of content with properties {file name:le_fichier_joint}
		end tell
	end tell
	
end cree_un_mail

--=====

on recolle(l, d)
	local oTIDs, t
	set oTIDs to AppleScript's text item delimiters
	set AppleScript's text item delimiters to d
	set t to l as text
	set AppleScript's text item delimiters to oTIDs
	return t
end recolle

--=====
--[SCRIPT]

I apologize, it seems that I don’t use the correct syntax to copy the files using cp/

So, at this time I use the Finder.

Yvan KOENIG (VALLAURIS, France) vendredi 24 décembre 2010 22:55:10

The problem with cp is that when a document is a folder or a package, it’s not the folder/package but its contents which is copied.

I know that I must pass a specific parameter but I don’t remember which one.

Yvan KOENIG (VALLAURIS, France) vendredi 24 décembre 2010 23:33:56

Bingo, I retrieved the required trickery.
Now I may use cp.


--[SCRIPT]
--=====

on run
	tell application "Finder"
		set mes_fichiers to (items of folder "Macintosh HD:Users:yvankoenig:Desktop:disabled - copie:") as alias list
	end tell
	my traite_la_liste(mes_fichiers)
end run
--=====

on open sel -- sel contient une liste d'alias des éléments 
	-- qu'on a déposés sur l'icône du script (la sélection)
	tell application "System Events"
		set classe1 to (class of item 1 of sel) as text
	end tell
	if (count of sel) = 1 and classe1 is in {"folder", "«class cfol»"} then
		my traite_un_dossier(item 1 of sel)
	else
		my traite_la_liste(sel)
	end if
end open -- fin 2

--=====

on traite_la_liste(les_fichiers)
	
	set p2t to path to desktop
	set nom_de_dossier to text returned of (display dialog "Give a name for the folder to attach." default answer "")
	if nom_de_dossier is "" then set nom_de_dossier to ("pièces jointes" & (do shell script "date +_%Y%m%d-%H%M%S"))
	set nouveau_dossier to ("" & p2t & nom_de_dossier)
	tell application "System Events"
		make new folder at end of p2t with properties {name:nom_de_dossier}
	end tell
	set dossier_cible to quoted form of POSIX path of nouveau_dossier
	repeat with i from 1 to count of les_fichiers
		set item_unix to POSIX path of ("" & item i of les_fichiers)
		if item_unix ends with "/" then set item_unix to text 1 thru -2 of item_unix
		do shell script "cp -R " & quoted form of item_unix & " " & dossier_cible
	end repeat
	
	my traite_un_dossier(nouveau_dossier)
end traite_la_liste

--=====

on traite_un_dossier(le_dossier)
	tell application "System Events"
		set les_fichiers to name of disk items of folder (le_dossier as text) whose visible is true
	end tell
	set fichier_archive to my compacte_le_dossier(le_dossier)
	set le_sujet to text returned of (display dialog "Give the subject of the mail to build." default answer "")
	if le_sujet is "" then set le_sujet to "Avec pièces jointes"
	my cree_un_mail(le_sujet, my recolle(les_fichiers, linefeed), fichier_archive as alias)
end traite_un_dossier

--=====

on compacte_le_dossier(le_dossier_source) (* le_dossier_source is an HFS path*)
	local Nom, dossier, nomZip, source, dest
	tell application "System Events" to tell disk item ("" & le_dossier_source)
		set Nom to name
		set dossier to path of container
	end tell
	set source to quoted form of POSIX path of (le_dossier_source)
	set nomZip to Nom & (do shell script "date +_%Y%m%d-%H%M%S.zip")
	set dest to quoted form of POSIX path of (dossier & nomZip)
	do shell script "ditto -ck " & source & " " & dest
	return (dossier & nomZip)
end compacte_le_dossier

--=====

on cree_un_mail(le_sujet, le_texte, le_fichier_joint)
	
	tell application "Mail"
		set new_message to make new outgoing message with properties {subject:le_sujet, content:le_texte, visible:true}
		tell new_message
			make new to recipient at end of to recipients with properties {name:"dupont", address:"durand@baguette.fr"}
			make new paragraph at end of last paragraph of content with data (linefeed & linefeed & linefeed)
			make new attachment at end of last paragraph of content with properties {file name:le_fichier_joint}
		end tell
	end tell
	
end cree_un_mail

--=====

on recolle(l, d)
	local oTIDs, t
	set oTIDs to AppleScript's text item delimiters
	set AppleScript's text item delimiters to d
	set t to l as text
	set AppleScript's text item delimiters to oTIDs
	return t
end recolle

--=====
--[SCRIPT]

Yvan KOENIG (VALLAURIS, France) vendredi 24 décembre 2010 23:40:04