[TxMt] Easy insert image? (HTML)

Sean Schertell sean at datafly.net
Wed May 24 03:38:04 UTC 2006


Wow -- thanks for that Allan!  So am I to understand then that the  
next version of TM is going have such a feature built-in?

Sean




On May 22, 2006, at 12:35 PM, Allan Odgaard wrote:

> On 22/5/2006, at 4:53, Sean Schertell wrote:
>
>> Hmm... that's a bit of a disappointment that the only way to get  
>> auto height/width is with the mouse.  Is it possible to add this  
>> functionality with a command?
>
> Sure it is -- it is already done with a drag command, you just need  
> to make it a regular command that e.g. uses AS to prompt for the  
> filename.
>
> Here’s a quick proof-of-concept, set input: none, output: insert as  
> snippet:
>
> img=$(osascript -e 'tell app "SystemUIServer"' -e activate -e  
> 'return POSIX path of (choose file with prompt "Pick an image:")' - 
> e 'end tell')
>
> err=$?
> osascript -e 'tell app "TextMate" to activate' &>/dev/null &
>
> [[ $err == 0 ]] || exit_discard
>
> src=${img#$(dirname "${TM_FILEPATH:-}")/}
> echo -n "<img src=\"$src\" "
>
> sips -g pixelWidth -g pixelHeight "$img" \
> |awk '/pixelWidth/  { printf("width=\"%d\" ",  $2) }
>       /pixelHeight/ { printf("height=\"%d\" ", $2) }'
>
> base=${img##*/}
> alt=$(tr <<<${base%.*} '[_-]' ' '|perl -pe 's/(\w+)/\u$1/g')
> echo -n "alt=\"\${1:$alt}\" />"
>
>
> Or starting with next (cutting edge) build, just click this file:
>
> <Insert Image.tmCommand>
>
> ______________________________________________________________________
> For new threads USE THIS: textmate at lists.macromates.com
> (threading gets destroyed and the universe will collapse if you don't)
> http://lists.macromates.com/mailman/listinfo/textmate

::::  DataFly.Net  ::::
Complete Web Services
http://www.datafly.net




More information about the textmate mailing list