Re: Fetching result from NSAppleScript
Re: Fetching result from NSAppleScript
- Subject: Re: Fetching result from NSAppleScript
- From: has <email@hidden>
- Date: Thu, 19 Jul 2007 23:58:11 +0100
On 19 Jul 2007, at 22:33, Nirnimesh wrote:
> I want to run an applescript and fetch its results in my cocoa app.
[...]
You need to use the methods provided by NSAppleEventDescriptor to
manipulate that data further. If you want more specific advice, you
need to say a bit more about what you're trying to achieve.
Well, I was hoping to get output similar to what osascript would
return. I now realize that as long as the script returns text, I
get what I want, but not for other datatypes (as list, in the
example above). Is there really a way I could just convert all of
these datatypes to text, just like osascript does?
You mean you want to display a AppleScript-style representation like
this:
% osascript -e 'tell app "Finder" to get windows'
Finder window id 491, Finder window id 490, Finder window id 504,
Finder window id 448
or this:
% osascript -ss -e 'tell app "Finder" to get windows'
{Finder window id 491 of application "Finder", Finder window id 490
of application "Finder", Finder window id 504 of application
"Finder", Finder window id 448 of application "Finder"}
For that you'll need to use the Cocoa OSAKit API (see OSAScript -
executeAndReturnDisplayValue:error:)
) or Carbon Open Scripting API (see OSADisplay), which provide
greater control over how results are displayed than NSAppleScript.
(I cannot directly use osascript because I want to use unicode
chars and the shell messes it up)
In what way? osascript should accept UTF8-encoded parameters and
return a UTF8-encoded result.
That said, regardless of how you call into AppleScript, you'll still
get problems as the language itself isn't fully Unicode-aware, e.g.
source code is restricted to the host system's primary encoding, and
it seems to substitute certain Unicode characters with '?' when
formatting results as text. If you really need full Unicode support
you'll have to use a language that actually provides it such as ObjC
or Python.
Again, if you want more specific advice you'll need to say more about
what it is you're working on.
HTH
has
--
http://appscript.sourceforge.net
http://rb-appscript.rubyforge.org
http://appscript.sourceforge.net/objc-appscript.html
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden