|
List Info
Thread: Re: catching quit from Wish menu
|
|
| Re: catching quit from Wish menu |

|
2007-02-27 15:49:26 |
Jon Guyer wrote:
> On Feb 27, 2007, at 3:40 PM, Robert Karen wrote:
> > I'm using tcltkaqui BI and want to catch the Quit
from the Wish menu.
> > Could someone tell me the tclAE commands to do
this, or a simpler way,
> > if there is one (besides renaming 'exit').
Thanks!
>
> % package require tclAE
> 2.0
> % tclAE::installEventHandler aevt quit
handleQuitApplication
> % proc handleQuitApplication {theAppleEvent theReplyAE}
{
> ...
> }
Do these actually work with the latest Tcl that has the
::tk::mac: event
handlers? I've been having troubles with getting Tk apps to
receive any
command line arguments. The problem is that the
OpenDocument handler
specifically operates by only allowing file references
through. This means if
you pass something like:
myapp --switch /path/to/file
you don't see --switch, just the filename (and only if it is
a real file).
Trying to use tclAE to override the built-in AE event
handlers in Tk has not
worked for me.
Jeff Hobbs, The Tcl Guy, http://www.ActiveState.co
m/
------------------------------------------------------------
-------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the
chance to share your
opinions on IT & business topics through brief
surveys-and earn cash
http://www.techsay.com/default.
php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Tcl-mac mailing list
tcl-mac lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tcl-mac
|
|
| Re: catching quit from Wish menu |
  United States |
2007-02-27 16:01:07 |
On Feb 27, 2007, at 4:49 PM, Jeff Hobbs wrote:
> Do these actually work with the latest Tcl that has
> the ::tk::mac: event
> handlers?
I don't know, I'm using
% set tk_patchLevel
8.4.14
which seems to support them, but I'm not a tk guy.
> Trying to use tclAE to override the built-in AE event
handlers in
> Tk has not
> worked for me.
I'm happy to try to help. What have you tried?
------------------------------------------------------------
-------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the
chance to share your
opinions on IT & business topics through brief
surveys-and earn cash
http://www.techsay.com/default.
php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Tcl-mac mailing list
tcl-mac lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tcl-mac
|
|
| Re: catching quit from Wish menu |

|
2007-02-27 16:15:56 |
Jon Guyer wrote:
> On Feb 27, 2007, at 4:49 PM, Jeff Hobbs wrote:
>> Do these actually work with the latest Tcl that has
>> the ::tk::mac: event
handlers?
...
>> Trying to use tclAE to override the built-in AE
event handlers in
>> Tk has not worked for me.
>
> I'm happy to try to help. What have you tried?
OK, using ActiveTcl 8.4.14(-ish), I run tkcon an type into
the main interp:
(PAI) 49 % package require tclAE
2.0
(PAI) 50 % ::tclAE::installEventHandler aevt odoc echo
odocAE
(PAI) 51 % alias ::tk::mac::OpenDocument echo odocTk
::tk::mac::OpenDocument
and then in the Script Editor I type in:
tell application "Wish"
open "/Users/jeffh/.emacs"
end tell
every time I execute that, I get:
odocTk
printed ... I've tried "open document" and
variations, but even then I
don't get args passed in. I'm just trying to override the
standard odoc
to be able to accept whatever comes in, as that seems to be
the aevt
used by OS X for command line arg passing (in some sense).
Or some
sensible alternative to that.
Jeff
------------------------------------------------------------
-------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the
chance to share your
opinions on IT & business topics through brief
surveys-and earn cash
http://www.techsay.com/default.
php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Tcl-mac mailing list
tcl-mac lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tcl-mac
|
|
| Re: catching quit from Wish menu |
  United States |
2007-02-27 18:43:28 |
On Feb 27, 2007, at 5:15 PM, Jeff Hobbs wrote:
> Jon Guyer wrote:
>> On Feb 27, 2007, at 4:49 PM, Jeff Hobbs wrote:
>>> Do these actually work with the latest Tcl that
has
>>> the ::tk::mac: event
handlers?
> ...
>>> Trying to use tclAE to override the built-in AE
event handlers
>>> in Tk has not worked for me.
>> I'm happy to try to help. What have you tried?
>
> OK, using ActiveTcl 8.4.14(-ish),
"-ish"? I guess! 8^)
alias? echo? I guess those are tkconisms?
> I run tkcon an type into the main interp:
>
> (PAI) 49 % package require tclAE
> 2.0
> (PAI) 50 % ::tclAE::installEventHandler aevt odoc echo
odocAE
The syntax for tclAE event handlers is very particular.
tclAE::installEventHandler takes the name of a proc, and
that proc
takes two arguments:
{theAppleEvent theResultAE}
both are handles to underlying AppleEvent descriptors,
e.g.,
::tclAE::installEventHandler aevt odoc odocHandler
proc odocHandler {theAppleEvent theReplyAE} {
puts $theAppleEvent
}
> (PAI) 51 % alias ::tk::mac::OpenDocument echo odocTk
> ::tk::mac::OpenDocument
If I then define ::tk::mac::OpenDocument, it never gets
called. This
doesn't surprise me. Unlike CarbonEvents, there's no
mechanism for
calling more than one AppleEvent handler. In fact, if you
::tclAE::installEventHandler aevt quit quitHandler
::tclAE::removeEventHandler aevt quit quitHandler
you'll find that you can't quit anymore, because not only is
the
TclAE-installed handler removed, so is the internal handler
that
invokes ::tk::mac::Quit because it gets replaced by TclAE's
handler.
>
> and then in the Script Editor I type in:
>
> tell application "Wish"
> open "/Users/jeffh/.emacs"
> end tell
This wouldn't generally work to tell an application to open
a file,
but it sounds like you don't care about that. Just for the
record,
you'd need to do
open posix file "/Users/jeffh/.emacs"
or
open file "jeffh:.emacs"
if you were really interested sending an AppleEvent to open
a file.
> I'm just trying to override the standard odoc to be
able to accept
> whatever comes in, as that seems to be the aevt used by
OS X for
> command line arg passing (in some sense). Or some
sensible
> alternative to that.
Using ::tclAE::installEventHandler (possibly in conjunction
with ::tclAE::removeEventHandler) you can replace Tk's
aevt/odoc
handler, but I don't know whether you can do it early enough
to
override command-line launch behavior.
------------------------------------------------------------
-------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the
chance to share your
opinions on IT & business topics through brief
surveys-and earn cash
http://www.techsay.com/default.
php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Tcl-mac mailing list
tcl-mac lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tcl-mac
|
|
| Re: catching quit from Wish menu |
  France |
2007-02-28 09:24:55 |
Le 27 févr. 07 à 23:15, Jeff Hobbs a écrit :
> ... I've tried "open document" and
variations, but even then I
> don't get args passed in.
When I tried to get filename to edit from Yummy ftp I had
the same
problem. I finaly found this tricky way to get something
usable:
package require tclAE
proc MyAeHandler {class id} {
set filename [string range [tclAE::coerceDesc
[string range $class [expr {[string first [
$class]+1}]
[expr {[string first ] $class]-1}]] TEXT] 1
end-1]
if {[file exists $filename] && $::ready} {
after idle [list FileOpen $filename]
}
return [tclAE::print $class]
}
tclAE::installEventHandler aevt odoc MyAeHandler
It works but I know I have to do something cleaner when I'll
understand how tclAE really works.
--
David Zolli
kroc kroc.tk
http://www.kroc.tk
------------------------------------------------------------
-------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the
chance to share your
opinions on IT & business topics through brief
surveys-and earn cash
http://www.techsay.com/default.
php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Tcl-mac mailing list
tcl-mac lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tcl-mac
|
|
| Re: catching quit from Wish menu |
  United States |
2007-02-28 11:06:27 |
On Feb 28, 2007, at 10:24 AM, David Zolli wrote:
> Le 27 févr. 07 à 23:15, Jeff Hobbs a écrit :
>
>> ... I've tried "open document" and
variations, but even then I
>> don't get args passed in.
>
> When I tried to get filename to edit from Yummy ftp I
had the same
> problem. I finaly found this tricky way to get
something usable:
>
> package require tclAE
>
> proc MyAeHandler {class id} {
> set filename [string range [tclAE::coerceDesc
> [string range $class [expr {[string first
[ $class]
> +1}]
> [expr {[string first ] $class]-1}]] TEXT]
1 end-1]
> if {[file exists $filename] && $::ready}
{
> after idle [list FileOpen $filename]
> }
> return [tclAE::print $class]
> }
ouch! You should *never* need (or want) to do string
manipulations on
TclAE's AE descriptors. Yes, they're strings, because Tcl
really,
really, really wants strings, and because it makes it easy
to simply
look at it and see what you're getting (handy for debugging
and code
development), but you should *always* use TclAE's tools for
pulling
them apart and putting them together. The string is simply a
handle
to / representation of an internal data structure.
> proc MyAeHandler {class id} {
the arguments are (using Apple's notation) {theAppleEvent
theReplyAE}
$theAppleEvent is the incoming AppleEvent record. You're
almost
always interested in this.
$theReplyAE is an initially empty AppleEvent descriptor for
you to
send back a reply to the caller (if they're expecting one)
> set filename [string range [tclAE::coerceDesc
> [string range $class [expr {[string first
[ $class]
> +1}]
> [expr {[string first ] $class]-1}]] TEXT]
1 end-1]
In addition to fragile string manipulations, this assumes
that the
file is being sent in as an AE list (bracketed by [ and ]),
but this
is not always true. You might be sent a list of files, you
might be
sent a single file, you might be sent one or more files as
alias
records, or as file specifiers, or file urls. Some
applications
(BBEdit) accept raw posix paths sent as strings, but this is
not
universal. A robust solution should be prepared for any of
these
possibilities.
> return [tclAE::print $class]
There's no reason to do this. The result gets sent back to
the
caller, bundled as well as possible into $theReplyAE, but
the caller
already knows what's in $class (or $theAppleEvent), because
they sent
it.
In the case of aevt/odoc, the caller is not expecting any
reply at
all. However, if you throw an error, the caller will get
back an
AppleEvent error and if your return a reply, they'll get
that back as
a string. If you want to reply with something that's not a
string,
you'll need to stuff appropriate records into $theReplyAE.
Also, tclAE::print has been a no-op for many years.
> It works but I know I have to do something cleaner when
I'll
> understand how tclAE really works.
Here's a solution, adapted from what Alpha does, that should
be
reasonably robust (most of it is comments):
proc MyAeHandler {theAppleEvent theReplyAE} {
# extract the direct object, which holds the file(s)
we're to open
set pathDesc [::tclAE::getKeyDesc $theAppleEvent ----]
# if we didn't get an AE list, make one
if {[tclAE::getDescType $pathDesc] ne "list"}
{
set pathDesc [::tclAE::coerceDesc $pathDesc list]
}
set count [::tclAE::countItems $pathDesc]
set paths [list]
# iterate through the AE list of files and build a list
of paths
for {set item 0} {$item < $count} {incr item} {
set fileDesc [::tclAE::getNthDesc $pathDesc $item]
# convert whatever we got into an 'alis' AEDesc
object
set alisDesc [::tclAE::coerceDesc $fileDesc alis]
# convert the 'alis' to a path
# better to convert to 'utf8', but a coercion
handler isn't
# available for that
lappend paths [::tclAE::getData $alisDesc TEXT]
# a more modern solution might be to convert to
'furl'
rather than
# 'alis', but then the URL needs to be parsed
# a robust solution would provide coercion handlers
from all
# possible argument types ('fss ', 'alis', 'furl',
'TEXT',
'utf8', etc.)
# and convert them to a single type that we want to
deal with.
#
# the right way is with
with ::tclAE::installCoercionHandler, not by
# adding switches here
}
foreach path $paths {
if {[file exists $path] && $::ready} {
after idle [list FileOpen $path]
}
}
}
------------------------------------------------------------
-------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the
chance to share your
opinions on IT & business topics through brief
surveys-and earn cash
http://www.techsay.com/default.
php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Tcl-mac mailing list
tcl-mac lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tcl-mac
|
|
| Re: catching quit from Wish menu |
  France |
2007-02-28 11:36:51 |
Le 28 févr. 07 à 18:06, Jon Guyer a écrit :
> ouch!
It seems this single word pretty well summarize what I've
done. ;)
> Here's a solution, adapted from what Alpha does, that
should be
> reasonably robust (most of it is comments)
And this is what lacks on tclAE website/doc: working
examples with
comments for dummies like me.
Thanks a lot for this Jon.
--
David Zolli
kroc kroc.tk
http://www.kroc.tk
------------------------------------------------------------
-------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the
chance to share your
opinions on IT & business topics through brief
surveys-and earn cash
http://www.techsay.com/default.
php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Tcl-mac mailing list
tcl-mac lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tcl-mac
|
|
| Re: catching quit from Wish menu |
  United States |
2007-02-28 11:56:03 |
On Feb 28, 2007, at 12:36 PM, David Zolli wrote:
>> Here's a solution, adapted from what Alpha does,
that should be
>> reasonably robust (most of it is comments)
>
> And this is what lacks on tclAE website/doc: working
examples with
> comments for dummies like me.
Since AEDescs can hold just about anything, and because
AppleEvents
can communicate just about anything, in any direction, it's
hard to
know how to do this in a general way, but your point is
taken. I have
tried to be responsive (mostly on the Alpha lists, but also
here when
it (infrequently) comes up) with specific solutions to
specific
questions, but none of that has made it back to the TclAE
documentation or web page. Certainly examples of how to
handle the
"basic four" are in order.
------------------------------------------------------------
-------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the
chance to share your
opinions on IT & business topics through brief
surveys-and earn cash
http://www.techsay.com/default.
php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Tcl-mac mailing list
tcl-mac lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tcl-mac
|
|
| Re: catching quit from Wish menu |

|
2007-02-28 11:58:30 |
Sorry for top-posting, but this is short -
Does someone have access to add Jon's detailed sample to the
tclAE
doc pages? While I've not been troubled by this (as I've
not tried
to use it), I can now see excellent purposes for AppleEvents
that I'd
not previously considered just by reviewing the code
presented.
Tim
On Feb 28, 2007, at 10:06 AM, Jon Guyer wrote:
> Here's a solution, adapted from what Alpha does, that
should be
> reasonably robust (most of it is comments):
>
>
> proc MyAeHandler {theAppleEvent theReplyAE} {
> # extract the direct object, which holds the
file(s) we're to
> open
> set pathDesc [::tclAE::getKeyDesc $theAppleEvent
----]
>
> # if we didn't get an AE list, make one
> if {[tclAE::getDescType $pathDesc] ne
"list"} {
> set pathDesc [::tclAE::coerceDesc $pathDesc
list]
> }
>
> set count [::tclAE::countItems $pathDesc]
>
> set paths [list]
>
> # iterate through the AE list of files and build a
list of paths
> for {set item 0} {$item < $count} {incr item}
{
> set fileDesc [::tclAE::getNthDesc $pathDesc
$item]
>
> # convert whatever we got into an 'alis'
AEDesc object
>
> set alisDesc [::tclAE::coerceDesc $fileDesc
alis]
>
> # convert the 'alis' to a path
> # better to convert to 'utf8', but a coercion
handler isn't
> # available for that
>
> lappend paths [::tclAE::getData $alisDesc
TEXT]
>
> # a more modern solution might be to convert
to 'furl'
> # rather than 'alis', but then the URL needs
to be parsed
>
> # a robust solution would provide coercion
handlers from all
> # possible argument types ('fss ', 'alis',
'furl',
> 'TEXT', 'utf8', etc.)
> # and convert them to a single type that we
want to deal
> with.
> #
> # the right way is with
::tclAE::installCoercionHandler,
> not by
> # adding switches here
> }
>
> foreach path $paths {
> if {[file exists $path] && $::ready}
{
> after idle [list FileOpen $path]
> }
> }
> }
------------------------------------------------------------
-------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the
chance to share your
opinions on IT & business topics through brief
surveys-and earn cash
http://www.techsay.com/default.
php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Tcl-mac mailing list
tcl-mac lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tcl-mac
|
|
| Re: catching quit from Wish menu |
  United States |
2007-02-28 12:06:47 |
On Feb 28, 2007, at 12:58 PM, Tim Jones wrote:
> Does someone have access to add Jon's detailed sample
to the tclAE
> doc pages?
Jon does ;^)
> While I've not been troubled by this (as I've not
tried
> to use it), I can now see excellent purposes for
AppleEvents that I'd
> not previously considered just by reviewing the code
presented.
Good to hear. I will add this example, as well as others
that have
come up over the years, as soon as possible (probably not
before this
weekend), but in the meantime, please ask questions here.
TclAE does assume that you have somehow obtained some kind
of
knowledge of how AppleEvents work (through divine
inspiration, if
nothing else). It is beyond my capabilities to teach
AppleEvents from
first principles, but I will help where I can.
------------------------------------------------------------
-------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the
chance to share your
opinions on IT & business topics through brief
surveys-and earn cash
http://www.techsay.com/default.
php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Tcl-mac mailing list
tcl-mac lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tcl-mac
|
|
[1-10]
|
|