I want to make a script that has builtin funcitons, and reads and external text file to run functions. So for example, you have a plain text file that says:
And the script has a function called DoSomething() like this:
to DoSomething()
display dialog "It Worked!"
end DoSomething
The problem is that I get the error “<> doesn’t understand the DoSomething() message.” If I put the function in the the text file along with the command, everything works fine, but that defeats the whole purpose entirely. I know there must be a way to do this, but I need some help.
Thanks,
Black Leopard
P.S. I know how to call the text file. I get this far:
set UserName to (do shell script "whoami")
set CommandPath to ("/Users/" & UserName & "/Desktop/Commands.txt")
set CommandPath to (POSIX file CommandPath) as Unicode text
run script (read file CommandPath)
and that works fine, so I don’t need help with it (unless I did it inefficently, in which case, please let me know!)
Edit: Post withdrawn with my apologies. I hadn’t realised that what I was suggesting depended on having Jon’s Commands installed. This OSAX has a script-to-text coercion that was somehow being triggered in the transfer of the run script parameter. kel’s suggestion seems the way to go.
Also, note that if you save the main script as an applicaiton, then it should work when run as an app.
Main script:
set dp to (path to desktop as string)
set CommandsPath to (dp & "Commands.txt") as alias
run script CommandsPath
--
on DoSomething()
display dialog "It Worked!"
return
end DoSomething
Here’s another way. You place all your handlers in a script server. You can save it as stay open application. e.g.
on Do1()
display dialog "It Works!"
return
end Do1
--
on Do2()
display dialog "Here's more."
return
end Do2
--
on Do3()
display dialog "Haven't you had enough?"
return
end Do3
In your text file, you declare the above script application as the parent.