Use Resedit to add script

I would like to use resedit to add and run a compiled AppleScript within an application.
Is it possible to use resedit to add an apple script as a resource within an application?
Thanks, Justin

That’s very simple. A script saved compiled or as an app contains a “scpt” resource. If you want to see it in ResEdit other than as gobbldegook you would need the appropriate template, with which it would look exactly as it appears in Script Editor. You don’t, though, need to examine it - you can simply copy it and then paste it anywhere else you like (e.g. into the app you have in mind).

I haven’t the faintest idea what this means. What is going to run the script? What app are you talking about? An app you have written or - as I suspect you mean - someone else’s app?

Without further information I can make neither head nor tail of this. Pasting the ‘scpt’ resource into an app might of itself do no damage because the app would just ignore it - but then what happens? If there is something I haven’t thought of or don’t know about I would love to hear more from you.
Andreas

Hi,
This can be done using Jon’s Commands Scripting Additions ‘run script resource’ command. As a simple example try doing this. First, create a script application:
run script resource “hello”
and save as application. Next, close the window and open a new script window. The following will be your compiled script:
display dialog “Hello.”
Save as compiled script and quit the Script Editor. Run ResEdit or some other resource editor. Open the compiled script’s “scpt” resource. Select all and copy all that hex stuff. You can close it if you want now and open the applications resource fork. Create a new resource of type “Scpt” (note the capital S). Paste the data from the compiled script. Get info on that resource and name it “hello”. Quit and save changes. Run the script application and it will run the script in the resource.
You can find further documentation in the Jon’s Commands package.
gl, Kel.

I’ve learnt a bit more - thanks, Kel. I just embedded a couple of "Scpt"s in Tex-Edit Plus - no problems - working perfectly. Please, though, explain a bit more. I can see an immediate advantage of this method in compactness - but what else? Could you perhaps give me a couple of examples where you actually use this method or where you would choose to use it. I don’t mean example scripts - that I don’t need - I mean a real or hypothetical situation where an embedded script would be perhaps the method of choice.
And an additional question for you, Kel. Jon’s documentation has (in the Run Script Rsrc section):

Firstly I presume that this means write it (and copy it) in Script Editor (selecting QK in the pop-up menu to get it to compile) and not in the QK Editor. The latter, as far as I can see produces data only intelligible to the QK Editor itself and to no-one else. Secondly - and my real question here - what advantage might this have over “tell QK Toolbox etc”?
Andreas

Hi Andreas,
Actually, I was just trying to give a solution to the question of how to run a script stored in a resource. However, I’ve also been trying to think of ways to use this idea. As you said, its compactness would be good for very large scripts. Instead of transfering a bunch of compiled scripts they would all be there in one script with little thought needed by users. You could create a script runner. I did the same thing that you did with regards to Tex-Edit. But, I was thinking that for attachable applications this in unnecessary since you can just run the script through the script menu. So, perhaps this idea may have uses with non-attachable applications. There is only one app that I can think of that is non-attachable and can compile and run the command ‘run script resource’. What you could do is embed compiled scripts in the Script Editor. If the user did not have OSA Menu then the user could run a compiled script from a Script Editor window instead. Of course the user could just as well use the ‘run script’ command if the user wanted to keep the Script Editor in the front. So, I guess this would come under the catagory of compactness also. Perhaps Justin can tell us his thoughts about why he would want to use this mwthod also.
About the statement in the Jon’s Commands documentation, at first, I was a bit confused also. I don’t have QK, but, my thought is that it is like the Tex-Edit command ‘do script’ where you can run text as a script. Perhaps this is why he mentions that you do not need his OSAX to do this, but, just QuickKeys. Example:

tell application "Tex-Edit Plus" 
activate 
do script "display dialog "Hello."" 
end tell

My biorythms is a bit low right now. Perhaps, in a week or 2 some great world changing idea about how to use this idea will come to me. Have you come up with anything and where’s Justin?
Have a good day, Kel.

I don’t have QiuckKeys again so just guessing. My guess is that QuickKeys is a scripting component. Somehow you would record a script in QuickKeys. Copy the text and Paste it into the variable foo. In applescript your script would be something like this:

set foo to "say "hello"" run script foo in AppleScript

I have only one scripting component, but, guessing that AppleScript is default so its its not needed. For a QuickKeys script the value of foo would be the text of the script and in place of AppleScript component you would use QuickKeys.

Thank you, Kel (and now you too, Eelco) for the imput. Kel, as you don’t use QK it won’t mean much to you (and I don’t expect you to respond to it), but you can’t actually copy from QK - what you get on the clipboard is readable only by QK itself - so you can copy and paste easily within the QK Editor but, although it looks like ‘text’, it can’t be used anywhere else. That’s why I’m pretty sure that my interpretation of what Jon wrote is correct - and it works. i.e. Somehow find out the QK-speak for the command (e.g. speech “Hello”), write it in the AS Script Editor (optionally choosing “QK” in the pop-up to test it), and then copy and paste it into a ‘normal’ (AS) Editor window and use it via "run script “speech “Hello” in “quicKeys””.
For anyone following this thread who uses QK I would add that the problem (for me) is knowing how to say it in QK-speak. Most commands don’t show their ‘translation’, but a little trick I use is to tempoarily put the same command within a ‘sequence’. The Sequence Editor has an option to “show additional step info” where the translation, although it can’t be copied as text, can at least be seen and transferred manually to the AS Script Editor. (I certainly don’t want to try to learn QK-speak so that is good enough for me on the very few occasions I might want to use it).
Eelco, you say:

I would give more weight to that than you do. I often spend time rewriting bits of an app just to minimise some yo-yoing to-and-fro. And now we have yet another little trick up our sleeves. Great!
That more or less sums this little chapter up for me - no burning instant use for it, but for sure a tool that will get used. Thanks to you, Kel, for bringing it to my attention, I feel sure that this method will gradually creep into my scripting. Next time I see some unpleasant yo-yoing guess what will spring to mind, Eelco.
Thanx guys
Andreas

Andreas / Kel,
Just some thoughts on your embedded scripts.
There may be some speed benefit for QuicKeys.
I refer to situations where QK is the solution if the host app has no or a limited AE dictionary.
I recall that in OS9, using QK to send/execute scripts is very slow. (compared to OSX, it seems that QK does compilation on the fly in OSX while in OS9 the QK Backgrounder does so in runtime).
Now QK can make a direct call to the compiled script embedded in the host app, without compilation which is faster.
The other (minor) advantage is that the host app is and stays in front, when executing the script which means less app switching / system overhead.
If direct passing variables between the app and the embedded script would be possible, I’d see considerably more advantages (and even so more disadvantages such as complexer debugging!)
Eelco Houwink