Re: Converting "scpt" resource to text
Re: Converting "scpt" resource to text
- Subject: Re: Converting "scpt" resource to text
- From: Mike Miller <email@hidden>
- Date: Tue, 31 Jul 2001 18:36:02 -0500
At 9:58 PM +0300 7/31/01, Douglas Wagner wrote:
>
As Mike Millar suggested, I can get the text of the "scpt" resource by saving the resource as a ScriptEditor document. However, what I want to do is get the resource and convert it to text, inside the current script, and then add it to a list of other scripts I've extracted from the window objects in the Facespan project.
Remember, you don't need to dig through 'scpt' resources to get the Project Script. Use load script on the FaceSpan project/app and you have it. My first post showed a working example.
But for what it's worth, this should work. It uses ResourceIO 1.4.1.
on hilited theObj
set theFile to choose file with prompt "Select a file:"
try
set resFile to openResourceFile theFile
try
set resCount to count1Resources resFile of type "scpt"
if resCount < 1 then
error "No Scripts" number 20001
end if
if resCount > 1 then
-- Here you would ask which script to read, or read all of them.
-- For this example, we'll always read the first one.
-- I don't believe any normal scripts or FaceSpan apps have
-- multiple 'scpt' resources, but you never know...
set resCount to 1
end if
if resCount > 0 then
set itsScript to get1IndexedResource resFile of type "scpt" index resCount as script
set itsText to (resData of itsScript) as text
set contents of textbox "txtScript" to itsText
end if
on error errTxt number errNum
closeResourceFile resFile
error errTxt number errNum
end try
closeResourceFile resFile
on error errTxt number errNum
set contents of textbox "txtScript" to errTxt & return & errNum
end try
end hilited
>
Apart from being rather complicated, saving the "scpt" resource to disc and then opening it in a script editor causes the Facespan commands to appear as apple event codes. If I can get the script as it appears in the Facespan editor I don't have any lookups to do.
This is where you're going to have trouble. In normal situations, you don't have the FaceSpan terminology available. It will work if you're running in the FS Development Environment, where the FS terminology is fully there. As an app, it works but loses the FS-specific terminology.
However, FaceSpan 3.5.1 comes with a Script Exporter app that doesn't have this problem. So what's the difference? The FS Script Exporter has a number of OSAXen embedded. Open up the app in ResEdit and look at the 'osax' resource type.
When I copied all of the 'osax' resources into an app that shows scripts for you, it seemed to work. I'd recommend trying that if the existing Script Exporter isn't enough. The steps are:
Make an app from your project.
Open the app and the Script Exporter that came with FaceSpan in ResEdit.
Copy all the osax resources from the FaceSpan Script Exporter into your app.
Save your app and quit ResEdit.
Hope this helps,
Mike Miller
ESG Labs
http://www.esglabs.com/