Re: AppleScript to C
Re: AppleScript to C
- Subject: Re: AppleScript to C
- From: "John W. Baxter" <email@hidden>
- Date: Tue, 06 Jul 2004 15:18:43 -0700
Years ago (ca 1993-94, I had a little toy application which used in-line C
to build and send the Apple events necessary to instruct Microsoft Excel to
create a spreadsheet--I think that was pre-"workbook"--and put values in one
or two cells. Lots of grunt work code (which, had I been serious I would
have hidden in carefully-crafted functions).
I had an alternate path through the system which created the needed
AppleScript script, and had the AppleScript component compile and execute
it. Again straight line. The AppleScript version fit on one Mac Plus
screen. The Apple event version didn't come close of one screen.
Stick with the modern equivalent, the NSAppleScript class use, as Steve
suggests. Unless you really want to mess about.
--John
On 7/6/2004 13:54, "Steven Majewski" <email@hidden> wrote:
>
You can send apple events if you want, but is there any reason you can't
>
just use Cocoa Foundation's NSAppleScript on a text string?
>
>
[ A python example using pyobjc is at bottom. ]
>
>
It's been a while since I had to do it with raw events and Carbon, but
>
if you know how to send the standard event suite events, any others are
>
going to be done exactly the same. Only the event codes and descriptors
>
are going to change.
>
>
-- Steve Majewski
>
>
On Jul 6, 2004, at 4:06 PM, Mark Thomas wrote:
>
>
> Hi All,
>
> Does anyone know if there is a good way to convert apple script to
>
> C/C++
>
> as I'm going to need to do a variation of
>
>
>
> tell application "Safari"
>
> get the URL of the document of the front window
>
> end tell
>
>
>
> I know roughly how to send the standard events, but anything more
>
> than
>
> that no ideas :-(.
>
>
>
> also I remember way back there was a way to do a Msg boxes, as I
>
> would
>
> like to check that actual URL I'll get back.
>
>
>
>
>
>
>
src = defsrc = """
>
tell me
>
activate
>
display dialog "TESTING..."
>
end tell
>
"""
>
>
import sys,os
>
>
from Foundation import NSAppleScript,NSString
>
as=NSAppleScript.alloc()
>
>
# file must be an .applescript source code file, not a compiled script.
>
>
if sys.argv[1:] and sys.argv[1]: # else (no filename), use
>
default string as script.
>
os.stat( sys.argv[1] ) # file exists ?
>
src = NSString.stringWithContentsOfFile_( sys.argv[1] )
>
if not src : raise IOError( "empty? " + sys.argv[1] )
>
>
as.initWithSource_( src )
>
print as.source().encode( 'UTF' ) # applescript source files may have
>
unicode chars.
>
# ( and without encode(), printing
>
unicode can fail )
>
out = as.executeAndReturnError_()
>
>
print out
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.