Skip navigation

Am I having encoding trouble with this script?

658 Views 20 Replies Latest reply: Apr 23, 2013 4:23 PM by Wagringo RSS
  • Tom Gewecke Level 9 Level 9 (70,855 points)
    Currently Being Moderated
    Apr 23, 2013 8:05 AM (in response to twtwtw)

    twtwtw wrote:

     

    Most likely this is a problem with html entities

     

    The source of the site front page is UTF-8 and doesn't use html entities.

  • Frank Caggiano Level 7 Level 7 (22,830 points)
    Currently Being Moderated
    Apr 23, 2013 8:11 AM (in response to Wagringo)

    Substituting a space for that char so that the line reads P P O W doing a file on .tmp_dayone says it is ascii

     

    so od -c

    LIBMACLAPcaggiano:~ frank$ od -c .tmp_dayone

    0000000    R   e   a   d       o   n       t   h   e       W   e   b   :

    0000020            P       P       O       W       |       T   h   e   

     

    (spaces in place of the special char gives

     

    LIBMACLAPcaggiano:~ frank$ file .tmp_dayone

    .tmp_dayone: ASCII English text, with no line terminators

    LIBMACLAPcaggiano:~ frank$

     

    So now it's just a question of figuring out how to get those switched in the script

     

    The other question that needs to be answered is what is the dayone program doing and what is it written in?

  • red_menace Level 6 Level 6 (14,275 points)
    Currently Being Moderated
    Apr 23, 2013 8:54 AM (in response to Wagringo)

    For most western users, AppleScript writes files in MacRoman.  To write in UTF-8, you need to specify that in the write command, for example:

     

      write text_out to out_file_ref as «class utf8»

     

    The term "as Unicode text" is not needed for your strings since strings in AppleScript are already Unicode, but if you happen to use the term in the write command, it will output UTF-16 (aint AppleScript grand?).

     

    Also, is there a particular reason for writing to an invisible temp file, just to pass it on to your app, or is that also because of encoding issues?

  • Frank Caggiano Level 7 Level 7 (22,830 points)
    Currently Being Moderated
    Apr 23, 2013 10:07 AM (in response to red_menace)

    That definitly chages it so that the .tmp_dayone file is reported as UTF8 rather then ISO8859, nice.

     

    But the real question is if the dayone program that is taking this in can deal with this any better then it dealt with the orignal.

     

    There is a dayone app which sounds like what the OP is using in the MAS but it is $10 and of course given the new world of MAS no trial version.

  • Hiroto Level 5 Level 5 (4,815 points)
    Currently Being Moderated
    Apr 23, 2013 10:49 AM (in response to Wagringo)

    Hello

     

    Or simply -

     

    tell application "Safari"
        tell window 1's current tab
            set {n, u} to {name, URL}
        end tell
    end tell
    set t to "Read on the Web:  " & n & " " & u
    do shell script "/bin/echo -n " & t's quoted form & " | /usr/local/bin/dayone new"
    

     

    The 'do shell script' passes the command to shell using UTF-8, hence the t's value which is UTF-16BE is converted to UTF-8 before being passed to shell in the above code. Here I assume the said 'dayone' programme expects UTF-8 text from standard input.

     

    cf.

    http://developer.apple.com/library/mac/technotes/tn2065/_index.html

     

    Regards,

    H

1 2 Previous Next

Actions

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.