• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Moving a file and changing its name in X
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

References: 
 >Moving a file and changing its name in X (From: Leif Skoog <email@hidden>)

  • Prev by Date: Re: Scripting Mail:get selection
  • Next by Date: Re: percentages (was re: repeat with i in string optimization)
  • Previous by thread: Re: Moving a file and changing its name in X
  • Next by thread: Re: Re: Moving a file and changing its name in X
  • Index(es):
    • Date
    • Thread