• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: AppleScript to C
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.


  • Follow-Ups:
    • Re: AppleScript to C
      • From: "John W. Baxter" <email@hidden>
References: 
 >AppleScript to C (From: Mark Thomas <email@hidden>)

  • Prev by Date: Re: Getting the default language with AppleScript
  • Next by Date: Re: Getting the default language with AppleScript
  • Previous by thread: AppleScript to C
  • Next by thread: Re: AppleScript to C
  • Index(es):
    • Date
    • Thread