Is there a way to read a compiled Applescript?

Binary stream reads uncompiled Applescripts ( i.e.text files) into a XOJO TextArea, though I would prefer to be able to read in a compiled Applescript using GetOpenFolderitem and display the file’s contents just the same as the uncompiled script text. If I try to read a compiled applescript I get garbage, which is what I expected. Can anyone point me in the right direction. Am guessing that accessing the Cocoa API is the way to go but I have no idea how to go about. If MBS is the only solution then it will be too expensive for me and I’ll stick to my current limitation of using uncompiled scripts. Thanks in advance.

Did you try AppleScriptMBS or NSAppleScriptMBS classes?

I think you can put compiled script in binary property and than read source property.

If you save the app as “only executable” you can’t retrieve the source code.

Thee is really no need for an expensive plugin here (as suggested in the SPAM above). Just a few declares are fine for AppleScript.
See Speak Command for the declares.
It takes an AppleScript text, compiles it and calls the compiled script.

Only very seldom I would like to see a “dislike” button.

Many people here in this forum highly appreciate the efforts and initiative of Christian to continously support the xojo community with his knowledge and expertise, with organizing Xojo congresses and last but not least with his invaluable plugins.

His recommendation is perfectly on topic and I personally use his plugins for exactly the purpose asked for in this thread. So: no spam at all!

Well, since there is no disclaimer that he does sell his plugins himself when he recommends it, it is actually just SPAM for me.

Also: Plugins are needed for specific tasks. There are not needed for simple stuff which can be easily resolved by using a declare.

Call “osadecompile” using a script… it is included as part of macOS

Thanks all for responding. The Applescripts to be included are saved as ‘compiled’ in ScriptDebugger or Script Editor, not as a read only application (what Beatrix calls an 'only executable '). Don’t know anything about OSAdecompile but will investigate. Dave do you have a little more info on your suggestion?

Go to Terminal and type MAN OSADECOMPILE

Can’t you code what those AppleScript do in Xojo ?

AppleScript can be so slow (on file access for example).

in the Terminal:
man -k OSAdecompile

thanks for your

My I must be really stupid ;-)…

In answer to questions, no, AppleScript is required to automate Adobe Creative Suite and much more besides and that is my service and skill set - publishing automation. AppleScript is single threaded so bombing out of a 20k line Applescript that may take 20 minutes to complete can cause a mess on a computer, which is why I am writing a threaded scriptable progress bar in XOJO that can embed / launch a user defined applescript that can clean up the mess post bombing out of a publishing automation script… phew i think that just about covers it. of course the final app needs to comply with Apples rules to be sold on the appstore too

[quote=430908:@Emile Schwarz]Can’t you code what those AppleScript do in Xojo ?
AppleScript can be so slow (on file access for example).[/quote]
There are some things that are hard to duplicate in Xojo code
Like setting a files tag to anything you want

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

use framework "Foundation"

on run {theTag, thePath}
	try
		set theURL to current application's NSURL's fileURLWithPath:thePath
		set {success, tagArray, theError} to theURL's getResourceValue:(reference) forKey:(current application's NSURLTagNamesKey) |error|:(reference)
		if theError is not missing value then error theError's localizedDescription() as text
		if tagArray is not missing value and (tagArray's containsObject:theTag) as boolean is true then return
		if tagArray is missing value then set tagArray to current application's NSMutableArray's array()
		tagArray's addObject:theTag
		set {success, theError} to theURL's setResourceValue:tagArray forKey:(current application's NSURLTagNamesKey) |error|:(reference)
		if theError is not missing value then error theError's localizedDescription() as text
	on error
		log theError
	end try
end run

-- use like addTagToPath("Green", "/Users/npalardy/Desktop/foo")

For file tags we got a method for FolderItem class in our plugins:

folderitem.SetTagNamesMBS(tags() as string) as Integer

https://www.monkeybreadsoftware.net/files-folderitem-method2.shtml#7

Oh I know this
Just saying that trying to do some things in Xojo instead of AppleScript can be challenging
There are still a lot of apps you can drive the UI using AppleScript and significant portions of the macOS UI you can drive using AppleScript
And it doesnt require a plugin :stuck_out_tongue:

And sometimes the answer is elsewhere (as Dave once gives me).

To give a good answer, sometimes we need a bit more data to understand what the op want to do, not a simple answer to a simple question. :wink:

Getting back to the subject :wink: …is it possible to call a function in XOJO that can access the Cocoa API to perform OSADecompile on a user selected applescript at runtime so that it can be streamed in as text and then later executed using:

[code]Method ExecuteAppleScript(TheScript as string) As String
soft declare function NSClassFromString lib “Cocoa” (classname as CFStringRef) as ptr
soft declare function initWithSource lib “Cocoa” selector “initWithSource:” (obj as ptr,source as CFStringRef) as ptr
soft declare function executeAndReturnError lib “Cocoa” selector “executeAndReturnError:” (obj as ptr,byref error as ptr) as ptr
soft declare function alloc lib “Cocoa” selector “alloc” (classRef as Ptr) as Ptr
soft declare function stringValue lib “Cocoa” selector “stringValue” (classRef as Ptr) as CFStringRef

dim nsscript As ptr=initWithSource(alloc(NSClassFromString(“NSAppleScript”)),TheScript)
dim err As ptr
dim descriptor As ptr=executeAndReturnError(nsscript,err)
if err<> nil then
MsgBox “An error occured”
else
//MsgBox stringValue(descriptor)
end if

control Action()
Call ExecuteAppleScript(TheScript)[/code]

it’s like the above function needs to be reversed i.e. decompile-and-read-in rather than compile-and-read-out

The OSADecompile is really nice functionality as an AppleScript to decompile another AppleScript but my XOJO app won’t know in advance what script the user wants to attach to it at runtime.

you can call osadecompile with an arbitrary file

  dim f as fodleritem = GetOpenFolderItem("") // the user picks a script

 dim s as new shell
 s.execute "/usr/bin/osadecompile " + f.shellpath
 
 // s.result should now contain the text

EDIT - note this is written entirely in the forum so it may not be 100% accurate

https://derflounder.wordpress.com/2016/05/10/reading-applescript-source-code-with-osadecompile/