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