Am I having encoding trouble with this script?
G'day,
I have a simple applescript, intended to get the title and url from current webpage in order to log to a text-based journaling app called Day One:
set out_file to "/Users/home/.tmp_dayone"
tell application "Safari"
set current_tab to current tab of front window
set tab_name to name of current_tab as Unicode text
set get_url to URL of current_tab as Unicode text
end tell
set text_out to "Read on the Web: " & tab_name & " " & get_url & " " as Unicode text
set out_file_ref to open for access POSIX file out_file with write permission
try
write text_out to out_file_ref
end try
close access out_file_ref
try
do shell script "usr/local/bin/dayone new < " & out_file
end try
delay 0.3
try
do shell script "rm " & out_file
end try
The script is obviously not very robust but mostly works. However...
...At this page http://www.ppowgallery.com/selected_work.php?artist=25 the
name of current_tab
returns this title:
"P·P·O·W | The Estate of Martin Wong | Selected Text"
Saving this to a text file and asking a shell subprocess to write a new DayOne entry from the .txt, only creates a blank entry in the journal. And I can't figure out why!
If I use less at the terminal I can see that the ' · ' character is written as '<E1>' in the .txt. Is this what is causing the problem? If I enter
file -I .tmp_dayone
at the terminal the response says the file is ISO-8859-1 encoded. I don't know if any of this is relevant; I am an amateur at all of this stuff.
Why wouldn't applescript be writing to a file as 'UTF-8" ?
Cheers!
MacBook Pro, OS X Mountain Lion (10.8.3)