Page 1 of 1

Fun with AppleScript

PostPosted: Sat May 29, 2010 6:33 pm
by udo.killermann
Hello Board,

using the latest Beta Objective Basic is now capable to handle AppleScript calls via NSAppleScript and NSAppleEventDescriptor:
Code: Select all
Declare Class "NSAppleEventDescriptor"
Declare Function "NSAppleEventDescriptor" - (NSString *)stringValue
Declare Function "NSAppleEventDescriptor" - (DescType)descriptorType
Declare Function "NSAppleEventDescriptor" - (NSInteger)numberOfItems
Declare Function "NSAppleEventDescriptor" - (NSAppleEventDescriptor *)descriptorAtIndex:(NSInteger)anIndex
Declare Function "NSAppleEventDescriptor" + (NSAppleEventDescriptor *)alloc


Declare Class "NSAppleScript"
Declare Function "NSAppleScript" + (id)alloc
Declare Function "NSAppleScript" - (id)initWithSource:(NSString *)source

Declare Function "NSAppleScript" - (id) executeAndReturnError: (NSError **) errorInfo



Event AwakeFromNib()
  Dim myScriptString As String
  Dim myASScript As NSAppleScript
  Dim myAEDescriptor As NSAppleEventDescriptor = Nil
 
 
  Dim err As id = Nil
   
  myScriptString = "choose URL"
 
  myASScript=myASScript.initWithSource(myScriptString)
 
  myAEDescriptor = myASScript.executeAndReturnError(errinfo := err)
 
  Alert(myAEDescriptor.stringValue())
 
End Event


Using
Code: Select all
myScript="tell application \"System Profiler\"\nset detail level of document 1 to basic\nset theProfile to profile of document 1\nend tell"
you will see the current system configuration.

Have Fun
Udo

Re: Fun with AppleScript

PostPosted: Tue Jun 01, 2010 7:04 pm
by berndnoetscher
Hi Udo!

Thanks for your feedback.
Happy coding :-)

CU
Bernd