Helpful Hints On Executing AppleScript |
|
Usually most people will put the script into a variable that they can then execute with thetell application "Finder" activate open folder open folder "MyHD:MyFolder:MySubfolder" end tell
do
command. One way to do this is like this:
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:put "tell application " & quote & "Finder" & quote & cr & \ "activate" & cr & \ "open folder " & quote & "MyHD:MyFolder:MySubfolder" & quote & cr & \ "end tell" into tScript
format
and
merge
.
Here’s the same block of code using format
:
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.put format("tell application \"Finder\"\n activate\n") & \ format("open folder \"MyHD:MyFolder:MySubfolder\"\n end tell") into tScript
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:
To call this withput "tell application " & quote & "Finder" & quote & cr & \ "activate" & cr & \ "open folder " & quote & ConvertPath(pPath) & quote & cr & \ "end tell" into tScript
merge
, you could do this (the "q" function simply puts quotes
around whatever is pased to it):
Originally posted 3/12/2002, updated on 8/12/2002 by Terry Vogelaar to the Use-Revolution List (See the complete post/thread)put merge("tell application [[q(Finder) & cr]]activate[[cr]]")