From: Bernhard S. <Ber...@gm...> - 2013-09-21 12:53:09
|
Hi, For years I was looking for a simple way to restore the behavior that was once provided by Daniel Steffen's "Launcher", namely running a Tcl/Tk script simply by double clicking on it in the Finder. I understand that there are several ways to get a similar and even more Mac like behavior as documented here: http://opensource.codebykevin.com/tutorial.html. While packaging scripts in StarPacks or even a real Mac app bundle provides the best Mac application experience, I was looking for a solution, that does not require repackaging when a new version of wish would come along. Also, I was looking not for a solution for packaging and shipping finished apps but for a more lightweight solution that simplifies running scripts during development and running some simple apps for home use (but, of course, without resorting to the command line). Just recently I discovered by more or less putting together several pieces that were floating around on the web, that I could achieve exactly what I wanted by simply putting the script proc my_open_document {file} { if [catch {uplevel #0 [list source $file]} errorInfo] { puts $errorInfo } } proc ::tk::mac::OpenDocument {args} { foreach f $args { my_open_document $f } } into Wish.app/Contents/Resources/Scripts/AppMain.tcl and associating Wish.app with files ending in .tcl. Now, double clicking on any tcl file in the Finder launches Wish.app and tells Wish.app to run the script. For me, this is the most natural behavior what Wish.app should do on the Mac. (Wish acts in this way on Windows, too.) 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? Thanks, Bernhard |
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 |
From: Bernhard S. <Ber...@gm...> - 2013-09-22 08:23:46
|
Hi Kevin, On 21.09.2013, at 16:36, Kevin Walzer <kw...@co...> wrote: > 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. Wouldn't IDLE or any other app just redefine :tk::mac::OpenDocument such that it fits their needs, i.e., displaying a document or whatever? Then my original definition of :tk::mac::OpenDocument wouldn't be seen/used any longer. > > 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. Ok, this is a tough one. Of course, it's always a balance act between security and convenience. From what I've read (http://bugs.python.org/issue5262) MacPython Launcher executes .py files but is not set as default application for .py files any longer. I think this is a reasonable approach. I just find it odd that when I actively associate tcl files with Wish and double click on these files, Wish starts up but just sits there and does nothing. (The same result when I drop a tcl file on WIsh). For me the most natural thing to expect from an interpreter as default action would be to interpret/run the script that it was given. Actually, that's exactly the behavior of the command line wish: wish foo.tcl tells wish to run script foo.tcl. Perhaps that behavior could be restricted to scripts having their executable bit set (as suggested in the thread above). > > 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 Interesting approach. However, I regularly shudder at AppleScript's pseudo human syntax and would rather stay with a pure tcl solution. Also, I don't see any difference in terms of security. Actually, I'm quite happy with my current solution. I just need to remember to apply my modification again in case a new version of Wish comes along. I was just wondering why on the Mac it's much more difficult to run a tcl script than on Windows (albeit probably less secure). Thanks for providing background and suggestions. Cheers, Bernhard > > Hope this helps, > Kevin > > -- > Kevin Walzer > Code by Kevin/Mobile Code by Kevin > http://www.codebykevin.com > http://www.wtmobilesoftware.com > > ------------------------------------------------------------------------------ > LIMITED TIME SALE - Full Year of Microsoft Training For Just $49.99! > 1,500+ hours of tutorials including VisualStudio 2012, Windows 8, SharePoint > 2013, SQL 2012, MVC 4, more. BEST VALUE: New Multi-Library Power Pack includes > Mobile, Cloud, Java, and UX Design. Lowest price ever! Ends 9/22/13. > http://pubads.g.doubleclick.net/gampad/clk?id=64545871&iu=/4140/ostg.clktrk > _______________________________________________ > Tcl-mac mailing list > tc...@li... > https://lists.sourceforge.net/lists/listinfo/tcl-mac |