Re: Why doesn't this simple script work?
Re: Why doesn't this simple script work?
- Subject: Re: Why doesn't this simple script work?
- From: Paul Berkowitz <email@hidden>
- Date: Wed, 08 Aug 2001 10:40:01 -0700
On 8/8/01 9:49 AM, "email@hidden" <email@hidden>
wrote:
>
When this script encounters a file:
>
>
>
tell application "Finder"
>
activate
>
set this_folder to "Daily Pairer 1:DailyDone:"
Oops. That's just a string, not a folder. Unless you have Jon's Commands or
Akua Sweets installed, which will coerce that string to an alias in the next
line, you're going to run into trouble, since you can't 'list folder' a
string. (And if you DO have one of these osaxen installed, as you seem to or
the whole thing would have errored out sooner, why use the Finder at all?
See below.) You mean to say:
set this_folder to alias "Daily Pairer 1:DailyDone:"
Is "Daily Pairer" the name of your hard disk or the name of folder on the
root of your hard disk? If the latter, then the 'alias' format (i.e. using
colons and a file path) needs to begin with the name of the hard disk. Let's
say yours is "Macintosh Hard Disk". Substitute the correct name if it's
different (like "Steve's Hard Disk"). So, if that's the case, the above line
should read:
set this_folder to alias "Macintosh Hard Disk:Daily Pairer 1:DailyDone:"
And if you're using this 'alias' AppleScript format, why put it all in a
Finder tell block? (See below for improved version.)
>
set these_items to list folder this_folder without invisibles
>
repeat with i from 1 to the count of these_items
>
set this_item to alias ((this_folder as text) & (item i of
>
these_items as text))
So this-item is ALREADY defined by you as an alias type.
>
set the item_info to info for file (this_item)
Oops. 'file alias'? You don't need 'file' since it's already 'alias'. You
can certainly use one or the other _outside_ a Finder tell block. ('alias'
is usually better because it ensures that the file actually exists.) But the
Finder has its own 'file' term which would need a different syntax here if
you were to use it. (file "Something" of folder "Whatever" of disk "HD").
And in neither case can you use both. But Jon's Commands, or maybe the
Finder, has probably saved you from error here by "understanding" (coercing)
what yopu really meant. Still, it's better to get it right. See below.
>
if folder of the item_info is true then
>
if (alias of the item_info is false) and (the file type of
>
the item_info is "EPSF") then
>
move this_item to folder "Ad Report Folder:"
Oops! You seem to have specified a disk, not a folder. Is this new folder on
your same hard disk? If so, this line should read:
move this_item to alias "Macintosh hard Disk:Ad Report
Folder:"
or, if you want to use the Finder's terminology (which _doesn't_ use colons)
move this_item to folder "Ad Report Folder" of disk
"Macintosh Hard Disk"
or
move this_item to folder "Ad Report Folder" of startup
disk
which are all the same thing.
>
end if
>
end if
>
end repeat
>
end tell
Why are you putting this whole thing in a Finder tell block anyway, since
you're using 'list folder' and 'info for' osaxen (correctly: they're both
better than the Finder's equivalents) and the alias format throughout, the
only thing you need the Finder for is to move the file (and for that, you
might be better off using Jon's Commands moveFile or Akua Sweets' 'collate
by moving' for speed and not running into Finder traffic jams. But let's
forget that for the moment.)
Try this:
set this_folder to alias "Daily Pairer 1:DailyDone:"
set these_items to list folder this_folder without invisibles
repeat with i from 1 to the count of these_items
set this_item to alias ((this_folder as string) & (item i of
these_items)) -- each item of these_items already is 'as string'
set the item_info to info for alias (this_item)
if folder of the item_info is true then
if (alias of the item_info is false) and (the file type of
the item_info is "EPSF") then
tell application "Finder" to move this_item to folder
"Ad Report Folder" of startup disk
end if
end if
end repeat
If you have really a lot of these files, then try it with the last 'move'
line, instead of telling the Finder, use Jon's Commands:
moveFile this_item to alias "Macintosh Hard Disk:Ad Report
Folder:"
or Akua Sweets:
collate this_item by moving it to alias "Macintosh Hard
Disk:Ad Report Folder:"
without using the Finder at all. It will be much quicker.
>
>
I get the error
>
>
--> Can't get folder of {name:"IP09.15N.1ST.EPSF", creation date:date
>
"Wednesday, August 8, 2001 3:47:47 pm", modification date:date "Wednesday,
>
August 8, 2001 3:47:49 pm", icon position:{-1, -1}, visible:true,
>
size:5.78659E+5, folder:false, alias:false, locked:false, busy
>
status:false, file creator:"XPR3", file type:"EPSF", short version:"", long
>
version:""}.
>
>
>
...which doesn't make sense because it's right there- folder:false. Can
>
anyone shed some light on this for me?
It's because you put the whole thing in a Finder tell block. The Finder has
its own understanding of the term 'folder' - you're confusing the script by
using it here to mean the record label 'folder' from the 'info for' record,
but doing so inside a Finder tell block. Here's a very good reason why you
shouldn't use 'info for', 'path to' and certain other of the Standard
Additions inside Finder tell blocks, or any osaxen that use keywords inside
an application tell block with the same keywords that mean something
different.
Just get out of the habit of putting everything inside a Finder tell block.
That comes from your earliest steps in scripting which were to record Finder
scripts. It's a bad habit which leads to problems just like the one you hit.
>
>
PLEASE NOTE: The Independent has moved
Duly noted, several times.
>
>
The new switchboard telephone number is 020 7005 2000
>
The address is Independent House, 191 Marsh Wall, London E14 9RS
OK.
>
>
This e-mail is confidential and is intended to be read by the addressee
>
only.
Too late for that: you sent it to a mailing list.
>
If you have received it in error, please notify us at once by return
>
e-mail or by telephone on 020 7005 2000.
Nope.
>
You should then delete this e-mail
>
and any copies of it from your computer system.
Nope, I won't do that.
>
Any reproduction,
>
publication, copying, modification, distribution or other dissemination or
>
use of this communication is strictly prohibited.
So sue me.
>
The Independent News &
>
Media Group does not accept any liability for opinions, advice or views
>
contained in this e-mail. Please note that the Group does not enter into
>
any form of contract by email, and no one is authorised to enter into
>
contracts on behalf of the Group in this way. Any part of this e-mail,
>
which is of a purely personal nature is unauthorised by the Group,
Oops, looks like you're going tom get in trouble here?
>
and the
>
Group specifically disclaims all liability for any e-mails which are
>
defamatory, racist, offensive, or in breach of any person's rights. All
>
e-mail passing through the Group's e-mail systems may be subject to
>
monitoring. The Group accepts no liability for errors or viruses.
OK. Duly noted.
--
Paul Berkowitz