• 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: trapping an apple event
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: trapping an apple event


  • Subject: Re: trapping an apple event
  • From: Paul Berkowitz <email@hidden>
  • Date: Fri, 15 Jun 2001 20:03:56 -0700

On 6/15/01 2:03 PM, "Michelle Steiner" <email@hidden> wrote:

> On 6/15/01 8:51 AM, Andrew Donnelly <email@hidden>
> wrote:
>
>> Hi all, I am wondering if anyone has any ideas. I have a folder that
>> remote users drop image files in. User 'A' might drop off a file called
>> "1.eps" , user 'B' now comes along and needs to drop off a file called
>> "1.eps" but is confronted with the "file already exists" dialog. Is it
>> possible to trap this so that user 'B' ' would not receive the dialog and
>> the file would be renamed to say "1_01.eps"? It is not an option to have
>> the file dropped into one folder and pushed to another, the file must stay
>> where it is dropped off.
>
> check to see if the file exists in the destination folder; if it does,
> then rename the file before moving it.
>
--and this can be a little more complicated than first appears if you have
to worry about several such attempts. the whole series will have to be
sequenced, adding 1 on, and not forgetting that you have to turn any string
version of a number into an integer before you can add 1 on, then back to a
string again to rename. A good way to test for the existence of a the same
name already, that doesn't involve the Finder which can get quite gummed up
in these existence checks, is to do

try
get alias "Disk:Folder:1.eps"
-- doesn't error, means the thing exists, change name
set done to false
set j to 1
repeat until done
set jj to text -2 thru -1 of ("0" & j)
try
set theName to "Disk:Folder:1_" & jj & ".eps"
get alias theName
-- doesn't error, means it exists, change name
set j to j +1
on error -- doesn't exist
set done to true
end try
end repeat
on error -- 1.eps doesn't exist yet
set theName to "1.eps"
end try

tell application "Finder"
set name of theFile to theName
move theFile to someFolder
end tell

--------------

Make sure that theFile is predefined so that even if it takes the Finder its
customary 3 seconds or more to do the renaming, it can still find theFile to
move it. Don't refer to theFile by its new name when you move it, or it will
usually error. Even so, you may have Finder problems. If so, use Jon's
Commands or Akua Sweets to do the naming and moving, which I would
recommend.


--
Paul Berkowitz


References: 
 >Re: trapping an apple event (From: Michelle Steiner <email@hidden>)

  • Prev by Date: Re: Scripting Mail in OS X
  • Next by Date: Re: startup script
  • Previous by thread: Re: trapping an apple event
  • Next by thread: startup script
  • Index(es):
    • Date
    • Thread