• 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: Renaming files
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Renaming files


  • Subject: Re: Renaming files
  • From: email@hidden
  • Date: Thu, 21 Apr 2011 20:07:08 +0000
  • Importance: Normal
  • Sensitivity: Normal

I have a solution somewhere. Will try to supply it if I can get to my box before next week.

Sent from my Verizon Wireless BlackBerry

-----Original Message-----
From: Thomas Fischer <email@hidden>
Sender: applescript-users-bounces+zavpublic=email@hidden
Date: Thu, 21 Apr 2011 20:41:09
To: AS Users Lisit<email@hidden>
Subject: Re: Renaming files

Hello Jay,

thanks for your thoughts.
No, the names are not present before, and as I mentioned, I use the Finder for renaming since with System Events I lose the Spotlight comments. Checking if a file with the given name exists and else trying again seems a viable option, albeit a little awkward.
Incidentally, I now found a – somewhat unexpected – solution for my problem.
Instead of the processes

– open the file with TextWrangler
– edit the file using TextEditor macros, finding the new name
– save and close the file with TextWrangler
– rename the file using Finder  	# doesn't usually work, even with delay!

I do now

– open the file with TextWrangler
– edit the file using TextEditor macros, finding the new name
– rename the file using Finder  	# always works without delay!
– save and close the file with TextWrangler

I suppose this works because we're dealing with file references all the time, and changing a name for them doesn't hamper TextWrangler's saving.
Still it remains unclear what's happening in the other case.

Cheers
Thomas

Am 21.04.2011 um 04:47 schrieb email@hidden:

> Hi Thomas,
>
> First off, I'm curious if a file with the same name (as what you're renaming
> your file to) already exists in the same directory?  If this is the case, the
> Finder (at least in OS 10.6) seems to happily continue without creating the
> new file and not throwing an error.  In this case, you may want to use
> 'list folder' to get the current contents and check if that file name already
> exists beforehand.
>
> Most people that use AppleScript try to avoid using the Finder, since it's
> quite clunky.  I usually only use it to move, duplicate, rename and update
> items.  I've noticed too that sometimes when I try to rename folders/files,
> it sometimes doesn't work like I was hoping.  Not sure why this is the case
> though.  Another thing you might try is checking to see if your file was
> renamed and if not, maybe loop a few times and see if you can force it.
> I haven't tried this, but here's some code to give you a possible idea:
>
> --
>
> set folderPath to "Snow_Leopard:Users:jyoung:Desktop:test:"
> set myFile to "Snow_Leopard:Users:jyoung:Desktop:test:textfile.rtf"
> set newName to "newFile.txt"
>
> renameFile(folderPath, myFile, newName)
>
> on renameFile(folderPath, myFile, newName)
> 	set itemList to listFolder(folderPath)
>
> 	if newName is in itemList then
> 		error "File already exists!"
> 		-- If file already exists, maybe delete it beforehand?
> 		-- Be careful using system events to delete a file though
> 		-- because you won't get it back!
> 		-- tell application "System Events" to delete alias (folderPath & newName)
> 	end if
>
> 	repeat 5 times
> 		tell application "Finder" to set alias myFile's name to newName
> 		delay 1
> 		if newName is in listFolder(folderPath) then exit repeat
> 	end repeat
> end renameFile
>
> on listFolder(itemPath)
> 	tell application "System Events" to return (list folder alias itemPath without invisibles)
> end listFolder
>
> Jay

_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >Re:Renaming files (From: email@hidden)
 >Re: Renaming files (From: Thomas Fischer <email@hidden>)

  • Prev by Date: Re: Renaming files
  • Next by Date: Re: Closing a file you left open (error -49)
  • Previous by thread: Re: Renaming files
  • Next by thread: Applescript to add user in workgroup manager
  • Index(es):
    • Date
    • Thread