Applescript - changing the extension of files

Joined
Aug 25, 2006
Messages
82
Reaction score
1
Points
8
Your Mac's Specs
MacBook
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.
 
Joined
Mar 30, 2004
Messages
4,744
Reaction score
381
Points
83
Location
USA
Your Mac's Specs
12" Apple PowerBook G4 (1.5GHz)
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.
 
OP
origami
Joined
Aug 25, 2006
Messages
82
Reaction score
1
Points
8
Your Mac's Specs
MacBook
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\"."
 
Joined
Mar 11, 2004
Messages
1,964
Reaction score
174
Points
63
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.
 
Joined
Oct 27, 2005
Messages
4,702
Reaction score
404
Points
83
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.
 
Joined
Mar 11, 2004
Messages
1,964
Reaction score
174
Points
63
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.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top