Creating Unique ID's For… Anything!
There are numerous reasons you might need a unique identifier on something; you upload files with common names to the same ftp site, you use the id attribute for internal links on a blog that might display multiple posts (the chances of repeating yourself are good), you want to sign your emails with a unique, one time id for your own verification… Whatever the case, a unique id could come in handy.
The easiest thing to do is use a timestamp and a shell script can do that easily enough for us. For everyday use, the year, month, day, hour, minutes and seconds should suffice (unless you need multiple unique id’s per second). Here is how the bash script would look:
date +%y%m%d%H%M%S
Entering this string into the Terminal.app would yield a twelve digit number like this:
091027191546
The first pair of digits is the year, the second pair is the month, the third pair is the day, then the hour, minutes and seconds (all in pairs). Run this script in Terminal.app as many times as you like and you will never get the same number.
So you could enter this into your terminal every time you wanted a unique id… or you could make this shell script work for you from anywhere.
TextMate Snippet
TextMate makes running shell scripts dead easy — all you need to do is create your own snippet. To do this:
- open your Bundle editor —
Bundles > Bundle Editor > Show Bundle Editoror⌃⌥⌘B - create a new bundle (if you don’t already have your own) from the + icon
- within that bundle create a new snippet from the + icon
in the edit window, type:
`date +%y%m%d%H%M%S`- define a Tab Trigger or Key Equivalent
- leave the scope selector blank to have the snippet apply to all language types
Now you have a snippet that is accessible in any language scope you use TextMate for. This is handy if you write reference links in HTML articles, such as:
<a href="#note_091027194043">See this note</a>
<div id="note_091027194043">
This is the special note I wanted you to see.
</div>
Or for reference style links in MarkDown:
Check out our site, [seyDoggy][a_091027194631], for some
really cool tips and tricks.
[a_091027194631]: http://www.seydoggy.com/ "seyDoggy's really cool site"
Download
Download your fresh copy of “Unique ID.tmSnippet” from seyDoggy.com.
AppleScript to clipboard
Say you’re not a TextMate user but you still want a quick way to run this shell script with as little effort as possible. AppleScript makes quick work of this task with it’s do shell script functionality. We need to make an AppleScript that runs the shell script, then copies the results to the clipboard. Then we can paste that result into what ever we’re working with at the time; file renaming, email signing, etc…
Here is how the script looks:
set uniqueID to (do shell script "date +%y%m%d%H%M%S")
set the clipboard to uniqueID
display alert "\"" & uniqueID & "\"" & "Has been copied to your ¬
clipboard" giving up after 1
Download
Get your fresh copy of “UniqueID.scpt” from CodeCollector.net
TextMate Tip: Use Color Picker in All Bundles
After reading this TextMate tip this morning about using the color picker in TextMates CSS bundle, it reminded me of an article I thought I wrote once about extending this same color picker functionality to the other bundles I commonly use in TextMate (namely Property List). After a quick search here and on other blogs of mine, I was unable to find it. So I Googled it and as it turns out, I blogged about it on Flickr of all places. Knowing the information wasn’t of much use there, I thought I had better revisit this tip for the benefit of other geeks.
Use Color Picker in Other Bundles
So here is the gist of it; in the CSS bundle in TextMate you can quickly pick colors for your CSS properties. This is great, but I do a lot with hex colors in other bundles too, like the Property List, Javascript and jQuery bundles. So here is what I did…
I opened the Bundle Editor (⌃⌥⌘B), went into the CSS Bundle, found the “Insert Color…” command and made a copy of it (it’s the ++ icon at the bottom of the panel). I selected and renamed the command and changed it’s Scope Selector from “source.css” to “text, source”. This will enable color picker for just about everything. “text” will cover all of the plain text based languages like HTML, XML, Property List, Markdown, BB Code, LaTeX, etc… While “source” will cover all the programatic languages like CSS, Javascript, PHP, Ruby, etc…
Now keep in mind that this particular command is going to add the hash (#) as a prefix. This may not suite you needs for some languages so you may choose to make another “Insert Color…” command for those languages and modify the appropriate lines, then use “source.actionscript.2″, for example, as your Scope Selector.
Play around with the poosibilities and have fun.

