"Scripting component error" fixed by re-framing tell block... why?

I recently ran into a “Scripting component error” when GUI scripting the “Finder”… and with a bit of playing around, managed to write a work-around. However, the work-around takes more lines, declares another variable, and probably slows things down (on a nanoscale level). Here’s the script that causes the error:

set AllIcons to {} as list
tell application "System Events" to tell application process "Finder" to tell front window to tell splitter group 1 to tell scroll area 1
	tell (first group whose description = "All My Files") to repeat with ListType in every list
		set AllIcons to (AllIcons & every image of (contents of ListType))
	end repeat
end tell
return AllIcons

And here’s the work-around… the working script:

set AllIcons to {} as list
tell application "System Events" to tell application process "Finder" to tell front window to tell splitter group 1 to tell scroll area 1
	set TellTarget to first group whose description = "All My Files"
	tell TellTarget to repeat with ListType in every list
		set AllIcons to (AllIcons & every image of (contents of ListType))
	end repeat
end tell
return AllIcons

hmmm… there’s got to be a reason why this happens, does anyone know it? I’m using Lion by the way, just in case it matters.

Note to Moderator(s): When including system info in a post, the OSX version only goes up to 10.6… that’s old news, lol. :cool:

Aesthir

I don’t have Lion, so I can’t test it. But in your first script, you’re telling the group in System Events to work with every list, which is undoubted an element type it doesn’t possess.

The second script first obtains the group in a AppleScript-understandable form which presumably does contain list(s).

You could probably lose the extra variable by inserting a ‘get’ into the problem line:

tell (get first group whose description = "All My Files") to repeat with ListType in every list

Those ‘tell . to tell . to tell .’ lines aren’t condusive either to understanding or to future editing. And in any case, they involve more typing than the equivalent ‘. of .’ or '.'s ’ constructions. :wink:

I Moderator(s) have no influence over such matters. It’s the dreaded Administrators who have the power ” or maybe only the mysterious entity known as Ray Barber. But I’ll supplicate on your behalf. It’s Sunday. He may already have eaten…)

Yeah… unfortunately, I just realized the problem is Lion only as the window configuration (once you go through to the bottom of the tell statements :rolleyes:) only exists in the new “arrangement” options the Finder offers. It turns out Apple decided to describe all folders arranged in some way “All My Files” for some reason…

As for your solution, even though you can’t test it, you still managed to narrow down the problem… your solution works! You’re a scripting genius Nigel! :wink:

Thanks Nigel, the problem was fixed almost immediately.

Finally…

Are you tyring to say the more common/accepted form of scripting is using “of … of … of” instead of “to tell … to tell … to tell”? I’m pretty new to AppleScript, so I’m still quite pliable. My AppleScripting form hasn’t yet been engrained.

And perhaps off topic:
The reason I’m writing these scripts is because Lion can’t seem to remember Finder window settings as Snow Leopard did. Also, the new minimum size for a window is larger than is was in Snow Leopard, so windows containing 1-10 files now must be larger than are necessary. My desktop is usually quite limited for space as I like to have Finder span all my spaces equally. I usually have 30+ windows open at once, all tiled nicely so I can easily click on any window no matter how buried, which is why window settings (ie. location, size, toolbar/statusbar/sidebar options, etc…) are quite important to me.

Ever since Lion upgrade, every time I reboot, all windows that were not previously open on reboot get their settings reset to default. If anyone who reads this doesn’t like this behaviour, maybe don’t switch to Lion yet. Anyway, by writing 2 scripts, I now have all window settings saved in a file of my creation, so when I re-open a previously saved window, the script immediately restores it, and makes it any size to boot (even 1x1 pixel, or negative ” window disappears, lol :cool:)… such is the reason I love AppleScript.

Aesthir