Applet needs to be recompiled before each use

Hey All,

I’ve got an applet for backing up and restoring virtual machines. Everything works just like it should except that it returns a type error “can’t make … into expected type” when trying to assign a displayed name of an alias to a string through a finder tell.

This only happens, however, if the applet hasn’t been compiled recently. So, I’ll try to run the applet and it returns the error. If I open, compile, save and close the applet and try again then everything works perfectly.

Below is the handler that throughs the error. The error occurs with the first line in the loop, the Finder tell.

Any reason you can think of why it should throw this error but not once recompiled? Maybe the applet forgets what Finder is until it’s recompiled and reassigned to the Finder application? This not the first call to the finder in the script though, so I doubt that’s it.

[Edit] Forgot to mention, the handler receives a list of aliases as its argument.

on getComments(VMs)
	set comments to {}
	
	repeat with currentVM in VMs
		tell application "Finder" to set vmName to displayed name of currentVM as string -- here's where the error's thrown
		tell me to display dialog "Enter comment for " & vmName default answer "leave blank for no comment" buttons {"Continue"} default button "Continue"
		set comment_ to text returned of result
		if comment_ is not "leave blank for no comment" then
			set commentParse to parseLine(comment_, space)
			if (count of commentParse) is greater than 1 then
				set commentUnderscore to {}
				repeat with i from 1 to ((count of commentParse) - 1)
					set end of commentUnderscore to item i of commentParse & "_"
				end repeat
				set end of commentUnderscore to last item of commentParse
				set comment_ to commentUnderscore as text
			end if
		end if
		set end of comments to comment_
	end repeat
	
	return comments
end getComments

Hi scriptim,

I get this error also sometimes. It’s because when you use it from the repeat loop variable, it has the form:

item n of {list items}

when you try to coerce to string I think it can’t do that. Try ‘contents of variable’, where variable is currentVM. I think that was the solution.

gl,

So the syntax would be “…to displayed name of (contents of currentVM)”

would that be the same as “…to displayed name of (info for currentVM)”?

It’s just my long shot, but change this:

tell application “Finder” to set vmName to displayed name of currentVM as string – here’s where the error’s

to this:

tell application “Finder” to set vmName to displayed name of (contents of currentVM) as string – here’s where the error’s

Hope it works x

Wait, what are the list items?

My guess, is that you would drop the as string and just use (contents of variable).

gl,

It’s a list of aliases, I think. The list is originally populated by this finder tell, so they could be aliases or files.

tell application "Finder"
		set files_ to every item of folder_ whose name extension is extension
end tell

That gives you a list of Finder references. You could use ‘as alias list’ after this:


tell application "Finder"
       set files_ to (every item of folder_ whose name extension is extension) as alias list
end tell

or try this in the end part after you’ve gotten the list of Finder references:

tell application “Finder” to set vmName to displayed name of ((contents of currentVM) as string) as alias

You might not need the 'contents of part.

gl,