Custom Tables

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Custom Tables Fri Mar 19, 2021 5:19 pm • by Nic
I've been playing around with Hazel 5's new custom tables attribute but have been having some difficulty getting my table to be properly recognised.

I've been using an external file as a table as the purpose for me is to have something that can be updated by AppleScript.

The first thing to address I guess is the format of the external table. In my first attempts I created a tab delimited file .tsv. But after having mixed results I consulted the Hazel user guide on custom table attributes and read that it said to create a text file. I guess a .tsv file is a type of text file, so maybe it's okay, but in case it meant a .txt file I changed mine to .txt but have been having the same issues. So probably it doesn't matter whether it's .txt .tsv .csv but it would be nice to know for sure.

Second, the substance of the issue I've been having is that Hazel seems not to be able to parse my table, and as a result the conditions that use it are not triggering. If/when in the custom table edit window in Hazel I move focus away from the delimiter edit field I get the following message: “The separator you have entered does not result in a valid table. Please enter a different one.”

My custom table uses tab as a delimiter. It's using what I thought was standard tsv format i.e. essentially typing plain text, separating each column with a tab character and separating each row with a… actually, now I write this I realise what the issue might be. Some of my lines/rows are separated with a linefeed character and some are separated by a carriage return. But I just changed them all too linefeeds and the issue persists, so that's probably not the issue after all. The first line of my file is the column headers and I've ticked the box in Hazel to say use first Line as column headers.

One thing I have tried is wrapping each cell/record in quotes. When I do that, Hazel properly parses the file and doesn't give me the alert about not resulting in a valid table, but the quotes themselves (and not just the content between them) then show up in Hazel in both the column name pop up menu and the body of the table in Hazel. As a result, the records don't match, plus I thought that it wasn't necessary to wrap each record in quotes in a tsv file. But I guess as above I'm not sure whether Hazel is expecting or respecting tsv format/convention.

How should I write my external custom table file to get best results from hazel? Is there a particular format/flavour of tsv/csv that works best? Do I need to wrap records in quotes? Does it matter whether I use linefeed or carriage return to separate rows/lines?

Cheers
Nic
 
Posts: 6
Joined: Tue Mar 09, 2021 12:10 am

Re: Custom Tables Sat Mar 20, 2021 12:18 am • by Nic
I've solved the problem (I think) and answered most of my own questions.

The problem (or at least a problem) I was having seems to have been caused by AppleScript. When AppleScript was adding a new row to the end of my file, it was writing the string in AppleScript's string or text object class, which is different it seems from its Unicode text class or from Unicode utf-8 encoding. So it was creating a file that was perhaps partly in utf-8 encoding and partly not. I think AppleScript's string/text class might be Mac-roman or something like that. So the trick in my script was to specify that it was to write the string “as "utf8"” which coerced the string to utf-8 encoded text.

I'm not exactly sure what was causing the problem initially, because I initially created the file by hand rather than by AppleScript and was still having trouble. But all seems to be working now.

The answers to my questions, so far as I have ascertained, are as follows (in case anyone else has similar questions):

Nic wrote:Is there a particular format/flavour of tsv/csv that works best?


Still not exactly sure about this one. I'm just using a .txt file for now. Will any .tsv/.csv file work so long as it adheres to public.text? I'm separating columns with a tab character and rows with a carriage return and am not wrapping records with quotes.

Nic wrote: Do I need to wrap records in quotes?


No.

Nic wrote:Does it matter whether I use linefeed or carriage return to separate rows/lines?


Seems not. My AppleScript currently inserts a carriage return \r between each line/row and it is working fine.
Nic
 
Posts: 6
Joined: Tue Mar 09, 2021 12:10 am

Re: Custom Tables Mon Mar 22, 2021 9:02 am • by Mr_Noodle
File type shouldn't matter as long as the actual file content is just text.
Mr_Noodle
Site Admin
 
Posts: 11230
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support