[TxMt] Re: Running an AppleScript

Jacob Rus jrus at hcs.harvard.edu
Sat Mar 31 04:51:08 UTC 2007


Tim Mansour wrote:
>     osascript <<-ENDSCRIPT
>     set title to "${TM_SELECTED_TEXT}"
>     if title ≠ "" then
>         tell application "FileMaker Pro Advanced"
>             if not (exists window "HachetteTitles") then open alias "Path:To:My:Database.fp7"
>             set cell "_Search" of layout "Titles" to title
>             do script "Search For Title"
>             set href to cell "_Search" of layout "Titles"
>             set img to cell "_thumb" of layout "Titles"
>         end tell
>         if href ≠ "" then set title to img & href
>     end if
>     return title
>     ENDSCRIPT
> 
> I know this script method works fine outside of TextMate, but no matter what I do I get errors running it inside TextMate:
> 
> 31:32: syntax error: Expected “then”, etc. but found unknown token. (-2741)
> 
> I'd certainly appreciate any help diagnosing this one. 

The issue here is the encoding.  AppleScript will not accept UTF-8, but 
instead likes Mac Roman (incidentally your email is Mac Roman--I didn't 
realize anyone still used it in email clients.  How terrible: why not 
use UTF-8?!).  The solution here is either to pass the text through a 
round of iconv, or else just stick to ASCII, which in this case means 
using `is not` or `<>` instead of `≠`.

It's really tragic that AppleScripts can't be encoded in any kind of 
unicode, because it prevents users from copy/pasting filenames from the 
finder, and it creates all sorts of compatibility nastiness with other 
shell-based applications and languages.

-Jacob




More information about the textmate mailing list