Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Wowzera

macrumors 6502a
Original poster
Oct 14, 2008
858
28
Brazil
Hello,
I want to make a script that will prompt the user to select two files and copy them to a pre-created folder on Desktop called TEMP. After it I want them to be renamed to a name that I will define later.

This is my code until now: (pretty poor I know)
tell application "Finder"

choose file with prompt "Please select the two ZIP files:" of type {"ZIP"} with multiple selections allowed

end tell


EDIT:
Btw, isn't there a way to instead of the user select the files he wants, he just drop them on a window? (whose window will check if the files are ZIP)?
 
Ok, I've figured out how to do it.

Here goes another question:

How can I rename files?

I'll always have four files on a folder (specified location, let's say ~/Desktop).
Two RAR files and two ZIP files. I need to rename ONLY the ZIP files.
So it will do the following:

If the files extensions are .ZIP --continue

The file with the bigger size* get renamed to 'heavy'
The other file will be renamed to 'thin'.

*Can be biggest size, alphabetically or anything else, it does not matter, I just need the two ZIP files to be named differently one 'heavy' and the other 'thin'.
 
To change a file name, here's a basic shell:

Code:
tell application "Finder"
	set theFileAlias to (choose file)
	set the name of theFileAlias to newFileString
end tell

(This will break because I haven't defined "newFileString"; I'm assuming you have some code already to handle what you want to name the file.)

Just remember, you can't change the name of a file itself, but you can to an alias; the Finder treats it like a property.

mt
 
To change a file name, here's a basic shell:

Code:
tell application "Finder"
	set theFileAlias to (choose file)
	set the name of theFileAlias to newFileString
end tell

(This will break because I haven't defined "newFileString"; I'm assuming you have some code already to handle what you want to name the file.)

Just remember, you can't change the name of a file itself, but you can to an alias; the Finder treats it like a property.

mt


Thanks.
This is what I did:
Code:
set largestFile to do shell script "cd ~/Desktop/Temporary; ls -S `pwd`| head -1"
	set smallestFile to do shell script "cd ~/Desktop/Temporary; ls -Sr `pwd`| head -1"
	
	set filePathLargest to (path to desktop folder as string) & "Temporary:" & largestFile
	set filePathSmallest to (path to desktop folder as string) & "Temporary:" & smallestFile
	
	set name of file (filePathLargest as string) to "regular.zip"
	set name of file (filePathSmallest as string) to "complex.zip"

Looks weird but did the job,
thanks for your help :)
 
Renaming files can easily be done with do shell script:

Code:
do shell script "cd /path/to/files; mv oldfile newfile"
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.