• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: AppleScript-Users Digest, Vol 13, Issue 269
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: AppleScript-Users Digest, Vol 13, Issue 269


  • Subject: Re: AppleScript-Users Digest, Vol 13, Issue 269
  • From: Christopher Stone <email@hidden>
  • Date: Wed, 22 Jun 2016 16:22:26 -0500

On Jun 22, 2016, at 15:56, Mitchell L Model <email@hidden> wrote:
I had tried -- that weird results — black diamonds. But I didn’t check closely to see what happened.
I always have UTF-8 in my HTML headers.


Hey Mitchell,

I suspect you didn't write your text as UTF8 to begin with.

Try this:

-------------------------------------------------------------------------------------------

set htmlFilePath to ((path to downloads folder as text) & "test.file.ccs.html")

set rawHTML to "<!DOCTYPE html>
<html lang=\"en\">
<head>
<meta charset=\"utf-8\" />
<title></title>
</head>
<body>
H3R3
</body>
</html>
"

set theURL to "http://pythonhosted.org/pyobjc/"

tell application "Safari"
   activate
   make new document with properties {URL:theURL}
   delay 4
   tell front document to set safariPageTitle to its name
end tell

set AppleScript's text item delimiters to "H3R3"
set rawHTML to text items of rawHTML
set AppleScript's text item delimiters to safariPageTitle
set rawHTML to rawHTML as text

writeUTF8(rawHTML, htmlFilePath)

tell application "Safari"
   activate
   open file htmlFilePath
end tell

-------------------------------------------------------------------------------------------
--» HANDLERS
-------------------------------------------------------------------------------------------
on writeUTF8(_text, _file)
   try
      if _file starts with "~/" then
         set _file to POSIX path of (path to home folder as text) & text 3 thru -1 of _file
      end if
      set fRef to open for access _file with write permission
      set eof of fRef to 0
      write _text to fRef as «class utf8»
      close access fRef
   on error e number n
      try
         close access fRef
      on error e number n
         error "Error in writeUTF8() handler!" & return & return & e
      end try
   end try
end writeUTF8
-------------------------------------------------------------------------------------------

--
Best Regards,
Chris

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >Re: AppleScript-Users Digest, Vol 13, Issue 269 (From: Mitchell L Model <email@hidden>)

  • Prev by Date: Re: AppleScript-Users Digest, Vol 13, Issue 269
  • Next by Date: Re: FastScripts and script editor discrepancies
  • Previous by thread: Re: AppleScript-Users Digest, Vol 13, Issue 269
  • Next by thread: AppleScript "standard libraries" project - need to hand off now
  • Index(es):
    • Date
    • Thread