Re: OS 10.4.5 breaks script, "startup disk missing value"
Re: OS 10.4.5 breaks script, "startup disk missing value"
- Subject: Re: OS 10.4.5 breaks script, "startup disk missing value"
- From: Matt Deatherage <email@hidden>
- Date: Wed, 15 Feb 2006 13:59:21 -0600
On 2/15/06 at 11:29 AM, James Weisbin <email@hidden> wrote:
> Since upgrading from 10.4.4 to 10.4.5, this script fails: "startup
> disk missing value". Any suggestions?
It breaks for me on 10.4.4 as well, but that's because the folder I
picked didn't have any files of that type. However, on a more DTS-type
note (yeah, I know, you can take the guy out of R&D 3, but...), it took
me a while to understand what you were trying to do.
I think the short version is "Create a formatted list of the first 30
items of the selected folder whose file types are in extension_list".
If that's the case, you're taking a really long way to do it, at least
if you're only going to use three file types.
You are creating a list of every item in the folder, then looping
through each item. However, once you've found 30 items that you like,
you don't exit the loop, but instead use an "if" condition to skip the
rest of the processing. Suppose the folder you choose has 5000 files
in it, and out of the first 60 files, half of them meet your criteria.
Your "repeat" loop will execute 5000 times, but after iteration 61,
you're just seeing the "if (mycount < 31)" test fail another 4940
times. Why loop through something if you know you don't want any more
results?
AppleScript also has built-in shortcuts for "(ASCII character 9)" and
"(ASCII character 13)" - they're the constants "tab" and "return".
On the larger scale, though, the loop is unnecessary if your list of
file types is suitably small. If it's just 3, and is not likely to get
much larger, you can ask the Finder to make the list for you and avoid
expensive AppleScript processing. You do have to use an integer loop
and not just a list loop (i.e., "for myFile in file_list") because you
need the number of each item in the list
At first I didn't understand why you'd need a "try" block, but I soon
discovered that if the Finder doesn't find any files that meet the
criteria, it throws an error. I modified the try block to assume that
any error in getting the files means there are no such files, so we
skip the rest of the processing and set the clipboard to the empty
string instead, since you want return values on the clipboard.
I also added a local variable, "found_items", because it's more
efficient to do a "count" operation on an unchanging data set once (or
twice, if it changes once) than it is to do it every time through a
loop. If you use the form "repeat with mycount from 1 to count of
mylist", then AppleScript recounts the items in myList every time
through the loop, and that's just not necessary. It's just automatic
with me - make static calculations once, not every time through a loop.
So here's my version:
---
tell application "Finder"
activate
set name_text to ""
set found_items to 0
set this_folder to choose folder with prompt ¬
"Choose a folder to list:"
try
set folder_items to every file of this_folder whose ¬
(file type is "AIFF" or ¬
file type is "MPG3 " or ¬
file type is "WAVE")
set found_items to count of folder_items
on error error_message number error_number
end try
if found_items > 0 then -- don't bother if list is empty
if found_items > 30 then
set folder_items to items 1 through 30 of folder_items
set found_items to 30 -- no need to recount, we know it's 30
end if
repeat with mycount from 1 to found_items
set name_text to (name_text & mycount & tab & ¬
(name of item mycount of folder_items) as string) & ¬
tab & return
end repeat
set the clipboard to «class ktxt» of ((the name_text as text) ¬
as record)
else
set the clipboard to ""
end if
end tell
---
This works for me on 10.4.5 - PROVIDED that the chosen folder is not on
a FileVault volume (that is, inside a FileVault home folder). If
that's the case, then I get errors from the Finder trying to get every
item of the directory. The alias that "choose folder" is returning
(alias "mattd:Desktop:" in my test) is not one that Finder can use
without error. I don't know why or if it's an old or new problem - the
only 10.4.5 PowerPC system I have handy uses FileVault, and I don't
have a 10.4.4 FileVault system handy for comparison.
Dunno if this will help or not, but it got my brain warmed up for the
day.
--Matt
--
Matt Deatherage <email@hidden>
GCSF, Incorporated <http://www.macjournals.com>
"He's got that pizza maker's hand where he casually drizzles the
food prouct." --Carson, Queer Eye
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden