renaming a folder based on a variable

Aright, if you guys remember my PSP project, I’ve scrapped that, but am working on something slightly different. At the moment, mac users do not have a way to hide corrupted data icons, short of some tedius manual work. This script takes the tedius out.

Using a trick in naming the folder, the corrupted data icon can be hidden. My script first asks where the first folder is, then asks what the name of the game is called, then (is supposed to) rename the folder using this trick. The trick involves a prefix on the folder name.

The main folder needs to have SCE at the beginning, and the secondary needs to have %SCE at the beginning.

I.E- a game called “mygame” would be __SCE__mygame and %__SCE__mygame. Spacing is important.

At the moment, the problem I’m having is renaming the folder correctly. Right now, it just says it cannot make partonename into a type string.

tell application "Finder"
	set partone to (choose folder with prompt "Choose the main folder" without invisibles)
	--set parttwo to (choose folder with prompt "Choose the second folder, with the % in front" without invisibles)
end tell
tell application "Finder"
	set partonename to (display dialog "What is this homebrew called?" default answer "") as string
end tell
tell application "Finder"
	set name of folder partone to ("__SCE__" & partonename)
end tell

PH;

You don’t have to keep “telling”, one will do. Your problem with partonename was that you wanted text returned of. A dialog with an answer returns a list {text returned, button returned} so you have to say which you want.

tell application "Finder"
	set partone to (choose folder with prompt "Choose the main folder" without invisibles)
	--set parttwo to (choose folder with prompt "Choose the second folder, with the % in front" without invisibles)
	set partonename to text returned of (display dialog "What is this homebrew called?" default answer "")
	set name of folder partone to ("__SCE__" & partonename)
end tell

Display dialog returns a record; You’re trying to coerce that record to a string, which can’t be done (directly, at least). I should get the ˜text returned’ property from that record instead.

set partone to (choose folder with prompt "Choose the main folder" without invisibles)
--set parttwo to (choose folder with prompt "Choose the second folder, with the % in front" without invisibles)

set partonename to text returned of (display dialog "What is this homebrew called?" default answer "")

tell application "Finder"
	set name of partone to ("__SCE__" & partonename)
end tell

Oops - I wrote it was a list, but it obviously cannot be or you couldn’t ask for part of it by name.

Thanks, that did it. Macscripter comes through for me again :smiley:

Edit, I figured this out

One other question would be, since both folders to be moved would share some part of their name (the user-defined part), can I just say “once I select a folder, get the part of the folder name after the SCE, then move all of the folders with that same part (i.e- __SCE__mygame and %__SCE__mygame, the script would move all folders with “mygame” in their name)” since I don’t want to automatically move the folders (if that was the case, this would be easy :P)

Thanks again :slight_smile:

Great scripts! How would you go about doing this in reverse? For example, entering the name that you want to use for a folder in the display dialog box, pushing the “OK” button and as a result creating a new folder with the name that was typed into the display dialog box.