Calling "tell application" block within event handler

I’m having problems calling an application tell block within an AppleScript Studio event handler, and am wondering if this is even possible?

I have written a script which I would like to do the following:

on launched theObject
	--This works no problem
	tell window "main"
		set allDisks to do shell script "cd //volumes ;ls -1"
		set olddelimiter to AppleScript's text item delimiters
		set AppleScript's text item delimiters to (return)
		set allDisks to the text items of allDisks
		set AppleScript's text item delimiters to olddelimiter
	end tell
	
	--Now I would like to call "System Events" to check each entry in allDisks to see if it is the startup disk, something like:
	repeat with d in allDisks
	tell application "System Events"
		get startup of disk d
		return result
	end tell
	end repeat
	--This doesn't work though

end launched

(I realize my tell application “System Events” block is not doing anything useful in the above example, it’s just for testing)
In this example, nothing within the tell application “System Events” block gets executed.
I tried changing it to “Finder” and just inserted a log statement to see if the tell was running, but it does not.
Does this mean I cannot embed tell application blocks within event handlers?
If not, how can I (at startup) build a list of disks, then omit from that list any disk that is the startup disk?

I typically use this:

tell application "Finder"
	set diskNames to name of every disk whose ejectable is true
end tell

Note that this will generate an error if there aren’t any ejectable disks.

Hi,

Also, the result returned from the shell is unicode text. In the statement:

get startup of disk d

d needs to be coerced to string.

get startup of disk (d as string)

If you wanted to know why.

Editted: and it’s erroring.

gl,

Just FYI… you can not use the ‘log’ command within a Finder tell block. Use ‘display dialog’ instead (when possible and usually just for testing purposes) or exit the tell block, log the item, then start a new tell block. You should only put code in tell blocks that must be there. Logging an item should not be the finder’s responsibility, so it does not support scriptability for the command.
j

Unix uses linefeed, not carriage return, characters as linebreaks, so your TIDs code fails to split the shell script’s result as you expect. Use ‘paragraphs of’ to split it; that works for any kind of linebreak:

on launched theObject
	tell window "main"
		set allDisks to paragraphs of (do shell script "cd //volumes ;ls -1")
	end tell
	...
end launched

Thanks for everyone’s help

I went with bruce’s idea, and that seemed to work!

I appreciate it!