Is it possable to compile ASOC scripts or projects outside of Xcode or the Applescript Editor ?
For example can you use osacompile on ASOC code, or do you use another compiler like LLVM from the command line ?
Many Thanks
Regards Mark
Is it possable to compile ASOC scripts or projects outside of Xcode or the Applescript Editor ?
For example can you use osacompile on ASOC code, or do you use another compiler like LLVM from the command line ?
Many Thanks
Regards Mark
Yes, you can use osacompile. I’m pretty sure that’s what Xcode is using anyway.
OK thanks Shane.
I hav’nt tried it yet, still planning how to construct my project, but I would like to compile ASOC code on the fly.
do you have to set any language flags for ASOC code ?, as the man pages for osacompile doesn’t give any ASOC specific instructions.
Working my way through your “Everyday ApplescriptObjC” book at the moment, and finding it very useful, and I’m learning a lot from it.
Thanks again.
Regards Mark
The compile man page should have all you need – ASObjC code is compiled the same. You will probably have to add or edit the bundle’s Info.plist file to add the ASObjC entry yourself after you compile.
You can also use NSAppleScript or OSAScript.
Hello.
Here is a snagged and slightly reworked piece from Mac OSX Automation that may be a good starting point for setting the property.
tell application "AppleScript Editor"
try
-- Check to see if the front document has been saved as a bundle.
try
set the doc_properties to the (properties of the its document 1)
set the script_path to the path of doc_properties
set the plist_path to script_path & "/Contents/Info.plist"
set the plist_file to plist_path as POSIX file as alias
on error
error "The " & name of doc_properties & " script has not be saved as a Script bundle."
end try
tell application "System Events"
tell property list file plist_path
if (exists property list item "OSAAppleScriptObjCEnabled") then
set the value of property list item "OSAAppleScriptObjCEnabled" to true
else
make new property list item at end of property list items of contents of it with properties {kind:string, name:"OSAAppleScriptObjCEnabled", value:true}
end if
end tell
end tell
display notification "The " & name of doc_properties & " bundle is enabled as an ASObjC Library"
on error error_message number error_number
display notification error_message
end try
end tell
I don’t think setting OSAAppleScriptObjCEnabled for an app bundle is going to do anything, though – only .scptd packages.
Anyway, here’s an ASObjC way of doing it:
on enableASObjCIn:posixPath
set theURL to (current application's NSURL's fileURLWithPath:posixPath)'s URLByAppendingPathComponent:"Contents/Info.plist"
set theDict to current application's NSMutableDictionary's dictionaryWithContentsOfURL:theURL
theDict's setValue:true forKey:"OSAAppleScriptObjCEnabled"
theDict's writeToURL:theURL atomically:true
end enableASObjCIn:
Hello.
The old comments and erromessages are revised.
I like your version better!
I like your new AS command tyr :)You might also change kind:string to kind:boolean, just for the sake of correctness.
Thank you both for your help with a solution for setting the OSAAppleScriptObjCEnabled flag of the bundles info.plist.
but I’m no way near that point as yet in the project, and was only really after some ideas as to how to compile ASOC code in the background without activating Applescript editor, or indeed Xcode.
The truth is that I have an idea for a project, and one of the problems that i was going to have to solve was the aforementioned ASOC code compiling issue, but the reality is that I would have a long way to go in the project before needing a solution, but just needed to know that it was a solvable problem.
Although if you have any code snippets showing any possable solutions for the ASOC background code compiling, I would be very grateful.
The first task in the project would be to create a simple BASIC programming language code editor, and as a relative novice to ASOC and Objective-C, I would probably need help with making the code editor part first.
Which brings me to a unrelated question for Shane, do you have any advise as to how to build a simple text editor, which can format the entered text as it is typed, in much the same way as a simple code editor does ?
Many Thanks
Regards Mark
Thank you very much I have corrected it. I blame Safari’s autocompletion for the unsolicited tyr!
@MarkFX:
It is very easy to translate Basic to AppleScript.
Yeah I can see that translating Basic to Applescript would be fairly simple.
Showing my age, but I miss the original Basic language I learnt as a young person in the DOS days.
The modern Object Oriented versions are great, but lack the simpleness of the original language.
I would like to create a simple Basic code editor, then have that editor create and compile Applescript
or ASOC code in the background, so when you hit a Run button on the code editor, it runs what appears
to be Basic code, but in fact runs the background Applescript code instead.
Sounds simple, but probably a more complex project than it sounds.
That’s the idea anyway, still thinking how to tackle it, while continuing to learn ASOC.
Regards Mark
Hello.
I wish you the best of luck with your project. I am a Basic fan myself, (but I love AppleScript!) At least there were a lot of interesting programs written in basic some time ago, although the user interface lacks some finish by todays standard.
My personal opinon, is that when I use TextEdit as a console window, I get that “feeling” back. IMHO, AppleScript is a lot more friendly/flexible environment than GWBasic for instance. (I leave BBC basic and line numbers out of this.) Of course, you can’t use half/bytes from AppleScript, and you’ll have to find ways to implement your own trigonometry and other functions, (see script below.). I don’t think it is an easy task to write a “machine-interpreter” from Basic into AppleScript, but I think it is doable. At least when it comes to “Console programs” that is programs that sends output to the console in a line oriented fashion, like with print statments, when it comes to the “CRT” programs, that has a lot of code in it for writing to screen memory, then I’m more of a skeptic, I think you’ll then need to use curses and shell scripting to emulate the effect, or do that part in Objective-C. But for what I know someone has made something like that already and open sourced it… I’d google a lot if I were you, as you may find large pieces for your project out there:)
Edit
You may also use the sketch.app that is an example project from Apple for drawing simple graphichs, to have something to look at, or play with, when it comes to drawing routines. (It is very fun to use from AppleScript since it provides a low entry access to scripting graphics. (A lot more fun than writing Postscript.)
The linke below is an example of a fairly complex basic program that was converted by Nigel Garvey into AppleScript.
MacScripter / A Script that calculates Sunrise and Sunset from your coordinates.
There are several syntax-coloring editors whose code is available on the Web. But I wouldn’t attempt such a thing in ASObjC – you really need Objective-C for both performance and multi-threading. Ironically, styling is easier with AppleScript, because the AppleScript interpreter does it for you.
Thanks again Shane and McUsrII for all of your advise.
You know what it’s like, you have an idea for an app that in reality would have very little commercial appeal, but would represent more of a novelty for old folks like me, so I shall give it some thought as to wether the work involved would be
justified, while continuing my efforts to learn ASOC and Objevtive-C.
Regards Mark
Hi,
I’m quite sure there’s a Basic compiler somewhere in unix.
Edited: oh I see. You want the editor.
gl,
kel