Helpful Hints On Executing AppleScript
Mac Only Mac Only

Although MetaCard and Revolution allow you to execute AppleScript, assembling the AppleScript itself to be executed can sometimes be a laborious chore. Consider the following code adapted from the tip file009: Opening a Folder on the Desktop:
tell application "Finder"
  open folder 
  open folder "MyHD:MyFolder:MySubfolder"
end tell
Usually most people will put the script into a variable that they can then execute with the do command. One way to do this is like this:
put "tell application " & quote & "Finder" & quote & cr & \
  "activate" & cr & \
  "open folder " & quote & "MyHD:MyFolder:MySubfolder" & quote & cr & \
  "end tell" into tScript
This is not bad, as it is quite readable, but a real pain to type. Luckily MetaCard and Revolution have two commands that help deal with some of these issues: format and merge.

Here’s the same block of code using format:

put format("tell application \"Finder\"\n activate\n") & \
  format("open folder \"MyHD:MyFolder:MySubfolder\"\n end tell") into tScript
It’s a lot shorter, although you can’t break a function in the middle, so for larger scripts you’ll need to call it multiple times (like I’ve done above). Note that the spaces after the \n were added for readability, but they don’t have to be there.

Another alternative is to use the merge function, which is especially helpful when you have functions to evaluate. The original code taken from file009: Opening a Folder on the Desktop actually had a function call:

put "tell application " & quote & "Finder" & quote & cr & \
  "activate" & cr & \
  "open folder " & quote & ConvertPath(pPath) & quote & cr & \
  "end tell" into tScript
To call this with merge, you could do this (the "q" function simply puts quotes around whatever is pased to it):
put merge("tell application [[q(Finder) & cr]]activate[[cr]]")
Originally posted 3/12/2002, updated on 8/12/2002 by Terry Vogelaar to the Use-Revolution List   (See the complete post/thread)