From: Kevin W. <kw...@co...> - 2013-09-21 14:36:37
|
On 9/21/13 8:52 AM, Bernhard Spinnler wrote: > So my question is: why hasn't this been implemented this way? Why is this not the default Wish behavior on the Mac? Are there any drawbacks/problems with this approach? I can't speak for the design decisions of prior maintainers, but I can think of at least a few reasons why this might not be the optimal approach: 1. :tk::mac::OpenDocument is intended to be a general-purpose placeholder for opening documents in Wish, but it is used more often for actually opening and displaying a document in an editor. Re-purposing this command's default mode to executing a Tcl script would cause a lot of complication for apps using the command for other purposes--this includes some of my own apps and apps such as IDLE, the Tk-based editor that ships with MacPython. 2. There is an argument to be made that automatically executing an arbitrary script may present security issues. MacPython does come with a bundled script launcher app that does what you are looking for, and there's been a lot of debate recently about removing it because of what some argue is the security risk. 3. There are much simpler ways to implement the behavior you're looking for without the overhead of re-defining a central command in Tk-Mac or updating and deploying a full-blown app launcher (I once looked at Launcher's source code and there was a lot going on there). One is to launch Wish and the script name from Terminal: "wish foo.tcl." That's my preferred method of running scripts. Another way would be to implement a simple AppleScript launcher that is associated with Tcl files (in the manner you've already done with Wish) and runs Wish when a script is double-clicked. Below I've posted the source code for a similar app I wrote years ago that launched Scribus when it was just an X11 app in FInk. I'll leave the modification of it as an exercise for you, but it would achieve exactly what you are looking to do, and if you wanted to share your resulting project with the community, I'm sure plenty of people would find it useful: property extension_list : {"sla", "sla.gz", "scd", "scd.gz"} on run display dialog "Scribus will launch after the X11 application has finished launching." delay 5 tell application "X11" activate end tell delay 10 set theEnv to "export DISPLAY=:0;" set theBoot to "source /sw/bin/init.sh;" set theCmd to "/sw/bin/scribus " do shell script theEnv & theBoot & theCmd end run on open this_item set the item_info to info for this_item if the name extension of the item_info is in the extension_list then display dialog "Scribus will open this document after the X11 application has finished launching." delay 5 tell application "X11" activate end tell delay 10 set theEnv to "export DISPLAY=:0;" set theBoot to "source /sw/bin/init.sh;" set theCmd to "/sw/bin/scribus " set theFile to quoted form of POSIX path of this_item do shell script theEnv & theBoot & theCmd & theFile else display dialog "Scribus is unable to open this file type." end if end open Hope this helps, Kevin -- Kevin Walzer Code by Kevin/Mobile Code by Kevin http://www.codebykevin.com http://www.wtmobilesoftware.com |