Re: Moving a file and changing its name in X
Re: Moving a file and changing its name in X
- Subject: Re: Moving a file and changing its name in X
- From: Mr Tea <email@hidden>
- Date: Tue, 25 Feb 2003 12:11:06 +0000
This from Leif Skoog - dated 25-02-03 08.36am:
>
I have this silly little problem. I this script it works in Mac OS 9. When I
>
try to move it to Mac OS X (jaguar) it will work until the very last part.
>
The file Bild 1 is selected but I want it to change name and move to another
>
location. How do I go about?
[SNIP]
>
tell application "Finder"
>
set new_pict to select file "Mac OS X:Bild 1"
>
set name of selection to this_item
>
move selection to folder "Dokument:LS:Video:Pict"
>
end tell
At this point in your script, Leif, the variable 'this_item' is an alias,
not a name. You need to get the name of this_item to pass on to 'new_pict'
Also, there's some unnecessary selecting going on here. You don't need to
select the file to move or rename it. Try this instead:
tell application "Finder"
set new_pict to "Mac OS X:Bild 1" as alias
set name of new_pict to name of this_item
move new_pict to folder "Dokument:LS:Video:Pict"
end tell
Using the 'alias' reference form allows the script to keep track of
'new_pict' even after you have changed its name and moved it. That doesn't
work with Finder item references.
There also seems to be some redundancy in the 'try' block near the top of
your script:
>
try
>
repeat with i from 1 to the count of these_items
>
set this_item to (item i of these_items)
>
set this_item to alias ((this_folder as text) & (item i of
>
these_items))
>
process_item(this_item)
>
end repeat
>
end try
I'm not sure why the first 'set this_item' line is there, as it is
overwritten by the line that follows it. The stuff inside the try block can
be trimmed down to this:
repeat with this_item in these_items
process_item(("" & this_folder & this_item) as alias)
end repeat
... but I don't know if that represents good AppleScript practice [1].
HTH
Nick
[1] I seem to recall someone here suggesting that the 'repeat with i from 1
to count of mylist' syntax used by Leif to define the scope of his repeat
loop is preferable the simpler 'repeat with x in y' syntax that I have used.
Is that so?
_______________________________________________
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.