• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Introduction and procmail test
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Introduction and procmail test


  • Subject: Re: Introduction and procmail test
  • From: Graff <email@hidden>
  • Date: Sun, 20 Jun 2004 16:43:46 -0400

On Jun 20, 2004, at 10:13 AM, Joe Klemmer wrote:

On Sun, 2004-06-20 at 02:08, Christopher Stone wrote:

One thing I forgot to mention is that it's a good idea to tell the list
what you're trying to do. This way you get answers to questions you
didn't know to ask, and frequently someone has already done the job and
can provide a turnkey solution.

Ok, here's the task...

I need to write a droplet that will take a file or folder of files and
make an archive/zip file from them. I'm nearly there now, I'm using "do
shell script" to make use of the zip program. I've got the idea of what
I want to do but now it's a matter of implementing it.

This should do it:
----
on open these_items
tell application "Finder"
set tempFolderPath to path to "temp" as string
set tempFolderName to my UniqueName(tempFolderPath, "Archive")

if (tempFolderName is not anything) then
try
set theFolder to choose folder with prompt "Choose where the archive should be placed:"
set archiveName to my UniqueName(theFolder, "Archive.zip")

if (archiveName is not anything) then
set tempFolder to make new folder at tempFolderPath with properties {name:tempFolderName}
repeat with i from 1 to the count of these_items
set this_item to item i of these_items
display dialog "Duplicating " & this_item & " to " & tempFolder
duplicate this_item to tempFolder
end repeat

set theSource to quoted form of (POSIX path of (tempFolder as alias))
set theDest to quoted form of ((POSIX path of theFolder) & archiveName)
do shell script "/usr/bin/ditto -c -k --sequesterRsrc " & theSource & " " & theDest
else
display dialog "The archive can not be created: too many archive files with similar names."
end if
delete tempFolder
end try
else
display dialog "The archive can not be created: too many temp files with similar names."
end if
end tell
end open

on UniqueName(baseFolder, itemName)
tell application "Finder"
set basePath to baseFolder as string
set savedDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to "."
set theTextItems to text items of itemName
if ((count of theTextItems) > 1) then
set baseName to (items 1 thru -2 of theTextItems) as text
set theExt to "." & (item -1 of theTextItems)
else
set baseName to itemName
set theExt to ""
end if
set AppleScript's text item delimiters to savedDelims

set tempName to itemName
set i to 0
repeat while ((folder (basePath & tempName) exists) and (i < 1000))
set i to i + 1
set tempName to baseName & i & theExt
end repeat
if (i > 999) then
return anything
else
return tempName
end if
end tell
end UniqueName
----

Mind the long lines since they may get wrapped wrong in the e-mail. If the script doesn't come out right then let me know and I'll send it to you directly as an attachment.

- Ken
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.


References: 
 >Introduction and procmail test (From: Joe Klemmer <email@hidden>)
 >Re: Introduction and procmail test (From: Graff <email@hidden>)
 >Re: Introduction and procmail test (From: Joe Klemmer <email@hidden>)
 >Re: Introduction and procmail test (From: Joe Klemmer <email@hidden>)

  • Prev by Date: Re: Introduction and procmail test
  • Next by Date: Re: where to put files owned by the application
  • Previous by thread: Re: Introduction and procmail test
  • Next by thread: Re: Introduction and procmail test
  • Index(es):
    • Date
    • Thread