New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

 
Start a Discussion
 

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
Running Windows (or anything else) on your Mac Discussion of Classic or running Windows, Linux and other OSes on the Mac.

Applescript - changing the extension of files


Post Reply New Thread Subscribe

 
Thread Tools
origami

 
origami's Avatar
 
Member Since: Aug 25, 2006
Posts: 82
origami is on a distinguished road
Mac Specs: MacBook

origami is offline
Hi, I am trying to use Applescript to run something so that in a folder, all the files with the extension ".xyz" would be changed to ".abc"
Can someone give me a hand?
I searched online for something and I found a file called "extensionchange.action" but I don't know what application is needed to open that file.
Thanks.
QUOTE Thanks
technologist

 
Member Since: Mar 30, 2004
Location: USA
Posts: 4,744
technologist has a reputation beyond reputetechnologist has a reputation beyond reputetechnologist has a reputation beyond reputetechnologist has a reputation beyond reputetechnologist has a reputation beyond reputetechnologist has a reputation beyond reputetechnologist has a reputation beyond reputetechnologist has a reputation beyond reputetechnologist has a reputation beyond reputetechnologist has a reputation beyond reputetechnologist has a reputation beyond repute
Mac Specs: 12" Apple PowerBook G4 (1.5GHz)

technologist is offline
What you have is an Automator action, for OS X 10.4.

This thing sounds like what you were looking for. Past it into the Applescript editor and give it a trial run.
QUOTE Thanks
origami

 
origami's Avatar
 
Member Since: Aug 25, 2006
Posts: 82
origami is on a distinguished road
Mac Specs: MacBook

origami is offline
I tried that before, and here is what I got as an error

tell current application
choose folder with prompt "Select folder to rename files in:"
alias "Hard Drive::new:"
display dialog "Extension to Replace:" default answer ""
{text returned:"abc", button returned:"OK"}
display dialog "Replace With:" default answer ""
{text returned:"xyz", button returned:"OK"}
end tell
tell application "Finder"
get every file of alias "Hard Drive:new:" whose name ends with "abc"
{alias "Hard Drive:new: ssscon08.abc"}
select file (alias "Hard Drive:new: ssscon08.abc")
document file " ssscon08.abc" of folder "new" of startup disk
get name of alias "Hard Drive:new: ssscon08.abc”
" ssscon08.abc”
offset of "abc" in " ssscon08.abc"
15
set name of selection to "ssscon08.xyz"
"Finder got an error: Can't set name of selection to \" ssscon08.xyz\"."
QUOTE Thanks
Brown Study

 
Brown Study's Avatar
 
Member Since: Mar 11, 2004
Location: Winnipeg
Posts: 1,964
Brown Study is a name known to allBrown Study is a name known to allBrown Study is a name known to allBrown Study is a name known to allBrown Study is a name known to allBrown Study is a name known to allBrown Study is a name known to all
Mac Specs: G4 Tiger and OS 9

Brown Study is offline
I found a script here that I changed to this:

tell application "Finder"
activate
set the chosen_folder to (choose folder with prompt "Pick the folder containing the files :")
repeat with i from 1 to count of file in chosen_folder
set this_text to name of file i of chosen_folder
set AppleScript's text item delimiters to ".xyz"
set AppleScript's text item delimiters to "/"
set this_text to every text item of this_text
if (count of characters of this_text) > 27 then
set this_text to (characters 1 thru 27 of this_text)
end if
set AppleScript's text item delimiters to ""
set name of file i of chosen_folder to this_text & ".abc" as string
end repeat
end tell

After booting into System 9, I created four SimpleText documents, each with the suffix .xyz, and dropped them into a folder. Then I pasted the above script into a blank Script Editor document and clicked on "Run." A dialog popped up asking me to click on the folder with the documents, and lo and behold, the script changed each one. Colour me astonished.

Before running it on your important files, you should try it first with dummy documents, just to be sure it will work properly with your version of AppleScript.

You'd likely have to change the number 27 to whatever number of documents are in the folder.

Edit: I spoke too soon. I tried it a second time, and it's adding the second suffix to the first. I'll keep working on it.
QUOTE Thanks
NanoBite

 
Member Since: Oct 27, 2005
Posts: 4,714
NanoBite is an unknown at this point

NanoBite is offline
Quote:
Originally Posted by origami View Post
Hi, I am trying to use Applescript to run something so that in a folder, all the files with the extension ".xyz" would be changed to ".abc"
Can someone give me a hand?
I searched online for something and I found a file called "extensionchange.action" but I don't know what application is needed to open that file.
Thanks.
G'day origami.

Your Mac comes with a script already written to do this very job. First you need to enable it by following the info in this link:

http://www.apple.com/ca/pro/tips/applescript.html

Firstly find and highlight all the items you need to effect a change to and then click on the AppleScript icon in the menubar to the right of the DeskTop and navigate to:

Finder Scripts>Replace Text in Item names.

Then follow the prompts and the task is done.

I tested this out on a folder of .mid files and successfully altered the extension from .mid to .mad ... completely unreadable by any app but at least it worked. I then used the script to change them back again.
QUOTE Thanks
Brown Study

 
Brown Study's Avatar
 
Member Since: Mar 11, 2004
Location: Winnipeg
Posts: 1,964
Brown Study is a name known to allBrown Study is a name known to allBrown Study is a name known to allBrown Study is a name known to allBrown Study is a name known to allBrown Study is a name known to allBrown Study is a name known to all
Mac Specs: G4 Tiger and OS 9

Brown Study is offline
Origami, since this thread is in the Classic Mac OS forum, don't you need an OS 9 script? I'm still trying to find one or change one to work properly, but I'm not optimistic. An AppleScript site might prove beneficial.
QUOTE Thanks
origami

 
origami's Avatar
 
Member Since: Aug 25, 2006
Posts: 82
origami is on a distinguished road
Mac Specs: MacBook

origami is offline
Any new help?
QUOTE Thanks
Brown Study

 
Brown Study's Avatar
 
Member Since: Mar 11, 2004
Location: Winnipeg
Posts: 1,964
Brown Study is a name known to allBrown Study is a name known to allBrown Study is a name known to allBrown Study is a name known to allBrown Study is a name known to allBrown Study is a name known to allBrown Study is a name known to all
Mac Specs: G4 Tiger and OS 9

Brown Study is offline
Are you running OS 9 or OS X?
QUOTE Thanks
origami

 
origami's Avatar
 
Member Since: Aug 25, 2006
Posts: 82
origami is on a distinguished road
Mac Specs: MacBook

origami is offline
I am running the latest OSX.
QUOTE Thanks
origami

 
origami's Avatar
 
Member Since: Aug 25, 2006
Posts: 82
origami is on a distinguished road
Mac Specs: MacBook

origami is offline
any new help?
QUOTE Thanks

Post Reply New Thread Subscribe


« Bootcamp cost? | MacPro - XP on bootcamp random freezes »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread
Thread Starter
Forum
Replies
Last Post
List view vs. Icon view - can't see all files =^o.o^= Switcher Hangout 8 01-20-2007 06:39 PM
Changing the location where files are downloaded to: essie OS X - Operating System 6 12-04-2006 06:31 PM
Files Lost during Profile Move SITF OS X - Operating System 0 10-17-2006 03:54 PM
Changing the file extensions on a number of files meatychi Running Windows (or anything else) on your Mac 8 01-19-2006 07:30 AM
repair permissions a waste of time? Macman Schweb's Lounge 5 05-31-2005 06:26 PM

All times are GMT -4. The time now is 05:40 PM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
X

Welcome to Mac-Forums.com

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!


(4 digit year)

Already a member?