Re: Random number and filename
Re: Random number and filename
- Subject: Re: Random number and filename
- From: Mr Tea <email@hidden>
- Date: Tue, 26 Feb 2002 10:14:20 +0000
This from email@hidden - dated 26/2/02 07:38 am:
>
Why doesn4t this script work?
>
>
tell application "Finder"
>
get random number from 1000 to 3000
>
set x to result
>
set search_for_file to alias "Macintosh
>
HD:images_to_database:Documents:"
>
set myListforfile to list folder search_for_file without invisibles
>
repeat with myFilename in myListforfile
>
set myfile to alias "Macintosh HD:images_to_database:Documents:"
>
& myFilename
>
end repeat
>
--try
>
set fileName of myfile to (x & ".doc")
>
--end try
>
end tell
Three reasons that I can see, Peter.
First - your line "set myFile to..." generates a list instead of an alias.
Try something like this instead:
set myfile to "Macintosh HD:images_to_database:Documents:" & myFilename as
alias
Second - fileName is just an empty variable, not any kind of AS terminology.
'set name of [file reference] to [name] is sufficient.
Third - the variable 'x' is an integer, and as such can't be concatenated
with ".doc" (a string) without a bit of coercion - this should do it for
you:
set name of myfile to (x as string) & ".doc"
One thing puzzles me though... why do you need to loop through everything in
the 'search_for_file' folder when this will invariably set myFile to the
last item it comes to, making all the previous iterations redundant. So you
could replace the repeat loop with a single line...
set myfile to "Macintosh HD:images_to_database:Documents:" & last item of
(list folder search_for_file without invisibles) as alias
So, the amended script in it's entirity would be:
tell application "Finder"
set x to random number from 1000 to 3000
set search_for_file to alias "Studio!:Graphics:Web Grabs:"
set myfile to "Studio!:Graphics:Web Grabs:" & last item of (list folder
search_for_file without invisibles) as alias
set name of myfile to (x as string) & ".doc"
end tell
Regards
Mr Tea
--
Brew of the day: African Blend
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.