Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Sep 26, 2004, 05:25 PM   #1
Mechcozmo
macrumors 601
 
Mechcozmo's Avatar
 
Join Date: Jul 2004
Send a message via AIM to Mechcozmo
AppleScript help

Just want to make a very basic AppleScript that, once pointed at a folder will rename them all to: "8993-myname-1", the '1' would be incremented for each picture. I have Visual Basic.NET programming experience, as well as some C++, but AppleScript always seems to elude me...

Thanks!
__________________
This is not the signature you're looking for.
This is not the signature we're looking for.
You can scroll down now.
You can scroll down now.

Last edited by Mechcozmo; Sep 26, 2004 at 05:27 PM.
Mechcozmo is offline   0 Reply With Quote
Old Sep 26, 2004, 05:48 PM   #2
Doctor Q
macrumors god
 
Doctor Q's Avatar
 
Join Date: Sep 2002
Location: Los Angeles
I got this from another site. Perhaps it will do what you want.

Code:
property nameString : ""
property extension : ""

tell application "Finder" to set theFiles to selection

if number of items in theFiles is greater than 0 then
	display dialog "Please enter the new name for the files:" default answer nameString
	set nameString to text returned of the result
	display dialog "Enter a file extension, or leave blank for none:" default answer extension
	set extension to text returned of the result
	if the nameString is not "" then
		repeat with i from 1 to number of items in theFiles
			set thisItem to item i of theFiles as alias
			set thisInfo to info for thisItem
			set currentName to name of thisInfo
			if extension is "" then
				set extensionString to ""
			else
				set extensionString to "." & extension
			end if
			if i is 1 then
				set newName to nameString & extensionString
			else
				set newName to nameString & " " & (i as string) & extensionString
			end if
			my setItemName(thisItem, newName)
		end repeat
	end if
else
	display dialog "No items are selected" buttons "OK" default button 1
end if

on setItemName(thisItem, newName)
	tell application "Finder"
		set parentFolder to (container of thisItem) as text
		if not (exists item (parentFolder & newName)) then
			try
				set name of thisItem to newName
			on error errorMessage number errorNumber
				tell me to display dialog ("An error occured when renaming to" & newName & ". The file will not be renamed.") buttons "OK" default button 1
				return 0
			end try
		else --the name already exists
			tell me to display dialog ("A file named" & newName & " already exists. The file will not be renamed.") buttons "OK" default button 1
			return 0
		end if
	end tell
end setItemName
__________________
Oh do pay attention 007. In the wrong hands, this cylindrical 12-core Mac Pro with three 4K displays, FirePro graphics, and Thunderbolt 2 could be very dangerous.
Doctor Q is offline   0 Reply With Quote
Old Sep 26, 2004, 06:13 PM   #3
HexMonkey
Demi-God (Moderator)
 
HexMonkey's Avatar
 
Join Date: Feb 2004
Location: New Zealand
I wrote that

It was originally in this thread, which has some more information about the script and some other possible solutions. If you have any questions about the script or want some changes, just ask.
HexMonkey is offline   0 Reply With Quote
Old Sep 26, 2004, 06:26 PM   #4
Mechcozmo
Thread Starter
macrumors 601
 
Mechcozmo's Avatar
 
Join Date: Jul 2004
Send a message via AIM to Mechcozmo
Very neat. The program, BTW, is for Yearbook. The two photographers (me and someone else) need to rename the pictures according to some style that the printer needs.

The other photographer has a 15" PowerBook (Rev. B or C, dunno)

The only thing that I wonder about, is that whole order thing that is mentioned in the other post. But, I guess if I were to tell that window to be displayed acording to Date Created, everything would be fine and dandy?

Thank you so much, in any case.

EDIT: Tested it out, the only problem I forsee is with the name extensions, but if I tell it .jpg it should work...I still like the OS 9 way of doing things, with the Creator codes. But it does work, and work well. Now I don't have to rename 100 pictures a week by hand!
__________________
This is not the signature you're looking for.
This is not the signature we're looking for.
You can scroll down now.
You can scroll down now.

Last edited by Mechcozmo; Sep 26, 2004 at 06:34 PM.
Mechcozmo is offline   0 Reply With Quote
Old Sep 26, 2004, 06:47 PM   #5
Doctor Q
macrumors god
 
Doctor Q's Avatar
 
Join Date: Sep 2002
Location: Los Angeles
Quote:
Originally Posted by HexMonkey
I wrote that
Thanks, HexMonkey. I didn't remember so I'm sorry I didn't give you credit.
__________________
Oh do pay attention 007. In the wrong hands, this cylindrical 12-core Mac Pro with three 4K displays, FirePro graphics, and Thunderbolt 2 could be very dangerous.
Doctor Q is offline   0 Reply With Quote
Old Sep 26, 2004, 07:12 PM   #6
HexMonkey
Demi-God (Moderator)
 
HexMonkey's Avatar
 
Join Date: Feb 2004
Location: New Zealand
Quote:
Originally Posted by Mechcozmo
The only thing that I wonder about, is that whole order thing that is mentioned in the other post. But, I guess if I were to tell that window to be displayed acording to Date Created, everything would be fine and dandy?
The problem is that there is no defined order that Finder uses to communicate its selection. Sometimes it's seemingly random, sometimes it's ordered. Changing the view in Finder to date created will not necessarily help. The only workaround I know of is to look at the contents of a folder rather than a list of files, which then sorts them by name. If that would be useful, tell me and I'll see if I can make the changes.

Quote:
Originally Posted by Doctor Q
Thanks, HexMonkey. I didn't remember so I'm sorry I didn't give you credit.
That's alright, as long as the code is helpful.
HexMonkey is offline   0 Reply With Quote
Old Jun 23, 2006, 03:52 AM   #7
zippyz
macrumors newbie
 
Join Date: Jun 2006
possible simple solution

If I understand your problem, then the script I have just written ought to work for you. Here it is:

set folderpath to (choose folder with prompt "Which folder would you like to rename the contents of?")
tell application "Finder"
set filelist to files in folderpath
set n to 0
repeat with afile in filelist
set newfilename to "8993-myname-" & n + 1
set name of afile to newfilename
set n to n + 1
end repeat
end tell

If this script is not quite what you want, please contact me either via the forum or email at cj.lusty@ukf.net.
Good luck!

p.s. this script is based on, but not copied from, a script in the book "Beginning mac os x programming" by Stephen Kochan. I highly recomend it to anyone wanting to gain a thorough grounding in the basics of applescript
zippyz is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Handling Duplicate AppleScripts the Otter Mac Programming 1 Dec 22, 2010 05:53 AM
Applescript NOOB Revolume Mac Programming 2 Dec 1, 2010 08:06 AM
help with excel for mac 2008 damiang72 Mac Applications and Mac App Store 0 Nov 14, 2010 06:19 AM
AppleScript Help krohde Mac Help/Tips 2 Mar 20, 2003 05:06 PM
AppleScript help cleo General Mac Discussion 0 Apr 10, 2002 08:21 PM


All times are GMT -5. The time now is 01:05 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

Privacy / DMCA contact / Affiliate and FTC Disclosure
Copyright 2002-2013, MacRumors.com, LLC