I've been trying to come up with a solution to creating shell scripts within Textmate and creating a widget on the Dashboard layer to call the script with references to any files or URLs passed to it, and I have eventually come up with a Textmate widget & bundle to do all this.
I've created a screencast (sorry - no audio) to show the various features of the bundle and the widget, and it can be found at:
http://homepage.mac.com/andy.herbert/Textmate-widget.mov
Features shown in the screencast include:
The actual widget is included inside the bundle and is installed in ~/ Library/Widgets/ the first time you call the bundle command to create a new widget using the currently opened document.
To call a script using the widget click on the Textmate icon, to pass files to the script as $1, $2.. etc drag files from Finder on to the Textmate icon, you can also drag a URL on to it if you have a web- browser open, this too is passed as $1.
If when the script is called there is any output a green icon will appear on the widget, and when this is clicked you will be able to view the output log, same goes with any errors the script throws up, except this time the icon is red.
Flipping the widget over will allow you to edit the widget's label or modify the script the widget uses. All scripts used by the widget are held in ~/Library/Application Support/Textmate/Widget Scripts/ and are deleted when you remove the widget.
Both the output and error logs are stored in ~/Library/Logs/, each widget has a separate file, and is deleted and re-created each time each script is called.
The widget bundle can be found at:
http://homepage.mac.com/andy.herbert/Widget.tmbundle.zip
I hope it might be useful to someone else on this list.
On Oct 22, 2006, at 8:18 AM, Andy Herbert wrote:
I've been trying to come up with a solution to creating shell scripts within Textmate and creating a widget on the Dashboard layer to call the script with references to any files or URLs passed to it, and I have eventually come up with a Textmate widget & bundle to do all this.
I've created a screencast (sorry - no audio) to show the various features of the bundle and the widget, and it can be found at:
http://homepage.mac.com/andy.herbert/Textmate-widget.mov
Features shown in the screencast include:
The actual widget is included inside the bundle and is installed in ~/Library/Widgets/ the first time you call the bundle command to create a new widget using the currently opened document.
To call a script using the widget click on the Textmate icon, to pass files to the script as $1, $2.. etc drag files from Finder on to the Textmate icon, you can also drag a URL on to it if you have a web-browser open, this too is passed as $1.
If when the script is called there is any output a green icon will appear on the widget, and when this is clicked you will be able to view the output log, same goes with any errors the script throws up, except this time the icon is red.
Flipping the widget over will allow you to edit the widget's label or modify the script the widget uses. All scripts used by the widget are held in ~/Library/Application Support/Textmate/Widget Scripts/ and are deleted when you remove the widget.
Both the output and error logs are stored in ~/Library/Logs/, each widget has a separate file, and is deleted and re-created each time each script is called.
The widget bundle can be found at:
http://homepage.mac.com/andy.herbert/Widget.tmbundle.zip
I hope it might be useful to someone else on this list.
This looks like it's going to be totally stinking awesome. One problem from the getgo however. I want to use existing scripts that already have names and stuff without being deleted when closing the widget. Can you make it link to existing scripts easily?
Link open document into new widget and then change the existing one to: Copy open document into new widget
Something like that. Yes, i know i could just call the existing script from the temporary widget script, but that's a whole extra unnecessary layer.
This is going to be totally awesome!
thomas Aylott — subtleGradient — CrazyEgg
On 22 Oct 2006, at 14:15, thomas Aylott wrote:
On Oct 22, 2006, at 8:18 AM, Andy Herbert wrote:
I've been trying to come up with a solution to creating shell scripts within Textmate and creating a widget on the Dashboard layer to call the script with references to any files or URLs passed to it, and I have eventually come up with a Textmate widget & bundle to do all this.
The widget bundle can be found at:
http://homepage.mac.com/andy.herbert/Widget.tmbundle.zip
I hope it might be useful to someone else on this list.
I want to use existing scripts that already have names and stuff without being deleted when closing the widget. Can you make it link to existing scripts easily?
Link open document into new widget and then change the existing one to: Copy open document into new widget
Thanks for that suggestion, I did wonder whether to have an option to call scripts directly which weren't saved for the purpose of the widget, but I figured that would cause all sort of problems handling error reporting, something which I didn't want to deal with in the limited UI of a dashboard widget.
Despite this I've included a new option in the bundle to "Call Document in New Widget" which basically creates a new script used by the widget which calls whatever $TM_FILENAME is and also passes any arguments to it, this way if you move, delete, or rename the script it calls it's reported in the log generated by the widget. The label given to the widget is also the original filename of the script it links to, so it might help save you some time. Since I've made some changes to the widget to do this, I'd recommend manually deleting the widget in ~/Library/Widgets/ (or use the widget manager), and select the new "Install Widget" option in the bundle to update it.
Thanks for the positive feedback.
On Oct 22, 2006, at 1:11 PM, Andy Herbert wrote:
On 22 Oct 2006, at 14:15, thomas Aylott wrote:
On Oct 22, 2006, at 8:18 AM, Andy Herbert wrote:
I've been trying to come up with a solution to creating shell scripts within Textmate and creating a widget on the Dashboard layer to call the script with references to any files or URLs passed to it, and I have eventually come up with a Textmate widget & bundle to do all this.
The widget bundle can be found at:
http://homepage.mac.com/andy.herbert/Widget.tmbundle.zip
I hope it might be useful to someone else on this list.
I want to use existing scripts that already have names and stuff without being deleted when closing the widget. Can you make it link to existing scripts easily?
Link open document into new widget and then change the existing one to: Copy open document into new widget
Thanks for that suggestion, I did wonder whether to have an option to call scripts directly which weren't saved for the purpose of the widget, but I figured that would cause all sort of problems handling error reporting, something which I didn't want to deal with in the limited UI of a dashboard widget.
Despite this I've included a new option in the bundle to "Call Document in New Widget" which basically creates a new script used by the widget which calls whatever $TM_FILENAME is and also passes any arguments to it, this way if you move, delete, or rename the script it calls it's reported in the log generated by the widget. The label given to the widget is also the original filename of the script it links to, so it might help save you some time. Since I've made some changes to the widget to do this, I'd recommend manually deleting the widget in ~/Library/Widgets/ (or use the widget manager), and select the new "Install Widget" option in the bundle to update it.
Thanks for the positive feedback.
Perfect! And nice turnaround time.
thomas Aylott — subtleGradient — CrazyEgg
On Oct 22, 2006, at 8:18 AM, Andy Herbert wrote:
I've been trying to come up with a solution to creating shell scripts within Textmate and creating a widget on the Dashboard layer to call the script with references to any files or URLs passed to it, and I have eventually come up with a Textmate widget & bundle to do all this.
http://homepage.mac.com/andy.herbert/Textmate-widget.mov
The widget bundle can be found at:
http://homepage.mac.com/andy.herbert/Widget.tmbundle.zip
I hope it might be useful to someone else on this list.
I've now updated the links above so the screencast now has commentary and the bundle to the version used in the screencast. I'll probably stop working on this bundle now unless somebody reports some major problems with it.
On 22. Oct 2006, at 14:18, Andy Herbert wrote:
I've been trying to come up with a solution to creating shell scripts within Textmate and creating a widget on the Dashboard layer to call the script with references to any files or URLs passed to it, and I have eventually come up with a Textmate widget & bundle to do all this.
I've created a screencast (sorry - no audio) to show the various features of the bundle and the widget, and it can be found at: [...]
This indeed looks pretty awesome!
A few things I noticed when watching the screencast:
* Just double click the bundle or drag it onto the TM icon, then it will go into the right location *and* TM will load it (so you don’t need to reload bundles after install) * I do that !env⇥ a lot myself in shell and have to fix shell → bash, so now I made the snippet special case that :) * Probably when creating a widget from within TextMate, it should prompt the user for a name, since you always want to provide one (and if not, it’s just return with the default), which is less work than that click the ‘i’ + edit + click done. * Menu titles should be Capitalized. So Create Widget From Document (yeah, I would shorten the action descriptions as well) * Widget as a bundle name is maybe a tad ambiguous -- how about Widget Factory or some such.
Can I link to your screencast from my blog?
On 22 Oct 2006, at 14:45, Allan Odgaard wrote:
A few things I noticed when watching the screencast:
- Probably when creating a widget from within TextMate, it should
prompt the user for a name, since you always want to provide one (and if not, it’s just return with the default), which is less work than that click the ‘i’ + edit + click done.
- Menu titles should be Capitalized. So Create Widget From
Document (yeah, I would shorten the action descriptions as well)
- Widget as a bundle name is maybe a tad ambiguous -- how about
Widget Factory or some such.
I agree with the labeling part, I've fixed the whole creation process so you don't have to leave the keyboard to label a widget, when creation is called from Textmate, the widget appears and the whole text input box is selected so you can immediately type in the name without using the mouse. I've also detected enter/return being pressed, so when it is the widget flips back around.
I notice now that all the other bundles have the capitalization rule you've described, I've fixed this in the bundle, as well as giving it a more descriptive name - Widget Creator.
As I mentioned in my other post to Thomas, I've updated http:// homepage.mac.com/andy.herbert/Widget.tmbundle.zip to include all the changes I've mentioned. Thanks for showing an interest.
Can I link to your screencast from my blog?
Sure, no problem
On 22. Oct 2006, at 19:20, Andy Herbert wrote:
I agree with the labeling part, I've fixed the whole creation process so you don't have to leave the keyboard to label a widget, when creation is called from Textmate, the widget appears and the whole text input box is selected so you can immediately type in the name without using the mouse. I've also detected enter/return being pressed, so when it is the widget flips back around.
Ah nice -- initially I figured you’d prompt the user before actually creating the widget, but this here works as well, and then there is only one way to name a widget, so probably good.
I notice now that all the other bundles have the capitalization rule you've described, I've fixed this in the bundle, as well as giving it a more descriptive name - Widget Creator.
Thanks -- actually AHIG says that all four character words should be capitalized, which would include ‘this’, we try to abide by that in bundles, but it’s up to you :)
As for the titles, I would suggest:
Create Widget With Contents of Document Create Widget Calling Current Document
Or something which makes the titles more similar, but stresses the difference between deep-copying the document, and linking to it.
The Call Document in new Widget does not make it very clear that it also creates a widget (exactly like the first action).
I don’t know what Create Widget from this Project does. Can you elaborate?
I would drop the Install Widget action, seeing how creating a widget auto-installs the widget. Less actions, less to (mis)understand. If you insist on keeping it, I would call it something like Install Master Widget, so that it is clear that this has nothing to do with the other Create Widget … actions.
The Work With Multiple Files should probably also stress that a snippet is inserted. So maybe Insert $@ Loop or Insert Argument Handling, hmm… not particularly fond of these titles, but something with Insert.
One more thing, you should use TM_BUNDLE_SUPPORT instead of TM_BUNDLE_PATH. The former points to the Support folder inside the bundle, the advantage is that the latter will point to the path of the bundle containing the current command, this could be different from the master bundle, if the user did a local edit of the current command (but did not install the bundle in the local location).
On 24 Oct 2006, at 16:46, Allan Odgaard wrote:
Thanks -- actually AHIG says that all four character words should be capitalized, which would include ‘this’, we try to abide by that in bundles, but it’s up to you :)
I've renamed the bundle as you've suggested, I can't really come up with a workable name for the snippet at the moment, I've left it as "Insert Loop to Handle Multiple Arguments".
I don’t know what Create Widget from this Project does. Can you elaborate?
It was an idea I was playing with, it writes a script to open the current TM_PROJECT_DIRECTORY using TM_SUPPORT_PATH/bin/mate, so the theory is you can click on the widget to open an often used project. I dropped it as it feels peculiar to open a file via the dashboard, and there are better way of doing it i.e. Quicksilver, etc.
One more thing, you should use TM_BUNDLE_SUPPORT instead of TM_BUNDLE_PATH...
Done; thanks for the advice. Also I've included a delay of 0.2 seconds until the abort button appears assuming the script hasn't already finished, which I agree looks a lot better.
One more thing:
That quick flash of the abort cross on the TM icon, could you maybe delay it by .2s, so only if the script takes more than .2s to complete, will the abort button appear?
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Andy Herbert wrote:
I've been trying to come up with a solution to creating shell scripts within Textmate and creating a widget on the Dashboard layer to call the script with references to any files or URLs passed to it, and I have eventually come up with a Textmate widget & bundle to do all this.
I've created a screencast (sorry - no audio) to show the various features of the bundle and the widget, and it can be found at:
http://homepage.mac.com/andy.herbert/Textmate-widget.mov
Features shown in the screencast include:
The actual widget is included inside the bundle and is installed in ~/Library/Widgets/ the first time you call the bundle command to create a new widget using the currently opened document.
To call a script using the widget click on the Textmate icon, to pass files to the script as $1, $2.. etc drag files from Finder on to the Textmate icon, you can also drag a URL on to it if you have a web-browser open, this too is passed as $1.
If when the script is called there is any output a green icon will appear on the widget, and when this is clicked you will be able to view the output log, same goes with any errors the script throws up, except this time the icon is red.
Flipping the widget over will allow you to edit the widget's label or modify the script the widget uses. All scripts used by the widget are held in ~/Library/Application Support/Textmate/Widget Scripts/ and are deleted when you remove the widget.
Both the output and error logs are stored in ~/Library/Logs/, each widget has a separate file, and is deleted and re-created each time each script is called.
The widget bundle can be found at:
http://homepage.mac.com/andy.herbert/Widget.tmbundle.zip
I hope it might be useful to someone else on this list.
Yes it is, It does complement a need I have, for a quick and easy way for batch renaming some files in a custom manner. I'm not using the widgets so much, but the do come in handy sometimes. This one definitely is.
Thanks, for posting this here, and doing this.
regards, marios