So, my copy of JEG2's TextMate book has arrived down under, and I'm really enjoying getting a better understanding of TextMate.
Being an avid AppleScripter, this was my first attempt at a bundle command--to look up a selection in a FileMaker database:
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.
Hi Tim,
31:32: syntax error: Expected “then”, etc. but found unknown token. (-2741)
that seems to point at the "not equal to" sign as being saved incorrectly when you save the command. If you change that to
"is not equal to"
(ie, replace the ≠ symbol with this text) in both places it occurs I imagine the command will get happier. It's probably conversion to a different encoding (UTF-8?) on saving that's stuffing up the script. Doubtless someone knows a better workaround than this (my Applescript days are long gone), but in the meantime this might get you started.
Cheers, Paul
On 31/03/2007, at 12:06 pm, Paul McCann wrote:
that seems to point at the "not equal to" sign as being saved incorrectly when you save the command. If you change that to
Well spotted Paul! If only I'd realised the error was referring to _that_ "if" ...
Changing "≠" to "is not" did the trick. But it does make me wonder if there's another way of dealing with this text encoding issue? Longer scripts--especially those developed outside of TextMate and pasted in--will doubtless have this same problem.
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
On 31/03/2007, at 2:51 pm, Jacob Rus wrote:
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 `≠`.
Incidentally, if you use "APPLESCRIPT" as a token, you'll get syntax highlighting for applescript inside your here-document.
Thanks for those tips Jacob.
Perhaps we can hope that AppleScript 2.0 includes unicode encoding?
And as for emails ... I can't find any way of changing Mail's encoding. Any suggestions?
Tim Mansour wrote:
Perhaps we can hope that AppleScript 2.0 includes unicode encoding?
Indeed! The inability of AppleScript to really handle unicode is one of its most annoying aspects.
And as for emails ... I can't find any way of changing Mail's encoding. Any suggestions?
Ah, Allan explained that Mail will just pick whichever encoding results in the smallest email, so apparently including ≠ will result in a Mac Roman encoding, because that saves 1 byte over the utf-8 encoded version. I think this sounds overly complex and a bit silly (at least for languages based on latin characters), but there it is. It was just surprising to me, as I hadn't seen a Mac Roman encoded email in years (or at least not noticed it). So I guess there's nothing you can do.
-Jacob
On 01/04/2007, at 3:47 am, Jacob Rus wrote:
I think this sounds overly complex and a bit silly (at least for languages based on latin characters), but there it is. It was just surprising to me, as I hadn't seen a Mac Roman encoded email in years (or at least not noticed it). So I guess there's nothing you can do.
Well I guess I'll just have to avoid typing ≠
Oops, sorry.
On 1. Apr 2007, at 03:14, Tim Mansour wrote:
On 01/04/2007, at 3:47 am, Jacob Rus wrote:
I think this sounds overly complex and a bit silly (at least for languages based on latin characters), but there it is. It was just surprising to me, as I hadn't seen a Mac Roman encoded email in years (or at least not noticed it). So I guess there's nothing you can do.
Well I guess I'll just have to avoid typing ≠
For the records, the iconv solution is:
iconv -f utf-8 -t mac <<-APPLESCRIPT|osascript 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 APPLESCRIPT
On Mar 31, 2007, at 1:47 PM, Jacob Rus wrote:
Ah, Allan explained that Mail will just pick whichever encoding results in the smallest email, so apparently including ≠ will result in a Mac Roman encoding, because that saves 1 byte over the utf-8 encoded version.
There is a menu item in Mail that might affect this behavior:
Message → Text Encoding → Unicode (UTF-8)
I haven't done much experimenting to see what it actually does though. (Is it only for reading or only for sending? Do you have to set it per-message or is it "sticky"? etc.) But it's there. :)
--- Rob McBroom http://www.skurfer.com/ I didn't "switch" to Apple... my OS did.
Rob McBroom wrote:
There is a menu item in Mail that might affect this behavior:
Message → Text Encoding → Unicode (UTF-8)
I haven't done much experimenting to see what it actually does though. (Is it only for reading or only for sending? Do you have to set it per-message or is it "sticky"? etc.) But it's there. :)
Only for reading, I believe.
-Jacob