Tcl:: Language Module

TextWrangler includes basic support for Tcl syntax highlighting and procedure recognition. Procedures are listed in a popup menu that makes it easy to navigate around large files. Unfortunately, this mechanism does not recognize procedures defined in a namespace with the concise namespace::procedure syntax. The intervening “::” characters are not among those TextWrangler normally recognizes as valid identifier characters.

For example, “Bar” appears in the function menu when a procedure is defined like this:

namespace eval Foo {
    proc Bar {} {
        puts "Hello, World!"
    }
}

I prefer this syntax:

proc Foo::Bar {} {
    puts "Hello, World!"
}

but procedures defined this way don’t appear in the function menu:

TextWrangler's Default Tcl Procedure Recognition

Rather than forfeit the convenience of the function popup or conform to a more cumbersome convention, I created a codeless language module that essentially duplicates TextWrangler’s built-in Tcl support. The only distinction is that I’ve added the colon to the “Identifier and Keyword Characters” string. As a result, TextWrangler recognizes strings containing colons as valid procedure names:

Namespace Compatible Tcl Procedure Recognition

Unfortunately, this approach appears to prevent recognition of the nested syntax. Ideally I would like to support both styles.

Download

I believe this module should be compatible with BBEdit as well as TextWrangler.

Tcl:: Codeless Language Module 1k .zip

Installation

Put Tcl.plist in ~/Library/Application Support/TextWrangler/Language Modules/ and restart TextWrangler. The module identifies itself as “Tcl::” to differentiate it from TextWrangler’s internal “Tcl” mode, which remains available. It may be necessary to tweak your language preferences to use this module by default, as shown here.

Please share any problems you encounter with this module, particularly those related to the colon’s promoted status.

Posted on Thursday, September 6th, 2007.

Tcl starting points for ThisService

Waffle Software has released ThisService 2.0, a utility that bundles simple scripts as services accessible throughout Mac OS X. Jesper has included example scripts written in a variety of popular languages to help service authors get started. I like Tcl (have you met?), so I have prepared similar templates for Tcl programmers.

Download Tcl service starting points 2.3K

Tcl supports Unicode intrinsically, so, as with the other starting points, these templates should handle whatever text you throw at them without complaint.

Posted on Thursday, September 6th, 2007.

Yojimbo Script Updates

Minor updates to a few Yojimbo AppleScripts are available: Export with Comment Tags, Archive Bookmarks, and Backdate Items. These updates allow the scripts to act on items even when Yojimbo’s item list pane does not have input focus. This means you can run the scripts when editing items as well as when selecting them.

Posted on Friday, August 31st, 2007.

Yojimbo Export with Comment Tags

In response to this query, I wrote a script which allows Yojimbo items to be exported with their tags preserved as Spotlight comments. I don’t really use Spotlight, so I’m not sure if the comment format is ideal, but it works fine for a first draft.

Example Screencast

Now updated for compatibility with Mac OS X 10.5.

Download ExportwithCommentTags.scpt.zip 1.2 4k

Put the script in ~/Library/Scripts/Applications/Yojimbo, select some items, and choose “Export with Comment Tags” from your script menu.

Posted on Thursday, August 30th, 2007.

“Open As” Pseudo-Stationery Finder AppleScript

Update: Now located at https://github.com/anoved/Finder-Scripts/tree/master/Open%20As


Use this AppleScript to create and open an explicitly named copy of the selected file or folder. You will be prompted to specify the name and location of the new copy. Clicking “Save” will duplicate the item and open the new duplicate.

Open As screenshot

This script is the result of dissatisfaction with some applications’ lack of support for Stationery Pad files. Specifically, the default behavior appears to be for the Finder to create and open a generic duplicate with “copy [#]” appended to the original base filename. I find it more convenient to name the new instance directly, so that is the functionality this script provides. Stationery pads are not required as it works with regular files.

Rigorous testing has not been performed. Be advised that duplication is performed with cp, which ignored the resource fork in early versions of Mac OS X. Therefore, Mac OS X 10.4 is strongly recommended for compatibility with all files.

Download FinderOpenAs.scpt.zip 3.4K

I suggest saving the script in ~/Library/Scripts/Applications/Finder and assigning it the keyboard shortcut Shift-Command-O via FastScripts.

Posted on Friday, August 17th, 2007.

Brickshelver Development Release

Brickshelver is a small utility I have written to simplify the process of uploading files to Brickshelf, a popular site for LEGO hobbyists.

When you start Brickshelver, you log in using your Brickshelf account. Brickshelver maintains a list of your Brickshelf folders, but it takes a few moments to conduct this inventory. You can skip this step after the first run for faster logins, but in this case Brickshelver will not be aware of any new folders created via the regular web interface.

Login window screenshot

You can add files to the list of files to upload by clicking the “+” button or by dragging them to Brickshelver’s Dock icon. The files will all be uploaded to the indicated folder, which can be an existing folder or a new folder created with Brickshelver.

Brickshelver screenshot

Clicking “Upload” will automatically zip the files and upload them to Brickshelf, creating a new folder if necessary. Upload status is reported in the space to the left of the “Upload” button.

Important Notes

This release consists of a stand-alone application for Mac OS X. This application exhibits many inconsistent or unconventional behaviors, as Brickshelver is actually a Tcl/Tk script bundled in a generic application wrapper. There are a large number of issues that need to be addressed and features that need to be improved, including but not limited to:

I am content with Brickshelver in its current state, but I caution others that it is alpha quality software. Further development depends on the reaction to this release; how to proceed is clear, but I am eager to work on other projects instead.

Download Brickshelver Development Release 2.6MB .tar.gz

Your folder inventory and account information (including unencrypted Brickshelf password) are stored on your computer in ~/Library/Preferences/net.anoved.brickshelver.plist. The format of this file may change in any future releases.

Posted on Monday, August 6th, 2007.

Archive Yojimbo Bookmarks

Yojimbo can catalog bookmarks as well as web archives, which are basically local copies of web sites. This script creates web archives from existing bookmarks you select.

tell application "Yojimbo"
-- get the selected items, if any
 set _items to selection
 if _items is missing value then return

-- archive all the selected bookmark items
 repeat with _item in _items
  if class of _item is bookmark item then

-- bookmark properties the archive should inherit
   set _name to name of _item
   set _url to location of _item
   set _tags to tags of _item

-- archive the bookmarked page
   try
    set _archive to make new web archive item with contents _url with properties {name:_name}
    add tags _tags to _archive
   end try

end if
 end repeat
end tell

Download ArchiveYojimboBookmarks.scpt.zip 1.1 3k

Install the script in ~/Library/Scripts/Applications/Yojimbo. The script does not check whether there is already a web archive for the bookmarked location, but it could be done.

Posted on Sunday, July 15th, 2007.

LDLink

Note: LDLink has been superseded by LDMerge.

LDLink is a utility that can reversibly combine separate LDraw part libraries by creating symbolic links to the contents of one directory structure in another. Alternate libraries can be used to manage unofficial LDraw parts; support for this concept is present to varying degrees in some LDraw programs. This utility is intended to facilitate other tools, such as L3P, which do not readily support parallel part libraries.

Download ldlink 1.0 (5k Tcl script)

Install the script as ldlink and make it executable with chmod +x ldlink.

Usage: ldlink merge|unmerge [-src LDRAWDIR] [-dst LDRAWDIR]
       On merge, links to src files are created in dst.
       On unmerge, links named after src files are removed from dst.
       Conflicts with normal files in dst are skipped and reported.
       Default dst is LDRAWDIR environment variable.
       Default src is dst/Unofficial.

To merge unofficial parts downloaded by LDView with the rest of your part library, the following command may be sufficient:

ldlink merge

If the environment variable LDRAWDIR is not defined — or if you would like to override its value — use the dst option to specify the destination where the merge should occur. Likewise, the src option may be used to merge parts from a source other than the destination’s Unofficial subdirectory:

ldlink merge -src /Custom/LDraw -dst /Standard/LDraw

To reverse a merge, reissue the command using unmerge instead of merge:

ldlink unmerge
ldlink unmerge -src /Custom/LDraw -dst /Standard/LDraw

LDLink reports how many links it created or removed.

Posted on Tuesday, July 10th, 2007.

Vector Image Stylization

I’ve stylized a few drawings with a vectorization program called autotrace. Here is a brief summary of the process:

  1. Photograph drawing
  2. Increase contrast
  3. Black & white threshold
  4. Vectorization (PDF)
  5. Result

The vectorization command looks like this:

autotrace -corner-threshold 20 -filter-iterations 15 threshold.pbm > vectorized.eps

Posted on Friday, July 6th, 2007.

Scaled LCD Resolution

My laptop’s display has a native resolution of 1280 × 800 pixels.

Native 1280 x 800

When I select a different display resolution, it is stretched to fit the screen. This may distort the aspect ratio. It also looks like crap.

Stretched 800 x 600

Scaled modes are available. These preserve proportion, but they still look like crap.

Scaled 800 x 600

Why not use an exact subsection of the screen? I don’t think my display can do this, but it seems like the most logical solution. Who wants the crappy scaling?

Centered 800 x 600

Are there any LCD monitors that work like this?

Posted on Wednesday, July 4th, 2007.