Re: AppleScript to C
Re: AppleScript to C
- Subject: Re: AppleScript to C
- From: Steven Majewski <email@hidden>
- Date: Tue, 6 Jul 2004 16:54:32 -0400
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.