I want to call AppleScript from LW Objective-C.
What I have to do is about (from
https://developer.apple.com/library/mac/technotes/tn2084/_index.html):
- (IBAction)addLoginItem:(id)sender
{
NSDictionary* errorDict;
NSAppleEventDescriptor* returnDescriptor = NULL;
NSAppleScript* scriptObject = [[NSAppleScript alloc]
initWithSource:
@"\
set app_path to path to me\n\
tell application \"System Events\"\n\
if \"AddLoginItem\" is not in (name of every login
item) then\n\
make login item at end with properties
{hidden:false,
path:app_path}\n\
end if\n\
end tell"];
returnDescriptor = [scriptObject executeAndReturnError:
&errorDict];
[scriptObject release];
if (returnDescriptor != NULL)
{
// successful execution
if (kAENullEvent != [returnDescriptor descriptorType])
{
// script returned an AppleScript result
if (cAEList == [returnDescriptor descriptorType])
{
// result is a list of other descriptors
}
else
{
// coerce the result to the appropriate ObjC type
}
}
}
else
{
// no script result, handle error here
}
}
My function looks like this
(defun applescript (text)
(let (err
(nsas (objc:invoke (objc:invoke "NSAppleScript" "alloc")
"initWithSource:" text)))
(objc:invoke nsas "executeAndReturnError:" err)
(objc:release nsas)
err))
and it works. I can execute AppleScript code. But I get no error
information back. I tried:
(defun applescript (text)
(let ((err (objc:invoke (objc:invoke "NSDictionary" "alloc")
"init"))
(nsas (objc:invoke (objc:invoke "NSAppleScript" "alloc")
"initWithSource:" text)))
(objc:invoke nsas "executeAndReturnError:" err)
(objc:release nsas)
err))
But I get an error
Error: #<Pointer: OBJC:OBJC-OBJECT-POINTER = #x0015D400>
cannot be
converted to foreign type (:POINTER OBJC:OBJC-OBJECT-POINTER).
This makes no sense to me.
[In a former life I tried to learn C and never completely grasped
this
pointer stuff. In my later lisp life I am very happy that there are no
pointers at all.]
Thanks for enlightment.
~jens
_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html