Jump to content
hubertcampan

Bash script in workflow. Language of locals ? Accented characters ?

Recommended Posts

Hi all,

 

I've have some problems with determining the locals language in bash script in workflows in Alfred2.

I'm on OSX 10.7.5 FR.

 

My script : 

DATE=$(echo "{query}" | sed -e's/HAEC/CEST/g' -e's/HNEC/CET/g'); export LC_TIME="fr_FR.UTF-8"; date -jf "%d %B %Y %T %Z" "$DATE" "+%Y%m%d%H%M%S"

 

I use it :

Select a text date (i.e. : "18 décembre 2006 19:24:12 HNEC"), use my hotkey to launch Alfred2/Workflow/Bashscript

 
Problem :
Works
• In Alfred2 when month has NO accented character (i.e. : "18 janvier 2006 19:24:12 HNEC")
• In terminal as is with or without month with accented characters
 
Does NOT work
• In Alfred2 when month has accented character
 

Note :

I had to add 'export LC_TIME="fr_FR.UTF-8"' as I assume Alfred bash script works in EN. It didn't work with french dates even though my whole system is in french and it DOES work in terminal without the export command. Also, I had to "translate" HAEC and HNEC as date command doesn't understand this frenchified CEST and CET.

 

Any ideas on how I can bypass this problem ? Is it a bug ?

 

Thanks in advance !

 

Hubert

 

Share this post


Link to post

Hi all,

 

I've have some problems with determining the locals language in bash script in workflows in Alfred2.

I'm on OSX 10.7.5 FR.

 

My script : 

DATE=$(echo "{query}" | sed -e's/HAEC/CEST/g' -e's/HNEC/CET/g'); export LC_TIME="fr_FR.UTF-8"; date -jf "%d %B %Y %T %Z" "$DATE" "+%Y%m%d%H%M%S"

 

I use it :

Select a text date (i.e. : "18 décembre 2006 19:24:12 HNEC"), use my hotkey to launch Alfred2/Workflow/Bashscript

 
Problem :
Works
• In Alfred2 when month has NO accented character (i.e. : "18 janvier 2006 19:24:12 HNEC")
• In terminal as is with or without month with accented characters
 
Does NOT work
• In Alfred2 when month has accented character
 

Note :

I had to add 'export LC_TIME="fr_FR.UTF-8"' as I assume Alfred bash script works in EN. It didn't work with french dates even though my whole system is in french and it DOES work in terminal without the export command. Also, I had to "translate" HAEC and HNEC as date command doesn't understand this frenchified CEST and CET.

 

Any ideas on how I can bypass this problem ? Is it a bug ?

 

Thanks in advance !

 

Hubert

 

I wonder if this could be a consequence of decomposed unicode. Alfred uses NSTask which automatically normalises and decomposes:

 

http://en.wikipedia.org/wiki/Unicode_equivalence#Normalization

 

Could this be the issue?

Share this post


Link to post

Andrew, thanks for your reply.

 

It could be what you say, I really have no idea.

 

How do I bypass this problem is my question.

 

Cheers.

 

Hubert

 

I'm not sure as I would have assumed that sed would be happy with decomposed unicode.

 

You could maybe strip the accented characters first using iconv? http://stackoverflow.com/questions/9889428/unaccent-string-in-bash-script-rhel

Share this post


Link to post

Andrew,

 

Thanks, but striping/replacing the accents will not work. The date command will then end in error.

 

I can use Alfred2 as is (that means in EN) and use SED to "translate" any month from FR to EN.

 

I'll see and post if I find a solution.

 

Take care.

 

Hubert

Share this post


Link to post

Andrew,

 

Thanks, but striping/replacing the accents will not work. The date command will then end in error.

 

I can use Alfred2 as is (that means in EN) and use SED to "translate" any month from FR to EN.

 

I'll see and post if I find a solution.

 

Take care.

 

Hubert

 

Thanks! Hopefully somebody can chime in to help too :)

Share this post


Link to post

I am having a similar issue with german umlauts.

 

I was able so solve the issue with the normalise command line tool posted by Andrew in another topic.

 

You could add Andrews tool to your workflow and try to do the following:

 

QUERY=$(./normalise "{query}")

DATE=$(echo "${QUERY}" | sed -e's/HAEC/CEST/g' -e's/HNEC/CET/g'); export LC_TIME="fr_FR.UTF-8"; date -jf "%d %B %Y %T %Z" "$DATE" "+%Y%m%d%H%M%S"

Share this post


Link to post

@Andrew: Just an FYI (given that your `normalise` CLI solved the problem): using `iconv -t ASCII/TRANSLIT` to replace accented characters with their base form, as described in the stackoverflow.com answer you linked to, does NOT work properly on OS X as of  10.9.2.

For instance

echo 'aüé' | iconv -f UTF8 -t ASCII//TRANSLIT 

yields 'a"u'e' rather than 'aue'.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...